CSL  6.0
CSL_TestComponent.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This is an automatically generated GUI class created by the Projucer!
5 
6  Be careful when adding custom code to these files, as only the code within
7  the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
8  and re-saved.
9 
10  Created with Projucer version: 6.0.0
11 
12  ------------------------------------------------------------------------------
13 
14  The Projucer is part of the JUCE library.
15  Copyright (c) 2017 - ROLI Ltd.
16 
17  ==============================================================================
18 */
19 
20 #pragma once
21 
22 //[Headers] -- You can add your own extra header files here --
23 
24 /// This is the JUCE wrapper for the CSL demos
25 ///
26 /// See the copyright notice and acknowledgment of authors in the file COPYRIGHT
27 ///
28 /// It loads a set of test code files for CSL tests and displays a menu of the tests.
29 ///
30 /// USAGE: CSL_Juce [suite#] [test#]
31 ///
32 /// The main() function reads argv[1] as the suite selector (from the above list, 1-based)
33 /// and argv[2] as the test within the suite, e.g., use "2 10" to select the 10th test in the
34 /// srcTestList suite ("Vector IFFT" -- found at the bottom of Test_Sources.cpp).
35 /// This is useful for debugging; set up the GUI to run the test you're working on.
36 ///
37 /// The demo also writes the last used test to ~/.cslrc so that it starts up with the same demo.
38 ///
39 
40 #include "CSL_Includes.h" // CSL core
41 #include "JuceHeader.h"
42 //#include "src/juce_appframework/audio/devices/juce_AudioDeviceManager.h"
43 #include "JCSL_Widgets.h" // my custom widgets (VU meter and oscilloscope)
44 
45 // Support code: CSL player thread
46 
47 // a thread class that takes a function
48 
49 typedef void* (*ThreadFunc)(void*); // Thread function signature
50 
51 // Support classes
52 
53 /// GThread takes a CSL test function and runs it
54 
55 class GThread : public juce::Thread {
56 public:
57  GThread(ThreadFunc afcn) : Thread("CSL Thread"), fcn(afcn) { };
58  void * (*fcn)(void *);
59 
60  void run() {
61  (*fcn)(NULL); // call my function
62  csl::sleepMsec(100); // wait a bit for it to stop
63  };
64 };
65 
66 /// LThread loops a CThread
67 
68 class CSLComponent; // forward decl
69 
70 class LThread : public juce::Thread {
71 public:
72  LThread(GThread * athr, CSLComponent * acomp, bool looper)
73  : Thread("CSL Thread"),
74  thr(athr), comp(acomp), loop(looper) { };
75  GThread * thr;
77  bool loop;
78 
79  void run();
80 };
81 
82 using namespace juce;
83 
84 //[/Headers]
85 
86 
87 
88 //==============================================================================
89 /**
90  //[Comments]
91  An auto-generated component, created by the Jucer.
92 
93  Describe your class and how it works here!
94  //[/Comments]
95 */
96 class CSLComponent : public Component,
97  public AudioIODeviceCallback,
98  public Timer,
99  public Button::Listener,
100  public ComboBox::Listener,
101  public Slider::Listener
102 {
103 public:
104  //==============================================================================
105  CSLComponent ();
106  ~CSLComponent() override;
107 
108  //==============================================================================
109  //[UserMethods] -- You can add your own custom methods in this section.
110 
111  void audioDeviceIOCallback (const float** inputChannelData,
112  int totalNumInputChannels,
113  float** outputChannelData,
114  int totalNumOutputChannels,
115  int numSamples);
116  void audioDeviceAboutToStart (juce::AudioIODevice* device);
117  void audioDeviceStopped();
118  void setComboLabels(unsigned which);
119  void timerCallback();
120  void recordOnOff();
121  void startStop();
122 
123  bool playing, recrding, loop, displayMode;
124 
125  //[/UserMethods]
126 
127  void paint (Graphics& g) override;
128  void resized() override;
129  void buttonClicked (Button* buttonThatWasClicked) override;
130  void comboBoxChanged (ComboBox* comboBoxThatHasChanged) override;
131  void sliderValueChanged (Slider* sliderThatWasMoved) override;
132 
133 
134 
135 private:
136  //[UserVariables] -- You can add your own custom variables in this section.
137 
138  juce::AudioDeviceManager mAudioDeviceManager; // JUCE audio
139  csl::Buffer outBuffer; // main CSL buffer for output
140  GThread * playThread; // test play and looper threads
142  int whichTests; // test selector
143  float amplValue; // amp scale
144 
145  //[/UserVariables]
146 
147  //==============================================================================
148  std::unique_ptr<TextButton> playButton;
149  std::unique_ptr<TextButton> quitButton;
150  std::unique_ptr<ComboBox> testCombo;
151  std::unique_ptr<AudioWaveformDisplay> oscilloscopeL;
152  std::unique_ptr<Label> label;
153  std::unique_ptr<TextButton> prefsButton;
154  std::unique_ptr<Label> cpuLabel;
155  std::unique_ptr<AudioWaveformDisplay> oscilloscopeR;
156  std::unique_ptr<VUMeter> VUMeterL;
157  std::unique_ptr<VUMeter> VUMeterR;
158  std::unique_ptr<Slider> scaleSlider;
159  std::unique_ptr<Slider> amplitudeSlider;
160  std::unique_ptr<ToggleButton> loopButton;
161  std::unique_ptr<ComboBox> familyCombo;
162  std::unique_ptr<ToggleButton> recordButton;
163 
164 
165  //==============================================================================
166  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CSLComponent)
167 };
168 
169 //[EndFile] You can add extra defines here...
170 //[/EndFile]
171 
std::unique_ptr< AudioWaveformDisplay > oscilloscopeL
bool sleepMsec(float dur)
Definition: CGestalt.cpp:372
std::unique_ptr< VUMeter > VUMeterL
std::unique_ptr< Slider > scaleSlider
void *(* ThreadFunc)(void *)
This is the JUCE wrapper for the CSL demos.
std::unique_ptr< ComboBox > testCombo
std::unique_ptr< TextButton > prefsButton
std::unique_ptr< Label > cpuLabel
GThread * thr
std::unique_ptr< Slider > amplitudeSlider
LThread(GThread *athr, CSLComponent *acomp, bool looper)
GThread takes a CSL test function and runs it.
std::unique_ptr< AudioWaveformDisplay > oscilloscopeR
void *(* fcn)(void *)
std::unique_ptr< Label > label
GThread(ThreadFunc afcn)
std::unique_ptr< ComboBox > familyCombo
std::unique_ptr< TextButton > playButton
GThread * playThread
csl::Buffer outBuffer
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
Definition: CSL_Core.h:106
juce::AudioDeviceManager mAudioDeviceManager
LThread * loopThread
std::unique_ptr< TextButton > quitButton
std::unique_ptr< ToggleButton > loopButton
std::unique_ptr< VUMeter > VUMeterR
std::unique_ptr< ToggleButton > recordButton
CSLAbstComponent * comp
CSLComponent * comp