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.

215 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. {
  90. addAndMakeVisible (tabbedComponent = new TabbedComponent (TabbedButtonBar::TabsAtTop));
  91. tabbedComponent->setTabBarDepth (30);
  92. tabbedComponent->addTab ("Audio Device Setup", Colours::lightgrey, new AudioDemoSetupPage (deviceManager), true);
  93. tabbedComponent->addTab ("File Playback", Colours::lightgrey, new AudioDemoPlaybackPage (deviceManager), true);
  94. tabbedComponent->addTab ("Synth Playback", Colours::lightgrey, new AudioDemoSynthPage (deviceManager), true);
  95. tabbedComponent->addTab ("Latency Test", Colours::lightgrey, new AudioDemoLatencyPage (deviceManager), true);
  96. tabbedComponent->addTab ("Recording", Colours::lightgrey, new AudioDemoRecordPage (deviceManager), true);
  97. tabbedComponent->setCurrentTabIndex (0);
  98. //[UserPreSize]
  99. deviceManager.initialise (2, 2, 0, true, String::empty, 0);
  100. //[/UserPreSize]
  101. setSize (600, 400);
  102. //[Constructor] You can add your own custom stuff here..
  103. //[/Constructor]
  104. }
  105. AudioDemoTabComponent::~AudioDemoTabComponent()
  106. {
  107. //[Destructor_pre]. You can add your own custom destruction code here..
  108. //[/Destructor_pre]
  109. tabbedComponent = nullptr;
  110. //[Destructor]. You can add your own custom destruction code here..
  111. //[/Destructor]
  112. }
  113. //==============================================================================
  114. void AudioDemoTabComponent::paint (Graphics& g)
  115. {
  116. //[UserPrePaint] Add your own custom painting code here..
  117. //[/UserPrePaint]
  118. g.fillAll (Colours::white);
  119. //[UserPaint] Add your own custom painting code here..
  120. //[/UserPaint]
  121. }
  122. void AudioDemoTabComponent::resized()
  123. {
  124. tabbedComponent->setBounds (0, 0, getWidth() - 0, getHeight() - 0);
  125. //[UserResized] Add your own custom resize handling here..
  126. //[/UserResized]
  127. }
  128. //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
  129. //==============================================================================
  130. Component* createAudioDemo()
  131. {
  132. return new AudioDemoTabComponent();
  133. }
  134. //[/MiscUserCode]
  135. //==============================================================================
  136. #if 0
  137. /* -- Introjucer information section --
  138. This is where the Introjucer stores the metadata that describe this GUI layout, so
  139. make changes in here at your peril!
  140. BEGIN_JUCER_METADATA
  141. <JUCER_COMPONENT documentType="Component" className="AudioDemoTabComponent" componentName=""
  142. parentClasses="public Component" constructorParams="" variableInitialisers=""
  143. snapPixels="8" snapActive="1" snapShown="1" overlayOpacity="0.330000013"
  144. fixedSize="0" initialWidth="600" initialHeight="400">
  145. <BACKGROUND backgroundColour="ffffffff"/>
  146. <TABBEDCOMPONENT name="new tabbed component" id="83c980d7793cdced" memberName="tabbedComponent"
  147. virtualName="" explicitFocusOrder="0" pos="0 0 0M 0M" orientation="top"
  148. tabBarDepth="30" initialTab="0">
  149. <TAB name="Audio Device Setup" colour="ffd3d3d3" useJucerComp="1"
  150. contentClassName="" constructorParams="deviceManager" jucerComponentFile="AudioDemoSetupPage.cpp"/>
  151. <TAB name="File Playback" colour="ffd3d3d3" useJucerComp="1" contentClassName=""
  152. constructorParams="deviceManager" jucerComponentFile="AudioDemoPlaybackPage.cpp"/>
  153. <TAB name="Synth Playback" colour="ffd3d3d3" useJucerComp="1" contentClassName=""
  154. constructorParams="deviceManager" jucerComponentFile="AudioDemoSynthPage.cpp"/>
  155. <TAB name="Latency Test" colour="ffd3d3d3" useJucerComp="1" contentClassName=""
  156. constructorParams="deviceManager" jucerComponentFile="AudioDemoLatencyPage.cpp"/>
  157. <TAB name="Recording" colour="ffd3d3d3" useJucerComp="1" contentClassName=""
  158. constructorParams="deviceManager" jucerComponentFile="AudioDemoRecordPage.cpp"/>
  159. </TABBEDCOMPONENT>
  160. </JUCER_COMPONENT>
  161. END_JUCER_METADATA
  162. */
  163. #endif
  164. //[EndFile] You can add extra defines here...
  165. //[/EndFile]