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.

219 lines
7.6KB

  1. /*
  2. ==============================================================================
  3. This is an automatically generated GUI class created by the Introjucer!
  4. Be careful when adding custom code to these files, as only the code within
  5. the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
  6. and re-saved.
  7. Created with Introjucer version: 3.1.0
  8. ------------------------------------------------------------------------------
  9. The Introjucer is part of the JUCE library - "Jules' Utility Class Extensions"
  10. Copyright 2004-13 by Raw Material Software Ltd.
  11. ==============================================================================
  12. */
  13. //[Headers] You can add your own extra header files here...
  14. //[/Headers]
  15. #include "AudioDemoTabComponent.h"
  16. #include "AudioDemoSetupPage.h"
  17. #include "AudioDemoPlaybackPage.h"
  18. #include "AudioDemoSynthPage.h"
  19. #include "AudioDemoLatencyPage.h"
  20. #include "AudioDemoRecordPage.h"
  21. //[MiscUserDefs] You can add your own user definitions and misc code here...
  22. LiveAudioInputDisplayComp::LiveAudioInputDisplayComp()
  23. {
  24. nextSample = subSample = 0;
  25. accumulator = 0;
  26. zeromem (samples, sizeof (samples));
  27. setOpaque (true);
  28. startTimer (1000 / 50); // use a timer to keep repainting this component
  29. }
  30. LiveAudioInputDisplayComp::~LiveAudioInputDisplayComp()
  31. {
  32. }
  33. void LiveAudioInputDisplayComp::paint (Graphics& g)
  34. {
  35. RectangleList<float> waveform;
  36. const float midY = getHeight() * 0.5f;
  37. int sampleNum = (nextSample + numElementsInArray (samples) - 1);
  38. for (int x = jmin (getWidth(), (int) numElementsInArray (samples)); --x >= 0;)
  39. {
  40. const float sampleSize = midY * samples [sampleNum-- % numElementsInArray (samples)];
  41. waveform.addWithoutMerging (Rectangle<float> ((float) x, midY - sampleSize, 1.0f, sampleSize * 2.0f));
  42. }
  43. g.fillAll (Colours::black);
  44. g.setColour (Colours::green);
  45. g.fillRectList (waveform);
  46. }
  47. void LiveAudioInputDisplayComp::timerCallback()
  48. {
  49. repaint();
  50. }
  51. void LiveAudioInputDisplayComp::audioDeviceAboutToStart (AudioIODevice*)
  52. {
  53. zeromem (samples, sizeof (samples));
  54. }
  55. void LiveAudioInputDisplayComp::audioDeviceStopped()
  56. {
  57. zeromem (samples, sizeof (samples));
  58. }
  59. void LiveAudioInputDisplayComp::audioDeviceIOCallback (const float** inputChannelData, int numInputChannels,
  60. float** outputChannelData, int numOutputChannels, int numSamples)
  61. {
  62. for (int i = 0; i < numSamples; ++i)
  63. {
  64. for (int chan = 0; chan < numInputChannels; ++chan)
  65. {
  66. if (inputChannelData[chan] != 0)
  67. accumulator += fabsf (inputChannelData[chan][i]);
  68. }
  69. const int numSubSamples = 100; // how many input samples go onto one pixel.
  70. const float boost = 10.0f; // how much to boost the levels to make it more visible.
  71. if (subSample == 0)
  72. {
  73. samples[nextSample] = accumulator * boost / numSubSamples;
  74. nextSample = (nextSample + 1) % numElementsInArray (samples);
  75. subSample = numSubSamples;
  76. accumulator = 0;
  77. }
  78. else
  79. {
  80. --subSample;
  81. }
  82. }
  83. // We need to clear the output buffers, in case they're full of junk..
  84. for (int i = 0; i < numOutputChannels; ++i)
  85. if (outputChannelData[i] != 0)
  86. zeromem (outputChannelData[i], sizeof (float) * (size_t) numSamples);
  87. }
  88. //[/MiscUserDefs]
  89. //==============================================================================
  90. AudioDemoTabComponent::AudioDemoTabComponent ()
  91. {
  92. addAndMakeVisible (tabbedComponent = new TabbedComponent (TabbedButtonBar::TabsAtTop));
  93. tabbedComponent->setTabBarDepth (30);
  94. tabbedComponent->addTab ("Audio Device Setup", Colours::lightgrey, new AudioDemoSetupPage (deviceManager), true);
  95. tabbedComponent->addTab ("File Playback", Colours::lightgrey, new AudioDemoPlaybackPage (deviceManager), true);
  96. tabbedComponent->addTab ("Synth Playback", Colours::lightgrey, new AudioDemoSynthPage (deviceManager), true);
  97. tabbedComponent->addTab ("Latency Test", Colours::lightgrey, new AudioDemoLatencyPage (deviceManager), true);
  98. tabbedComponent->addTab ("Recording", Colours::lightgrey, new AudioDemoRecordPage (deviceManager), true);
  99. tabbedComponent->setCurrentTabIndex (0);
  100. //[UserPreSize]
  101. deviceManager.initialise (2, 2, 0, true, String::empty, 0);
  102. //[/UserPreSize]
  103. setSize (600, 400);
  104. //[Constructor] You can add your own custom stuff here..
  105. //[/Constructor]
  106. }
  107. AudioDemoTabComponent::~AudioDemoTabComponent()
  108. {
  109. //[Destructor_pre]. You can add your own custom destruction code here..
  110. //[/Destructor_pre]
  111. tabbedComponent = nullptr;
  112. //[Destructor]. You can add your own custom destruction code here..
  113. //[/Destructor]
  114. }
  115. //==============================================================================
  116. void AudioDemoTabComponent::paint (Graphics& g)
  117. {
  118. //[UserPrePaint] Add your own custom painting code here..
  119. //[/UserPrePaint]
  120. g.fillAll (Colours::white);
  121. //[UserPaint] Add your own custom painting code here..
  122. //[/UserPaint]
  123. }
  124. void AudioDemoTabComponent::resized()
  125. {
  126. tabbedComponent->setBounds (0, 0, getWidth() - 0, getHeight() - 0);
  127. //[UserResized] Add your own custom resize handling here..
  128. //[/UserResized]
  129. }
  130. //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
  131. //==============================================================================
  132. Component* createAudioDemo()
  133. {
  134. return new AudioDemoTabComponent();
  135. }
  136. //[/MiscUserCode]
  137. //==============================================================================
  138. #if 0
  139. /* -- Introjucer information section --
  140. This is where the Introjucer stores the metadata that describe this GUI layout, so
  141. make changes in here at your peril!
  142. BEGIN_JUCER_METADATA
  143. <JUCER_COMPONENT documentType="Component" className="AudioDemoTabComponent" componentName=""
  144. parentClasses="public Component" constructorParams="" variableInitialisers=""
  145. snapPixels="8" snapActive="1" snapShown="1" overlayOpacity="0.330"
  146. fixedSize="0" initialWidth="600" initialHeight="400">
  147. <BACKGROUND backgroundColour="ffffffff"/>
  148. <TABBEDCOMPONENT name="new tabbed component" id="83c980d7793cdced" memberName="tabbedComponent"
  149. virtualName="" explicitFocusOrder="0" pos="0 0 0M 0M" orientation="top"
  150. tabBarDepth="30" initialTab="0">
  151. <TAB name="Audio Device Setup" colour="ffd3d3d3" useJucerComp="1"
  152. contentClassName="" constructorParams="deviceManager" jucerComponentFile="AudioDemoSetupPage.cpp"/>
  153. <TAB name="File Playback" colour="ffd3d3d3" useJucerComp="1" contentClassName=""
  154. constructorParams="deviceManager" jucerComponentFile="AudioDemoPlaybackPage.cpp"/>
  155. <TAB name="Synth Playback" colour="ffd3d3d3" useJucerComp="1" contentClassName=""
  156. constructorParams="deviceManager" jucerComponentFile="AudioDemoSynthPage.cpp"/>
  157. <TAB name="Latency Test" colour="ffd3d3d3" useJucerComp="1" contentClassName=""
  158. constructorParams="deviceManager" jucerComponentFile="AudioDemoLatencyPage.cpp"/>
  159. <TAB name="Recording" colour="ffd3d3d3" useJucerComp="1" contentClassName=""
  160. constructorParams="deviceManager" jucerComponentFile="AudioDemoRecordPage.cpp"/>
  161. </TABBEDCOMPONENT>
  162. </JUCER_COMPONENT>
  163. END_JUCER_METADATA
  164. */
  165. #endif
  166. //[EndFile] You can add extra defines here...
  167. //[/EndFile]