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.

216 lines
7.5KB

  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. g.fillAll (Colours::black);
  36. g.setColour (Colours::green);
  37. const float midY = getHeight() * 0.5f;
  38. int sampleNum = (nextSample + numElementsInArray (samples) - 1);
  39. for (int x = jmin (getWidth(), (int) numElementsInArray (samples)); --x >= 0;)
  40. {
  41. const float sampleSize = midY * samples [sampleNum-- % numElementsInArray (samples)];
  42. g.drawVerticalLine (x, midY - sampleSize, midY + sampleSize);
  43. }
  44. }
  45. void LiveAudioInputDisplayComp::timerCallback()
  46. {
  47. repaint();
  48. }
  49. void LiveAudioInputDisplayComp::audioDeviceAboutToStart (AudioIODevice*)
  50. {
  51. zeromem (samples, sizeof (samples));
  52. }
  53. void LiveAudioInputDisplayComp::audioDeviceStopped()
  54. {
  55. zeromem (samples, sizeof (samples));
  56. }
  57. void LiveAudioInputDisplayComp::audioDeviceIOCallback (const float** inputChannelData, int numInputChannels,
  58. float** outputChannelData, int numOutputChannels, int numSamples)
  59. {
  60. for (int i = 0; i < numSamples; ++i)
  61. {
  62. for (int chan = 0; chan < numInputChannels; ++chan)
  63. {
  64. if (inputChannelData[chan] != 0)
  65. accumulator += fabsf (inputChannelData[chan][i]);
  66. }
  67. const int numSubSamples = 100; // how many input samples go onto one pixel.
  68. const float boost = 10.0f; // how much to boost the levels to make it more visible.
  69. if (subSample == 0)
  70. {
  71. samples[nextSample] = accumulator * boost / numSubSamples;
  72. nextSample = (nextSample + 1) % numElementsInArray (samples);
  73. subSample = numSubSamples;
  74. accumulator = 0;
  75. }
  76. else
  77. {
  78. --subSample;
  79. }
  80. }
  81. // We need to clear the output buffers, in case they're full of junk..
  82. for (int i = 0; i < numOutputChannels; ++i)
  83. if (outputChannelData[i] != 0)
  84. zeromem (outputChannelData[i], sizeof (float) * (size_t) numSamples);
  85. }
  86. //[/MiscUserDefs]
  87. //==============================================================================
  88. AudioDemoTabComponent::AudioDemoTabComponent ()
  89. : tabbedComponent (0)
  90. {
  91. addAndMakeVisible (tabbedComponent = new TabbedComponent (TabbedButtonBar::TabsAtTop));
  92. tabbedComponent->setTabBarDepth (30);
  93. tabbedComponent->addTab ("Audio Device Setup", Colours::lightgrey, new AudioDemoSetupPage (deviceManager), true);
  94. tabbedComponent->addTab ("File Playback", Colours::lightgrey, new AudioDemoPlaybackPage (deviceManager), true);
  95. tabbedComponent->addTab ("Synth Playback", Colours::lightgrey, new AudioDemoSynthPage (deviceManager), true);
  96. tabbedComponent->addTab ("Latency Test", Colours::lightgrey, new AudioDemoLatencyPage (deviceManager), true);
  97. tabbedComponent->addTab ("Recording", Colours::lightgrey, new AudioDemoRecordPage (deviceManager), true);
  98. tabbedComponent->setCurrentTabIndex (0);
  99. //[UserPreSize]
  100. deviceManager.initialise (2, 2, 0, true, String::empty, 0);
  101. //[/UserPreSize]
  102. setSize (600, 400);
  103. //[Constructor] You can add your own custom stuff here..
  104. //[/Constructor]
  105. }
  106. AudioDemoTabComponent::~AudioDemoTabComponent()
  107. {
  108. //[Destructor_pre]. You can add your own custom destruction code here..
  109. //[/Destructor_pre]
  110. deleteAndZero (tabbedComponent);
  111. //[Destructor]. You can add your own custom destruction code here..
  112. //[/Destructor]
  113. }
  114. //==============================================================================
  115. void AudioDemoTabComponent::paint (Graphics& g)
  116. {
  117. //[UserPrePaint] Add your own custom painting code here..
  118. //[/UserPrePaint]
  119. g.fillAll (Colours::white);
  120. //[UserPaint] Add your own custom painting code here..
  121. //[/UserPaint]
  122. }
  123. void AudioDemoTabComponent::resized()
  124. {
  125. tabbedComponent->setBounds (0, 0, getWidth() - 0, getHeight() - 0);
  126. //[UserResized] Add your own custom resize handling here..
  127. //[/UserResized]
  128. }
  129. //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
  130. //==============================================================================
  131. Component* createAudioDemo()
  132. {
  133. return new AudioDemoTabComponent();
  134. }
  135. //[/MiscUserCode]
  136. //==============================================================================
  137. #if 0
  138. /* -- Introjucer information section --
  139. This is where the Introjucer stores the metadata that describe this GUI layout, so
  140. make changes in here at your peril!
  141. BEGIN_JUCER_METADATA
  142. <JUCER_COMPONENT documentType="Component" className="AudioDemoTabComponent" componentName=""
  143. parentClasses="public Component" constructorParams="" variableInitialisers=""
  144. snapPixels="8" snapActive="1" snapShown="1" overlayOpacity="0.330000013"
  145. fixedSize="0" initialWidth="600" initialHeight="400">
  146. <BACKGROUND backgroundColour="ffffffff"/>
  147. <TABBEDCOMPONENT name="new tabbed component" id="83c980d7793cdced" memberName="tabbedComponent"
  148. virtualName="" explicitFocusOrder="0" pos="0 0 0M 0M" orientation="top"
  149. tabBarDepth="30" initialTab="0">
  150. <TAB name="Audio Device Setup" colour="ffd3d3d3" useJucerComp="1"
  151. contentClassName="" constructorParams="deviceManager" jucerComponentFile="AudioDemoSetupPage.cpp"/>
  152. <TAB name="File Playback" colour="ffd3d3d3" useJucerComp="1" contentClassName=""
  153. constructorParams="deviceManager" jucerComponentFile="AudioDemoPlaybackPage.cpp"/>
  154. <TAB name="Synth Playback" colour="ffd3d3d3" useJucerComp="1" contentClassName=""
  155. constructorParams="deviceManager" jucerComponentFile="AudioDemoSynthPage.cpp"/>
  156. <TAB name="Latency Test" colour="ffd3d3d3" useJucerComp="1" contentClassName=""
  157. constructorParams="deviceManager" jucerComponentFile="AudioDemoLatencyPage.cpp"/>
  158. <TAB name="Recording" colour="ffd3d3d3" useJucerComp="1" contentClassName=""
  159. constructorParams="deviceManager" jucerComponentFile="AudioDemoRecordPage.cpp"/>
  160. </TABBEDCOMPONENT>
  161. </JUCER_COMPONENT>
  162. END_JUCER_METADATA
  163. */
  164. #endif
  165. //[EndFile] You can add extra defines here...
  166. //[/EndFile]