3939#include " Patch.h"
4040#include " VoltsPerOctave.h"
4141
42- // We have to undefine min/max from Owl 's basicmaths.h, otherwise they cause
42+ // We have to undefine min/max from OWL 's basicmaths.h, otherwise they cause
4343// errors when Faust calls functions with the same names in std:: namespace
4444#undef min
4545#undef max
5454#include " faust/gui/UI.h"
5555#include " faust/gui/meta.h"
5656
57- static float fFreq , fGain , fGate ;
57+ static float fKey , fFreq , fGain , fGate ;
5858static float fBend = 1 .0f ;
5959
6060class MonoVoiceAllocator {
61+ float & key;
6162 float & freq;
6263 float & gain;
6364 float & gate;
@@ -66,8 +67,9 @@ class MonoVoiceAllocator {
6667 uint8_t lastNote = 0 ;
6768
6869public:
69- MonoVoiceAllocator (float & fq, float & gn, float & gt, float & bd)
70- : freq(fq)
70+ MonoVoiceAllocator (float & ky, float & fq, float & gn, float & gt, float & bd)
71+ : key(ky)
72+ , freq(fq)
7173 , gain(gn)
7274 , gate(gt)
7375 , bend(bd) {
@@ -114,6 +116,7 @@ class MonoVoiceAllocator {
114116 void noteOn (uint8_t note, uint16_t velocity, uint16_t delay) {
115117 if (lastNote < 16 )
116118 notes[lastNote++] = note;
119+ key = note;
117120 freq = noteToHz (note);
118121 gain = velocityToGain (velocity);
119122 gate = 1 .0f ;
@@ -130,11 +133,12 @@ class MonoVoiceAllocator {
130133 notes[i] = notes[i + 1 ];
131134 i++;
132135 }
133- freq = noteToHz (notes[lastNote - 1 ]);
136+ key = notes[lastNote - 1 ];
137+ freq = noteToHz (key);
134138 }
135139 else {
136140 gate = 0 .0f ;
137- lastNote = 0 ;
141+ lastNote = 0 ;
138142 }
139143 }
140144 void allNotesOff () {
@@ -153,8 +157,7 @@ enum ParserState {
153157 * To enable MIDI in current patch, add this to source Faust file:
154158 * declare options "[midi:on]";
155159 *
156- * You can also add descrpiption to be displayed with debugMessage function like
157- * this:
160+ * You can also add a description to be displayed like this:
158161 * declare message "Hello World";
159162 *
160163 * To add V/Oct scaling support, use something likes this:
@@ -251,8 +254,8 @@ class MetaData : public Meta {
251254
252255/* *************************************************************************************
253256 *
254- * OwlParameter : object used by OwlUI to ensures the connection between an Owl
255- * parameter and a Faust widget
257+ * OwlParameter : object used by OwlUI to ensures the connection between an OWL
258+ * parameter and a FAUST widget
256259 *
257260 ***************************************************************************************/
258261
@@ -374,8 +377,8 @@ class OwlCheckbox : public OwlParameterBase {
374377 * OwlUI : Faust User Interface builder. Passed to buildUserInterface OwlU
375378 * ensures the mapping between owl parameters and faust widgets. It relies on
376379 * specific metadata "...[OWL:PARAMETER_X]..." in widget's label for that. For
377- * example any faust widget with metadata [OWL:PARAMETER_B ] will be controlled
378- * by PARAMETER_B (the second knob).
380+ * example any faust widget with metadata [OWL:B ] will be controlled by
381+ * PARAMETER_B (the second knob).
379382 *
380383 ***************************************************************************************/
381384
@@ -384,7 +387,7 @@ class OwlCheckbox : public OwlParameterBase {
384387#define NO_PARAMETER ((PatchParameterId)-1 )
385388#define NO_BUTTON ((PatchButtonId)-1 )
386389
387- MonoVoiceAllocator allocator (fFreq , fGain , fGate , fBend );
390+ MonoVoiceAllocator allocator (fKey , fFreq , fGain , fGate , fBend );
388391VoltsPerOctave* fVOctInput ;
389392VoltsPerOctave* fVOctOutput ;
390393
@@ -410,6 +413,10 @@ class OwlUI : public UI {
410413 fParameterTable [fParameterIndex ++] =
411414 new OwlVariable (fPatch , &fBend , zone, label, init, lo, hi);
412415 }
416+ else if (meta.midiOn && strcasecmp (label, " key" ) == 0 ) {
417+ fParameterTable [fParameterIndex ++] =
418+ new OwlVariable (fPatch , &fKey , zone, label, init, lo, hi);
419+ }
413420 else if (fParameter != NO_PARAMETER) {
414421 fParameterTable [fParameterIndex ++] =
415422 new OwlParameter (fPatch , fParameter , zone, label, init, lo, hi);
@@ -424,19 +431,7 @@ class OwlUI : public UI {
424431 if (label[strlen (label) - 1 ] != ' >' )
425432 debugMessage (" Add '>' character for output parameters" );
426433 if (fParameterIndex < MAXOWLPARAMETERS) {
427- if (meta.midiOn && strcasecmp (label, " freq" ) == 0 ) {
428- fParameterTable [fParameterIndex ++] =
429- new OwlVariable (fPatch , &fFreq , zone, label, lo, lo, hi, true );
430- }
431- else if (meta.midiOn && strcasecmp (label, " gain" ) == 0 ) {
432- fParameterTable [fParameterIndex ++] =
433- new OwlVariable (fPatch , &fGain , zone, label, lo, lo, hi, true );
434- }
435- else if (meta.midiOn && strcasecmp (label, " bend" ) == 0 ) {
436- fParameterTable [fParameterIndex ++] =
437- new OwlVariable (fPatch , &fBend , zone, label, lo, lo, hi, true );
438- }
439- else if (fParameter != NO_PARAMETER) {
434+ if (fParameter != NO_PARAMETER) {
440435 fParameterTable [fParameterIndex ++] = new OwlParameter (
441436 fPatch , fParameter , zone, label, lo, lo, hi, true );
442437 }
@@ -503,7 +498,7 @@ class OwlUI : public UI {
503498 delete fVOctOutput ;
504499 }
505500
506- // should be called before compute() to update widget's zones registered as Owl parameters
501+ // should be called before compute() to update widget's zones registered as OWL parameters
507502 void update () {
508503 for (int i = 0 ; i < fParameterIndex ; i++)
509504 fParameterTable [i]->update ();
@@ -565,7 +560,6 @@ class OwlUI : public UI {
565560 if (strcasecmp (k, " OWL" ) == 0 ) {
566561 if (strncasecmp (id, " PARAMETER_" , 10 ) == 0 )
567562 id += 10 ;
568-
569563 if (strlen (id) == 1 ) {
570564 // Single char parameter name.
571565 // Note that we can use I - P as aliases for AA-AH.
@@ -610,7 +604,7 @@ class OwlUI : public UI {
610604 std::min (int (PARAMETER_DH), param_tmp + *id - ' 0' ));
611605 }
612606 }
613- else if (param_tmp == PARAMETER_B && *id >= ' 0' && *id <= ' 9' ) {
607+ else if (param_tmp == PARAMETER_B && *id > ' 0' && *id <= ' 9' ) {
614608 fButton = PatchButtonId (BUTTON_A + *id - ' 1' );
615609 }
616610 else {
@@ -633,12 +627,13 @@ class OwlUI : public UI {
633627 else if (strcasecmp (id, " PUSH" ) == 0 )
634628 fButton = PUSHBUTTON;
635629 }
636- else if (strcasecmp (k, " midi" ) == 0 ) {
637- // todo!
638- // if (strcasecmp(id,"pitchwheel") == 0) fParameter = PARAMETER_G;
639- // // mapped to pitch wheel declare(&fHslider1, "midi",
640- // "pitchwheel"); declare(&fButton1, "midi", "ctrl 64");
641- }
630+ // else if (strcasecmp(k, "midi") == 0) {
631+ // if (strcasecmp(id, "pitchwheel") == 0){ // PB
632+ // }else if (strcasecmp(id, "ctrl") == 0){ // CC
633+ // }else if (strcasecmp(id, "chanpress") == 0){ // AT
634+ // }else if (strcasecmp(id, "pgm") == 0){ // PC
635+ // }
636+ // }
642637 }
643638
644639 // -- V/Oct
0 commit comments