CSL  6.0
CSLMIDIComponent.cpp
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This is an automatically generated file created by the Jucer!
5 
6  Creation date: 27 Oct 2009 10:19:22 pm
7 
8  Be careful when adding custom code to these files, as only the code within
9  the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
10  and re-saved.
11 
12  Jucer version: 1.12
13 
14  ------------------------------------------------------------------------------
15 
16  The Jucer is part of the JUCE library - "Jules' Utility Class Extensions"
17  Copyright 2004-6 by Raw Material Software ltd.
18 
19  ==============================================================================
20 */
21 
22 //[Headers] You can add your own extra header files here...
23 //[/Headers]
24 
25 #include "CSLMIDIComponent.h"
26 
27 
28 //[MiscUserDefs] You can add your own user definitions and misc code here...
29 
30 #include "MIDIIOJ.h"
31 #include <iostream>
32 using namespace csl;
33 
34 // Globals are here
35 
36 extern IO * theIO; // global IO object accessed by other threads
37 Label* gCPULabel = 0; // CPU % label
38 AudioDeviceManager * gAudioDeviceManager = 0; // global JUCE audio device mgr
39 unsigned argCnt = 0; // globals for argc/v from cmd-line
40 char **argVals;
41 VoidFcnPtrN * gFcn = 0; // test function ptr
42 
43 //[/MiscUserDefs]
44 
45 //==============================================================================
47  : quitButton (0),
48  label (0),
49  textEditor (0),
50  clearButton (0),
51  audioDeviceSelector (0),
52  filtButton (0)
53 {
54  addAndMakeVisible (quitButton = new TextButton (T("new button")));
55  quitButton->setButtonText (T("Quit"));
56  quitButton->addButtonListener (this);
57 
58  addAndMakeVisible (label = new Label (T("new label"),
59  T("CSL MIDI Input Dump")));
60  label->setFont (Font (24.0000f, Font::plain));
61  label->setJustificationType (Justification::centredLeft);
62  label->setEditable (false, false, false);
63  label->setColour (TextEditor::textColourId, Colours::black);
64  label->setColour (TextEditor::backgroundColourId, Colour (0x0));
65 
66  addAndMakeVisible (textEditor = new TextEditor (T("new text editor")));
67  textEditor->setMultiLine (false);
68  textEditor->setReturnKeyStartsNewLine (false);
69  textEditor->setReadOnly (false);
70  textEditor->setScrollbarsShown (true);
71  textEditor->setCaretVisible (true);
72  textEditor->setPopupMenuEnabled (true);
73  textEditor->setText (String::empty);
74 
75  addAndMakeVisible (clearButton = new TextButton (T("new button")));
76  clearButton->setButtonText (T("Clear"));
77  clearButton->addButtonListener (this);
78 
79 // addAndMakeVisible (audioDeviceSelector = new AudioDeviceSelectorComponent());
80 // audioDeviceSelector->setName (T("new component"));
81 
82  addAndMakeVisible (filtButton = new ToggleButton (T("new toggle button")));
83  filtButton->setButtonText (T("Filter Note On/Off"));
84  filtButton->addButtonListener (this);
85 
86 
87  //[UserPreSize]
88  //[/UserPreSize]
89 
90  setSize (650, 350);
91 
92  //[Constructor] You can add your own custom stuff here..
93 
94  filt = false;
95  cLin = new char[CSL_STR_LEN];
96  cLin[0] = 0;
97  textEditor->setMultiLine (true, true);
98  textEditor->setReturnKeyStartsNewLine (true);
99  textEditor->setText (T("MIDI Messages\n\n"));
100  textEditor->setPasswordCharacter(0);
101 
102 // AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager,
103 // const int minAudioInputChannels,
104 // const int maxAudioInputChannels,
105 // const int minAudioOutputChannels,
106 // const int maxAudioOutputChannels,
107 // const bool showMidiInputOptions,
108 // const bool showMidiOutputSelector,
109 // const bool showChannelsAsStereoPairs,
110 // const bool hideAdvancedOptionsWithButton);
111 
112  addAndMakeVisible (audioDeviceSelector = new AudioDeviceSelectorComponent
114  0, 0, 0, 0,
115  true, true, false, false));
116  audioDeviceSelector->setName (T("new component"));
117  audioDeviceSelector->setSize (500, 450);
118 
119 /// Create a MIDI in and attach a filtering listener to it
120 
121  mIn = new MIDIIn; // create the midi in
122  mIn->open(DEFAULT_MIDI_IN); // open it
123 // lst.mPeriod = 0.25;
124 // this->mKey = kNoteOn; // filter noteOn events
125  mIn->attachObserver(this); // attach this as observer of input
126  logMsg("Start MIDI listener");
127  mIn->start(); // start midi in
128  this->startTimer(100); // 0.1-sec timer
129 
130  //[/Constructor]
131 }
132 
134 {
135  //[Destructor_pre]. You can add your own custom destruction code here..
136 
137  logMsg("done.");
138  mIn->stop();
139  mIn->close();
140 
141  //[/Destructor_pre]
142 
143  deleteAndZero (quitButton);
144  deleteAndZero (label);
145  deleteAndZero (textEditor);
146  deleteAndZero (clearButton);
147  deleteAndZero (audioDeviceSelector);
148  deleteAndZero (filtButton);
149 
150  //[Destructor]. You can add your own custom destruction code here..
151  //[/Destructor]
152 }
153 
154 //==============================================================================
155 void CSLMIDIComponent::paint (Graphics& g)
156 {
157  //[UserPrePaint] Add your own custom painting code here..
158  //[/UserPrePaint]
159 
160  g.fillAll (Colour (0xff829bb1));
161 
162  //[UserPaint] Add your own custom painting code here..
163  //[/UserPaint]
164 }
165 
167 {
168  quitButton->setBounds (272, 312, 104, 32);
169  label->setBounds (16, 288, 224, 24);
170  textEditor->setBounds (392, 8, 248, 336);
171  clearButton->setBounds (272, 272, 102, 32);
172 // audioDeviceSelector->setBounds (16, 16, 360, 200);
173  filtButton->setBounds (232, 232, 144, 24);
174  //[UserResized] Add your own custom resize handling here..
175  //[/UserResized]
176 }
177 
178 void CSLMIDIComponent::buttonClicked (Button* buttonThatWasClicked)
179 {
180  //[UserbuttonClicked_Pre]
181  //[/UserbuttonClicked_Pre]
182 
183  if (buttonThatWasClicked == quitButton)
184  {
185  //[UserButtonCode_quitButton] -- add your button handler code here..
186 
187  JUCEApplication::quit();
188 
189  //[/UserButtonCode_quitButton]
190  }
191  else if (buttonThatWasClicked == clearButton)
192  {
193  //[UserButtonCode_clearButton] -- add your button handler code here..
194 
195  textEditor->clear();
196 
197  //[/UserButtonCode_clearButton]
198  }
199  else if (buttonThatWasClicked == filtButton)
200  {
201  //[UserButtonCode_filtButton] -- add your button handler code here..
202 
203  filt = ! filt;
204 
205  //[/UserButtonCode_filtButton]
206  }
207 
208  //[UserbuttonClicked_Post]
209 
210  //[/UserbuttonClicked_Post]
211 }
212 
213 
214 
215 //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
216 
217 // update() method takes a MIDI message and prints it
218 
219 void CSLMIDIComponent::update(void * arg) {
220  CMIDIMessage * msg = (CMIDIMessage *) arg;
221  mIn->clear();
222 // logMsg("MIDI msg %d k %d v %d", msg->message, msg->getNote(), msg->getVelocity());
223  if (filt && (! msg->isNoteOnOff()))
224  return;
225  char * cptr = cLin + strlen(cLin);
226  sprintf(cptr, " %.2d k %.2d v %.2d\n", msg->message, msg->getNote(), msg->getVelocity());
227  changed = true; // set changed flag for timer thread
228 }
229 
230 // timer call checks changed and prints messages
231 
233 // CSLAbstComponent::timerCallback();
234  if ( ! changed) return;
235  String lStr(cLin);
236  const MessageManagerLock mmLock; // create the lock so we can call the GUI from this thread
237  textEditor->setCaretPosition(textEditor->getTotalNumChars());
238  textEditor->insertTextAtCursor(lStr);
239  cLin[0] = 0; // reset string
240  changed = false; // reset flag
241 }
242 
243 // create the component -- called from main()
244 
245 Component* createCSLComponent() {
246  return new CSLMIDIComponent();
247 }
248 
249 //[/MiscUserCode]
250 
251 
252 //==============================================================================
253 #if 0
254 /* -- Jucer information section --
255 
256  This is where the Jucer puts all of its metadata, so don't change anything in here!
257 
258 BEGIN_JUCER_METADATA
259 
260 <JUCER_COMPONENT documentType="Component" className="CSLMIDIComponent" componentName=""
261  parentClasses="public CSLAbstComponent" constructorParams=""
262  variableInitialisers="" snapPixels="8" snapActive="1" snapShown="1"
263  overlayOpacity="0.330000013" fixedSize="1" initialWidth="650"
264  initialHeight="350">
265  <BACKGROUND backgroundColour="ff829bb1"/>
266  <TEXTBUTTON name="new button" id="c0692c09dc89d8ab" memberName="quitButton"
267  virtualName="" explicitFocusOrder="0" pos="272 312 104 32" buttonText="Quit"
268  connectedEdges="0" needsCallback="1" radioGroupId="0"/>
269  <LABEL name="new label" id="7dccc1a8e08b292d" memberName="label" virtualName=""
270  explicitFocusOrder="0" pos="16 288 224 24" edTextCol="ff000000"
271  edBkgCol="0" labelText="CSL MIDI Input Dump" editableSingleClick="0"
272  editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default font"
273  fontsize="24" bold="0" italic="0" justification="33"/>
274  <TEXTEDITOR name="new text editor" id="2df8e41197d78c6c" memberName="textEditor"
275  virtualName="" explicitFocusOrder="0" pos="392 8 248 336" initialText=""
276  multiline="0" retKeyStartsLine="0" readonly="0" scrollbars="1"
277  caret="1" popupmenu="1"/>
278  <TEXTBUTTON name="new button" id="fec4a7f49a098957" memberName="clearButton"
279  virtualName="" explicitFocusOrder="0" pos="272 272 102 32" buttonText="Clear"
280  connectedEdges="0" needsCallback="1" radioGroupId="0"/>
281  <GENERICCOMPONENT name="new component" id="b1bc16d7b6e9ef79" memberName="audioDeviceSelector"
282  virtualName="" explicitFocusOrder="0" pos="16 16 360 200" class="AudioDeviceSelectorComponent"
283  params=""/>
284  <TOGGLEBUTTON name="new toggle button" id="9ff31f17342ed08f" memberName="filtButton"
285  virtualName="" explicitFocusOrder="0" pos="232 232 144 24" buttonText="Filter Note On/Off"
286  connectedEdges="0" needsCallback="1" radioGroupId="0" state="0"/>
287 </JUCER_COMPONENT>
288 
289 END_JUCER_METADATA
290 */
291 #endif
void logMsg(const char *format,...)
These are the public logging messages.
Definition: CGestalt.cpp:292
Label * gCPULabel
virtual void clear()
stop MIDI stream
Definition: MIDIIOJ.cpp:102
unsigned getVelocity()
Definition: MIDIIOJ.cpp:32
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
AudioDeviceManager * gAudioDeviceManager
void paint(Graphics &g)
bool filt
filter note on-offs
MIDIIn class is-a MidiInputCallback too, and an "input-ready" flag.
Definition: MIDIIOJ.h:130
AudioDeviceSelectorComponent * audioDeviceSelector
void update(void *arg)
MIDI observer update method.
void buttonClicked(Button *buttonThatWasClicked)
virtual void stop()
stop MIDI stream
Definition: MIDIIOJ.cpp:241
AudioDeviceManager mAudioDeviceManager
JUCE audio.
void VoidFcnPtrN(void)
the truly void fcn pointer
Definition: CSL_Types.h:222
IO – the abstract I/O scheduling class; subclasses interface to specific I/O APIs.
Definition: CSL_Core.h:752
TextButton * clearButton
char * cLin
message to add
#define DEFAULT_MIDI_IN
Definition: CSL_Types.h:158
ToggleButton * filtButton
char ** argVals
bool isNoteOnOff()
Definition: MIDIIOJ.cpp:21
void attachObserver(Observer *)
(possibly notify obersvers on my death)
Definition: CGestalt.cpp:502
#define CSL_STR_LEN
default long string length
Definition: CSL_Types.h:123
Component * createCSLComponent()
unsigned getNote()
Definition: MIDIIOJ.cpp:31
TextButton * quitButton
VoidFcnPtrN * gFcn
CMIDIMessage class (mapped to juce::MidiMessage)
Definition: MIDIIOJ.h:46
CMIDIMessageType message
event type
Definition: MIDIIOJ.h:73
virtual void open(int deviceID)
open a device
Definition: MIDIIOJ.cpp:218
TextEditor * textEditor
IO * theIO
virtual void close()
closing MIDI stream
Definition: MIDIIOJ.cpp:95
virtual void start()
start MIDI stream
Definition: MIDIIOJ.cpp:233
juce_UseDebuggingNewOperator csl::MIDIIn * mIn
MIDI input.
unsigned argCnt