2 ==============================================================================
4 This is an automatically generated file created by the Jucer!
6 Creation date: 1 May 2011 12:08:14pm
8 Be careful when adding custom code to these files, as only the code within
9 the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
14 ------------------------------------------------------------------------------
16 The Jucer is part of the JUCE library - "Jules' Utility Class Extensions"
17 Copyright 2004-6 by Raw Material Software ltd.
19 ==============================================================================
22 //[Headers] You can add your own extra header files here...
25 #include "AudioDemoPlaybackPage.h"
28 //[MiscUserDefs] You can add your own user definitions and misc code here...
29 class DemoThumbnailComp
: public Component
,
30 public ChangeListener
,
31 public FileDragAndDropTarget
36 thumbnail (512, formatManager
, thumbnailCache
)
38 startTime
= endTime
= 0;
39 formatManager
.registerBasicFormats();
40 thumbnail
.addChangeListener (this);
45 thumbnail
.removeChangeListener (this);
48 void setFile (const File
& file
)
50 thumbnail
.setSource (new FileInputSource (file
));
52 endTime
= thumbnail
.getTotalLength();
55 void setZoomFactor (double amount
)
57 if (thumbnail
.getTotalLength() > 0)
59 double timeDisplayed
= jmax (0.001, (thumbnail
.getTotalLength() - startTime
) * (1.0 - jlimit (0.0, 1.0, amount
)));
60 endTime
= startTime
+ timeDisplayed
;
65 void mouseWheelMove (const MouseEvent
&, float wheelIncrementX
, float wheelIncrementY
)
67 if (thumbnail
.getTotalLength() > 0)
69 double newStart
= startTime
+ (wheelIncrementX
+ wheelIncrementY
) * (endTime
- startTime
) / 10.0;
70 newStart
= jlimit (0.0, thumbnail
.getTotalLength() - (endTime
- startTime
), newStart
);
71 endTime
= newStart
+ (endTime
- startTime
);
77 void paint (Graphics
& g
)
79 g
.fillAll (Colours::white
);
81 g
.setColour (Colours::mediumblue
);
83 if (thumbnail
.getTotalLength() > 0)
85 thumbnail
.drawChannels (g
, getLocalBounds().reduced (2, 2),
86 startTime
, endTime
, 1.0f
);
91 g
.drawFittedText ("(No audio file selected)", 0, 0, getWidth(), getHeight(),
92 Justification::centred
, 2);
96 void changeListenerCallback (ChangeBroadcaster
*)
98 // this method is called by the thumbnail when it has changed, so we should repaint it..
102 bool isInterestedInFileDrag (const StringArray
& /*files*/)
107 void filesDropped (const StringArray
& files
, int /*x*/, int /*y*/)
109 AudioDemoPlaybackPage
* demoPage
= findParentComponentOfClass ((AudioDemoPlaybackPage
*) 0);
112 demoPage
->showFile (File (files
[0]));
115 AudioFormatManager formatManager
;
116 AudioThumbnailCache thumbnailCache
;
117 AudioThumbnail thumbnail
;
118 double startTime
, endTime
;
123 //==============================================================================
124 AudioDemoPlaybackPage::AudioDemoPlaybackPage (AudioDeviceManager
& deviceManager_
)
125 : deviceManager (deviceManager_
),
126 thread ("audio file preview"),
127 directoryList (0, thread
),
135 addAndMakeVisible (zoomLabel
= new Label (String::empty
,
137 zoomLabel
->setFont (Font (15.0000f
, Font::plain
));
138 zoomLabel
->setJustificationType (Justification::centredRight
);
139 zoomLabel
->setEditable (false, false, false);
140 zoomLabel
->setColour (TextEditor::textColourId
, Colours::black
);
141 zoomLabel
->setColour (TextEditor::backgroundColourId
, Colour (0x0));
143 addAndMakeVisible (thumbnail
= new DemoThumbnailComp());
145 addAndMakeVisible (startStopButton
= new TextButton (String::empty
));
146 startStopButton
->setButtonText (L
"Play/Stop");
147 startStopButton
->addListener (this);
148 startStopButton
->setColour (TextButton::buttonColourId
, Colour (0xff79ed7f));
150 addAndMakeVisible (fileTreeComp
= new FileTreeComponent (directoryList
));
152 addAndMakeVisible (explanation
= new Label (String::empty
,
153 L
"Select an audio file in the treeview above, and this page will display its waveform, and let you play it.."));
154 explanation
->setFont (Font (14.0000f
, Font::plain
));
155 explanation
->setJustificationType (Justification::bottomRight
);
156 explanation
->setEditable (false, false, false);
157 explanation
->setColour (TextEditor::textColourId
, Colours::black
);
158 explanation
->setColour (TextEditor::backgroundColourId
, Colour (0x0));
160 addAndMakeVisible (zoomSlider
= new Slider (String::empty
));
161 zoomSlider
->setRange (0, 1, 0);
162 zoomSlider
->setSliderStyle (Slider::LinearHorizontal
);
163 zoomSlider
->setTextBoxStyle (Slider::NoTextBox
, false, 80, 20);
164 zoomSlider
->addListener (this);
165 zoomSlider
->setSkewFactor (2);
174 //[Constructor] You can add your own custom stuff here..
175 directoryList
.setDirectory (File::getSpecialLocation (File::userHomeDirectory
), true, true);
176 thread
.startThread (3);
178 fileTreeComp
->setColour (FileTreeComponent::backgroundColourId
, Colours::white
);
179 fileTreeComp
->addListener (this);
181 deviceManager
.addAudioCallback (&audioSourcePlayer
);
182 audioSourcePlayer
.setSource (&transportSource
);
186 AudioDemoPlaybackPage::~AudioDemoPlaybackPage()
188 //[Destructor_pre]. You can add your own custom destruction code here..
189 transportSource
.setSource (0);
190 audioSourcePlayer
.setSource (0);
192 deviceManager
.removeAudioCallback (&audioSourcePlayer
);
193 fileTreeComp
->removeListener (this);
196 deleteAndZero (zoomLabel
);
197 deleteAndZero (thumbnail
);
198 deleteAndZero (startStopButton
);
199 deleteAndZero (fileTreeComp
);
200 deleteAndZero (explanation
);
201 deleteAndZero (zoomSlider
);
204 //[Destructor]. You can add your own custom destruction code here..
208 //==============================================================================
209 void AudioDemoPlaybackPage::paint (Graphics
& g
)
211 //[UserPrePaint] Add your own custom painting code here..
214 g
.fillAll (Colours::lightgrey
);
216 //[UserPaint] Add your own custom painting code here..
220 void AudioDemoPlaybackPage::resized()
222 zoomLabel
->setBounds (16, getHeight() - 90, 55, 24);
223 thumbnail
->setBounds (16, getHeight() - 221, getWidth() - 32, 123);
224 startStopButton
->setBounds (16, getHeight() - 46, 150, 32);
225 fileTreeComp
->setBounds (16, 8, getWidth() - 32, getHeight() - 245);
226 explanation
->setBounds (256, getHeight() - 82, getWidth() - 275, 64);
227 zoomSlider
->setBounds (72, getHeight() - 90, 200, 24);
228 //[UserResized] Add your own custom resize handling here..
232 void AudioDemoPlaybackPage::buttonClicked (Button
* buttonThatWasClicked
)
234 //[UserbuttonClicked_Pre]
235 //[/UserbuttonClicked_Pre]
237 if (buttonThatWasClicked
== startStopButton
)
239 //[UserButtonCode_startStopButton] -- add your button handler code here..
240 if (transportSource
.isPlaying())
242 transportSource
.stop();
246 transportSource
.setPosition (0);
247 transportSource
.start();
249 //[/UserButtonCode_startStopButton]
252 //[UserbuttonClicked_Post]
253 //[/UserbuttonClicked_Post]
256 void AudioDemoPlaybackPage::sliderValueChanged (Slider
* sliderThatWasMoved
)
258 //[UsersliderValueChanged_Pre]
259 //[/UsersliderValueChanged_Pre]
261 if (sliderThatWasMoved
== zoomSlider
)
263 //[UserSliderCode_zoomSlider] -- add your slider handling code here..
264 thumbnail
->setZoomFactor (zoomSlider
->getValue());
265 //[/UserSliderCode_zoomSlider]
268 //[UsersliderValueChanged_Post]
269 //[/UsersliderValueChanged_Post]
274 //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
276 void AudioDemoPlaybackPage::showFile (const File
& file
)
278 loadFileIntoTransport (file
);
280 zoomSlider
->setValue (0, false, false);
281 thumbnail
->setFile (file
);
284 void AudioDemoPlaybackPage::loadFileIntoTransport (const File
& audioFile
)
286 // unload the previous file source and delete it..
287 transportSource
.stop();
288 transportSource
.setSource (0);
289 currentAudioFileSource
= 0;
291 // get a format manager and set it up with the basic types (wav and aiff).
292 AudioFormatManager formatManager
;
293 formatManager
.registerBasicFormats();
295 AudioFormatReader
* reader
= formatManager
.createReaderFor (audioFile
);
299 currentAudioFileSource
= new AudioFormatReaderSource (reader
, true);
301 // ..and plug it into our transport source
302 transportSource
.setSource (currentAudioFileSource
,
303 32768, // tells it to buffer this many samples ahead
308 void AudioDemoPlaybackPage::selectionChanged()
310 showFile (fileTreeComp
->getSelectedFile());
313 void AudioDemoPlaybackPage::fileClicked (const File
&, const MouseEvent
&)
317 void AudioDemoPlaybackPage::fileDoubleClicked (const File
&)
323 //==============================================================================
325 /* -- Jucer information section --
327 This is where the Jucer puts all of its metadata, so don't change anything in here!
331 <JUCER_COMPONENT documentType="Component" className="AudioDemoPlaybackPage" componentName=""
332 parentClasses="public Component, public FileBrowserListener"
333 constructorParams="AudioDeviceManager& deviceManager_" variableInitialisers="deviceManager (deviceManager_), thread ("audio file preview"), directoryList (0, thread)"
334 snapPixels="8" snapActive="1" snapShown="1" overlayOpacity="0.330000013"
335 fixedSize="0" initialWidth="600" initialHeight="400">
336 <BACKGROUND backgroundColour="ffd3d3d3"/>
337 <LABEL name="" id="d4f78f975d81c8d3" memberName="zoomLabel" virtualName=""
338 explicitFocusOrder="0" pos="16 90R 55 24" edTextCol="ff000000"
339 edBkgCol="0" labelText="zoom:" editableSingleClick="0" editableDoubleClick="0"
340 focusDiscardsChanges="0" fontname="Default font" fontsize="15"
341 bold="0" italic="0" justification="34"/>
342 <GENERICCOMPONENT name="" id="beef657b0e007936" memberName="thumbnail" virtualName=""
343 explicitFocusOrder="0" pos="16 221R 32M 123" class="DemoThumbnailComp"
345 <TEXTBUTTON name="" id="abe446e2f3f09420" memberName="startStopButton" virtualName=""
346 explicitFocusOrder="0" pos="16 46R 150 32" bgColOff="ff79ed7f"
347 buttonText="Play/Stop" connectedEdges="0" needsCallback="1" radioGroupId="0"/>
348 <GENERICCOMPONENT name="" id="1de1dc6a18a9032b" memberName="fileTreeComp" virtualName=""
349 explicitFocusOrder="0" pos="16 8 32M 245M" class="FileTreeComponent"
350 params="directoryList"/>
351 <LABEL name="" id="7db7d0a64ef21311" memberName="explanation" virtualName=""
352 explicitFocusOrder="0" pos="256 82R 275M 64" edTextCol="ff000000"
353 edBkgCol="0" labelText="Select an audio file in the treeview above, and this page will display its waveform, and let you play it.."
354 editableSingleClick="0" editableDoubleClick="0" focusDiscardsChanges="0"
355 fontname="Default font" fontsize="14" bold="0" italic="0" justification="18"/>
356 <SLIDER name="" id="38bbc108f4c96092" memberName="zoomSlider" virtualName=""
357 explicitFocusOrder="0" pos="72 90R 200 24" min="0" max="1" int="0"
358 style="LinearHorizontal" textBoxPos="NoTextBox" textBoxEditable="1"
359 textBoxWidth="80" textBoxHeight="20" skewFactor="2"/>