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.

213 lines
7.4KB

  1. /*
  2. ==============================================================================
  3. This is an automatically generated file created by the Jucer!
  4. Creation date: 1 May 2011 12:07:35pm
  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 "AudioDemoTabComponent.h"
  17. #include "AudioDemoSetupPage.h"
  18. #include "AudioDemoPlaybackPage.h"
  19. #include "AudioDemoSynthPage.h"
  20. #include "AudioDemoLatencyPage.h"
  21. #include "AudioDemoRecordPage.h"
  22. //[MiscUserDefs] You can add your own user definitions and misc code here...
  23. LiveAudioInputDisplayComp::LiveAudioInputDisplayComp()
  24. {
  25. nextSample = subSample = 0;
  26. accumulator = 0;
  27. zeromem (samples, sizeof (samples));
  28. setOpaque (true);
  29. startTimer (1000 / 50); // use a timer to keep repainting this component
  30. }
  31. LiveAudioInputDisplayComp::~LiveAudioInputDisplayComp()
  32. {
  33. }
  34. void LiveAudioInputDisplayComp::paint (Graphics& g)
  35. {
  36. g.fillAll (Colours::black);
  37. g.setColour (Colours::green);
  38. const float midY = getHeight() * 0.5f;
  39. int sampleNum = (nextSample + numElementsInArray (samples) - 1);
  40. for (int x = jmin (getWidth(), numElementsInArray (samples)); --x >= 0;)
  41. {
  42. const float sampleSize = midY * samples [sampleNum-- % numElementsInArray (samples)];
  43. g.drawVerticalLine (x, midY - sampleSize, midY + sampleSize);
  44. }
  45. }
  46. void LiveAudioInputDisplayComp::timerCallback()
  47. {
  48. repaint();
  49. }
  50. void LiveAudioInputDisplayComp::audioDeviceAboutToStart (AudioIODevice*)
  51. {
  52. zeromem (samples, sizeof (samples));
  53. }
  54. void LiveAudioInputDisplayComp::audioDeviceStopped()
  55. {
  56. zeromem (samples, sizeof (samples));
  57. }
  58. void LiveAudioInputDisplayComp::audioDeviceIOCallback (const float** inputChannelData, int numInputChannels,
  59. float** outputChannelData, int numOutputChannels, int numSamples)
  60. {
  61. for (int i = 0; i < numSamples; ++i)
  62. {
  63. for (int chan = 0; chan < numInputChannels; ++chan)
  64. {
  65. if (inputChannelData[chan] != 0)
  66. accumulator += fabsf (inputChannelData[chan][i]);
  67. }
  68. const int numSubSamples = 100; // how many input samples go onto one pixel.
  69. const float boost = 10.0f; // how much to boost the levels to make it more visible.
  70. if (subSample == 0)
  71. {
  72. samples[nextSample] = accumulator * boost / numSubSamples;
  73. nextSample = (nextSample + 1) % numElementsInArray (samples);
  74. subSample = numSubSamples;
  75. accumulator = 0;
  76. }
  77. else
  78. {
  79. --subSample;
  80. }
  81. }
  82. // We need to clear the output buffers, in case they're full of junk..
  83. for (int i = 0; i < numOutputChannels; ++i)
  84. if (outputChannelData[i] != 0)
  85. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  86. }
  87. //[/MiscUserDefs]
  88. //==============================================================================
  89. AudioDemoTabComponent::AudioDemoTabComponent ()
  90. : tabbedComponent (0)
  91. {
  92. addAndMakeVisible (tabbedComponent = new TabbedComponent (TabbedButtonBar::TabsAtTop));
  93. tabbedComponent->setTabBarDepth (30);
  94. tabbedComponent->addTab (L"Audio Device Setup", Colours::lightgrey, new AudioDemoSetupPage (deviceManager), true);
  95. tabbedComponent->addTab (L"File Playback", Colours::lightgrey, new AudioDemoPlaybackPage (deviceManager), true);
  96. tabbedComponent->addTab (L"Synth Playback", Colours::lightgrey, new AudioDemoSynthPage (deviceManager), true);
  97. tabbedComponent->addTab (L"Latency Test", Colours::lightgrey, new AudioDemoLatencyPage (deviceManager), true);
  98. tabbedComponent->addTab (L"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. deleteAndZero (tabbedComponent);
  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. /* -- Jucer information section --
  140. This is where the Jucer puts all of its metadata, so don't change anything in here!
  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