The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

353 lines
13KB

  1. /*
  2. ==============================================================================
  3. This is an automatically generated file created by the Jucer!
  4. Creation date: 18 Sep 2009 7:17:11 pm
  5. Be careful when adding custom code to these files, as only the code within
  6. the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
  7. and re-saved.
  8. Jucer version: 1.12
  9. ------------------------------------------------------------------------------
  10. The Jucer is part of the JUCE library - "Jules' Utility Class Extensions"
  11. Copyright 2004-6 by Raw Material Software ltd.
  12. ==============================================================================
  13. */
  14. //[Headers] You can add your own extra header files here...
  15. //[/Headers]
  16. #include "AudioDemoPlaybackPage.h"
  17. //[MiscUserDefs] You can add your own user definitions and misc code here...
  18. class DemoThumbnailComp : public Component,
  19. public ChangeListener
  20. {
  21. public:
  22. DemoThumbnailComp()
  23. : thumbnailCache (5),
  24. thumbnail (512, formatManager, thumbnailCache)
  25. {
  26. startTime = endTime = 0;
  27. formatManager.registerBasicFormats();
  28. thumbnail.addChangeListener (this);
  29. }
  30. ~DemoThumbnailComp()
  31. {
  32. thumbnail.removeChangeListener (this);
  33. }
  34. void setFile (const File& file)
  35. {
  36. thumbnail.setSource (new FileInputSource (file));
  37. startTime = 0;
  38. endTime = thumbnail.getTotalLength();
  39. }
  40. void setZoomFactor (double amount)
  41. {
  42. if (thumbnail.getTotalLength() > 0)
  43. {
  44. double timeDisplayed = jmax (0.001, (thumbnail.getTotalLength() - startTime) * (1.0 - jlimit (0.0, 1.0, amount)));
  45. endTime = startTime + timeDisplayed;
  46. repaint();
  47. }
  48. }
  49. void mouseWheelMove (const MouseEvent&, float wheelIncrementX, float wheelIncrementY)
  50. {
  51. if (thumbnail.getTotalLength() > 0)
  52. {
  53. double newStart = startTime + (wheelIncrementX + wheelIncrementY) * (endTime - startTime) / 10.0;
  54. newStart = jlimit (0.0, thumbnail.getTotalLength() - (endTime - startTime), newStart);
  55. endTime = newStart + (endTime - startTime);
  56. startTime = newStart;
  57. repaint();
  58. }
  59. }
  60. void paint (Graphics& g)
  61. {
  62. g.fillAll (Colours::white);
  63. g.setColour (Colours::mediumblue);
  64. if (thumbnail.getTotalLength() > 0)
  65. {
  66. int heightPerChannel = (getHeight() - 4) / thumbnail.getNumChannels();
  67. for (int i = 0; i < thumbnail.getNumChannels(); ++i)
  68. {
  69. thumbnail.drawChannel (g, 2, 2 + heightPerChannel * i,
  70. getWidth() - 4, heightPerChannel,
  71. startTime, endTime,
  72. i, 1.0f);
  73. }
  74. }
  75. else
  76. {
  77. g.setFont (14.0f);
  78. g.drawFittedText ("(No audio file selected)", 0, 0, getWidth(), getHeight(), Justification::centred, 2);
  79. }
  80. }
  81. void changeListenerCallback (void*)
  82. {
  83. // this method is called by the thumbnail when it has changed, so we should repaint it..
  84. repaint();
  85. }
  86. AudioFormatManager formatManager;
  87. AudioThumbnailCache thumbnailCache;
  88. AudioThumbnail thumbnail;
  89. double startTime, endTime;
  90. };
  91. //[/MiscUserDefs]
  92. //==============================================================================
  93. AudioDemoPlaybackPage::AudioDemoPlaybackPage (AudioDeviceManager& deviceManager_)
  94. : deviceManager (deviceManager_),
  95. thread ("audio file preview"),
  96. directoryList (0, thread),
  97. zoomLabel (0),
  98. thumbnail (0),
  99. startStopButton (0),
  100. fileTreeComp (0),
  101. explanation (0),
  102. zoomSlider (0)
  103. {
  104. addAndMakeVisible (zoomLabel = new Label (String::empty,
  105. T("zoom:")));
  106. zoomLabel->setFont (Font (15.0000f, Font::plain));
  107. zoomLabel->setJustificationType (Justification::centredRight);
  108. zoomLabel->setEditable (false, false, false);
  109. zoomLabel->setColour (TextEditor::textColourId, Colours::black);
  110. zoomLabel->setColour (TextEditor::backgroundColourId, Colour (0x0));
  111. addAndMakeVisible (thumbnail = new DemoThumbnailComp());
  112. addAndMakeVisible (startStopButton = new TextButton (String::empty));
  113. startStopButton->setButtonText (T("Play/Stop"));
  114. startStopButton->addButtonListener (this);
  115. startStopButton->setColour (TextButton::buttonColourId, Colour (0xff79ed7f));
  116. addAndMakeVisible (fileTreeComp = new FileTreeComponent (directoryList));
  117. addAndMakeVisible (explanation = new Label (String::empty,
  118. T("Select an audio file in the treeview above, and this page will display its waveform, and let you play it..")));
  119. explanation->setFont (Font (14.0000f, Font::plain));
  120. explanation->setJustificationType (Justification::bottomRight);
  121. explanation->setEditable (false, false, false);
  122. explanation->setColour (TextEditor::textColourId, Colours::black);
  123. explanation->setColour (TextEditor::backgroundColourId, Colour (0x0));
  124. addAndMakeVisible (zoomSlider = new Slider (String::empty));
  125. zoomSlider->setRange (0, 1, 0);
  126. zoomSlider->setSliderStyle (Slider::LinearHorizontal);
  127. zoomSlider->setTextBoxStyle (Slider::NoTextBox, false, 80, 20);
  128. zoomSlider->addListener (this);
  129. zoomSlider->setSkewFactor (2);
  130. //[UserPreSize]
  131. //[/UserPreSize]
  132. setSize (600, 400);
  133. //[Constructor] You can add your own custom stuff here..
  134. directoryList.setDirectory (File::getSpecialLocation (File::userHomeDirectory), true, true);
  135. thread.startThread (3);
  136. fileTreeComp->setColour (FileTreeComponent::backgroundColourId, Colours::white);
  137. fileTreeComp->addListener (this);
  138. deviceManager.addAudioCallback (&audioSourcePlayer);
  139. audioSourcePlayer.setSource (&transportSource);
  140. currentAudioFileSource = 0;
  141. //[/Constructor]
  142. }
  143. AudioDemoPlaybackPage::~AudioDemoPlaybackPage()
  144. {
  145. //[Destructor_pre]. You can add your own custom destruction code here..
  146. transportSource.setSource (0);
  147. audioSourcePlayer.setSource (0);
  148. deviceManager.removeAudioCallback (&audioSourcePlayer);
  149. fileTreeComp->removeListener (this);
  150. deleteAndZero (currentAudioFileSource);
  151. //[/Destructor_pre]
  152. deleteAndZero (zoomLabel);
  153. deleteAndZero (thumbnail);
  154. deleteAndZero (startStopButton);
  155. deleteAndZero (fileTreeComp);
  156. deleteAndZero (explanation);
  157. deleteAndZero (zoomSlider);
  158. //[Destructor]. You can add your own custom destruction code here..
  159. //[/Destructor]
  160. }
  161. //==============================================================================
  162. void AudioDemoPlaybackPage::paint (Graphics& g)
  163. {
  164. //[UserPrePaint] Add your own custom painting code here..
  165. //[/UserPrePaint]
  166. g.fillAll (Colours::lightgrey);
  167. //[UserPaint] Add your own custom painting code here..
  168. //[/UserPaint]
  169. }
  170. void AudioDemoPlaybackPage::resized()
  171. {
  172. zoomLabel->setBounds (16, getHeight() - 90, 55, 24);
  173. thumbnail->setBounds (16, getHeight() - 221, getWidth() - 32, 123);
  174. startStopButton->setBounds (16, getHeight() - 46, 150, 32);
  175. fileTreeComp->setBounds (16, 8, getWidth() - 32, getHeight() - 245);
  176. explanation->setBounds (256, getHeight() - 82, getWidth() - 275, 64);
  177. zoomSlider->setBounds (72, getHeight() - 90, 200, 24);
  178. //[UserResized] Add your own custom resize handling here..
  179. //[/UserResized]
  180. }
  181. void AudioDemoPlaybackPage::buttonClicked (Button* buttonThatWasClicked)
  182. {
  183. //[UserbuttonClicked_Pre]
  184. //[/UserbuttonClicked_Pre]
  185. if (buttonThatWasClicked == startStopButton)
  186. {
  187. //[UserButtonCode_startStopButton] -- add your button handler code here..
  188. if (transportSource.isPlaying())
  189. {
  190. transportSource.stop();
  191. }
  192. else
  193. {
  194. transportSource.setPosition (0);
  195. transportSource.start();
  196. }
  197. //[/UserButtonCode_startStopButton]
  198. }
  199. //[UserbuttonClicked_Post]
  200. //[/UserbuttonClicked_Post]
  201. }
  202. void AudioDemoPlaybackPage::sliderValueChanged (Slider* sliderThatWasMoved)
  203. {
  204. //[UsersliderValueChanged_Pre]
  205. //[/UsersliderValueChanged_Pre]
  206. if (sliderThatWasMoved == zoomSlider)
  207. {
  208. //[UserSliderCode_zoomSlider] -- add your slider handling code here..
  209. thumbnail->setZoomFactor (zoomSlider->getValue());
  210. //[/UserSliderCode_zoomSlider]
  211. }
  212. //[UsersliderValueChanged_Post]
  213. //[/UsersliderValueChanged_Post]
  214. }
  215. //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
  216. void AudioDemoPlaybackPage::loadFileIntoTransport (const File& audioFile)
  217. {
  218. // unload the previous file source and delete it..
  219. transportSource.stop();
  220. transportSource.setSource (0);
  221. deleteAndZero (currentAudioFileSource);
  222. // get a format manager and set it up with the basic types (wav and aiff).
  223. AudioFormatManager formatManager;
  224. formatManager.registerBasicFormats();
  225. AudioFormatReader* reader = formatManager.createReaderFor (audioFile);
  226. if (reader != 0)
  227. {
  228. currentAudioFileSource = new AudioFormatReaderSource (reader, true);
  229. // ..and plug it into our transport source
  230. transportSource.setSource (currentAudioFileSource,
  231. 32768, // tells it to buffer this many samples ahead
  232. reader->sampleRate);
  233. }
  234. }
  235. void AudioDemoPlaybackPage::selectionChanged()
  236. {
  237. loadFileIntoTransport (fileTreeComp->getSelectedFile());
  238. zoomSlider->setValue (0, false, false);
  239. thumbnail->setFile (fileTreeComp->getSelectedFile());
  240. }
  241. void AudioDemoPlaybackPage::fileClicked (const File&, const MouseEvent&)
  242. {
  243. }
  244. void AudioDemoPlaybackPage::fileDoubleClicked (const File&)
  245. {
  246. }
  247. //[/MiscUserCode]
  248. //==============================================================================
  249. #if 0
  250. /* -- Jucer information section --
  251. This is where the Jucer puts all of its metadata, so don't change anything in here!
  252. BEGIN_JUCER_METADATA
  253. <JUCER_COMPONENT documentType="Component" className="AudioDemoPlaybackPage" componentName=""
  254. parentClasses="public Component, public FileBrowserListener"
  255. constructorParams="AudioDeviceManager&amp; deviceManager_" variableInitialisers="deviceManager (deviceManager_),&#10;thread (&quot;audio file preview&quot;),&#10;directoryList (0, thread)"
  256. snapPixels="8" snapActive="1" snapShown="1" overlayOpacity="0.330000013"
  257. fixedSize="0" initialWidth="600" initialHeight="400">
  258. <BACKGROUND backgroundColour="ffd3d3d3"/>
  259. <LABEL name="" id="d4f78f975d81c8d3" memberName="zoomLabel" virtualName=""
  260. explicitFocusOrder="0" pos="16 90R 55 24" edTextCol="ff000000"
  261. edBkgCol="0" labelText="zoom:" editableSingleClick="0" editableDoubleClick="0"
  262. focusDiscardsChanges="0" fontname="Default font" fontsize="15"
  263. bold="0" italic="0" justification="34"/>
  264. <GENERICCOMPONENT name="" id="beef657b0e007936" memberName="thumbnail" virtualName=""
  265. explicitFocusOrder="0" pos="16 221R 32M 123" class="DemoThumbnailComp"
  266. params=""/>
  267. <TEXTBUTTON name="" id="abe446e2f3f09420" memberName="startStopButton" virtualName=""
  268. explicitFocusOrder="0" pos="16 46R 150 32" bgColOff="ff79ed7f"
  269. buttonText="Play/Stop" connectedEdges="0" needsCallback="1" radioGroupId="0"/>
  270. <GENERICCOMPONENT name="" id="1de1dc6a18a9032b" memberName="fileTreeComp" virtualName=""
  271. explicitFocusOrder="0" pos="16 8 32M 245M" class="FileTreeComponent"
  272. params="directoryList"/>
  273. <LABEL name="" id="7db7d0a64ef21311" memberName="explanation" virtualName=""
  274. explicitFocusOrder="0" pos="256 82R 275M 64" edTextCol="ff000000"
  275. edBkgCol="0" labelText="Select an audio file in the treeview above, and this page will display its waveform, and let you play it.."
  276. editableSingleClick="0" editableDoubleClick="0" focusDiscardsChanges="0"
  277. fontname="Default font" fontsize="14" bold="0" italic="0" justification="18"/>
  278. <SLIDER name="" id="38bbc108f4c96092" memberName="zoomSlider" virtualName=""
  279. explicitFocusOrder="0" pos="72 90R 200 24" min="0" max="1" int="0"
  280. style="LinearHorizontal" textBoxPos="NoTextBox" textBoxEditable="1"
  281. textBoxWidth="80" textBoxHeight="20" skewFactor="2"/>
  282. </JUCER_COMPONENT>
  283. END_JUCER_METADATA
  284. */
  285. #endif