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
@@ -349,8 +352,8 @@ class OwlButton : public OwlParameterBase {
349352 * OwlUI : Faust User Interface builder. Passed to buildUserInterface OwlU
350353 * ensures the mapping between owl parameters and faust widgets. It relies on
351354 * specific metadata "...[OWL:PARAMETER_X]..." in widget's label for that. For
352- * example any faust widget with metadata [OWL:PARAMETER_B ] will be controlled
353- * by PARAMETER_B (the second knob).
355+ * example any faust widget with metadata [OWL:B ] will be controlled by
356+ * PARAMETER_B (the second knob).
354357 *
355358 ***************************************************************************************/
356359
@@ -359,7 +362,7 @@ class OwlButton : public OwlParameterBase {
359362#define NO_PARAMETER ((PatchParameterId)-1 )
360363#define NO_BUTTON ((PatchButtonId)-1 )
361364
362- MonoVoiceAllocator allocator (fFreq , fGain , fGate , fBend );
365+ MonoVoiceAllocator allocator (fKey , fFreq , fGain , fGate , fBend );
363366VoltsPerOctave* fVOctInput ;
364367VoltsPerOctave* fVOctOutput ;
365368
@@ -385,6 +388,10 @@ class OwlUI : public UI {
385388 fParameterTable [fParameterIndex ++] =
386389 new OwlVariable (fPatch , &fBend , zone, label, init, lo, hi);
387390 }
391+ else if (meta.midiOn && strcasecmp (label, " key" ) == 0 ) {
392+ fParameterTable [fParameterIndex ++] =
393+ new OwlVariable (fPatch , &fKey , zone, label, init, lo, hi);
394+ }
388395 else if (fParameter != NO_PARAMETER) {
389396 fParameterTable [fParameterIndex ++] =
390397 new OwlParameter (fPatch , fParameter , zone, label, init, lo, hi);
@@ -451,7 +458,7 @@ class OwlUI : public UI {
451458 delete fVOctOutput ;
452459 }
453460
454- // should be called before compute() to update widget's zones registered as Owl parameters
461+ // should be called before compute() to update widget's zones registered as OWL parameters
455462 void update () {
456463 for (int i = 0 ; i < fParameterIndex ; i++)
457464 fParameterTable [i]->update ();
@@ -513,7 +520,6 @@ class OwlUI : public UI {
513520 if (strcasecmp (k, " OWL" ) == 0 ) {
514521 if (strncasecmp (id, " PARAMETER_" , 10 ) == 0 )
515522 id += 10 ;
516-
517523 if (strlen (id) == 1 ) {
518524 // Single char parameter name.
519525 // Note that we can use I - P as aliases for AA-AH.
@@ -581,12 +587,13 @@ class OwlUI : public UI {
581587 else if (strcasecmp (id, " PUSH" ) == 0 )
582588 fButton = PUSHBUTTON;
583589 }
584- else if (strcasecmp (k, " midi" ) == 0 ) {
585- // todo!
586- // if (strcasecmp(id,"pitchwheel") == 0) fParameter = PARAMETER_G;
587- // // mapped to pitch wheel declare(&fHslider1, "midi",
588- // "pitchwheel"); declare(&fButton1, "midi", "ctrl 64");
589- }
590+ // else if (strcasecmp(k, "midi") == 0) {
591+ // if (strcasecmp(id, "pitchwheel") == 0){ // PB
592+ // }else if (strcasecmp(id, "ctrl") == 0){ // CC
593+ // }else if (strcasecmp(id, "chanpress") == 0){ // AT
594+ // }else if (strcasecmp(id, "pgm") == 0){ // PC
595+ // }
596+ // }
590597 }
591598
592599 // -- V/Oct
0 commit comments