@@ -73,7 +73,7 @@ void DiatonicCV::process(const ProcessArgs &args){
7373 for (int c = 0 ; c < 16 ; c++) {
7474 float v = inputs[POLY_INPUT ].getVoltage (c);
7575 polyNotes_v[c] = v;
76- polyNotes[c] = voltage_to_note_int (v);
76+ polyNotes[c] = voltage_to_note_with_octave (v);
7777 }
7878 // sort the notes in ascending order
7979 std::sort (std::begin (polyNotes), polyNotes + polyChannels);
@@ -85,6 +85,14 @@ void DiatonicCV::process(const ProcessArgs &args){
8585 }
8686 }
8787
88+ // remove octave
89+ if (polyChannels > 0 ){
90+ int root_octave = (int )floor ((float )polyNotes[0 ] / 12 .0f );
91+ for (int c = 0 ; c < polyChannels; c++) {
92+ polyNotes[c] -= root_octave * 12 ;
93+ }
94+ }
95+
8896 float octave_v = params[OCTAVE_PARAM ].getValue ();
8997 if (inputs[OCTAVE_INPUT ].isConnected ()){
9098 octave_v = inputs[OCTAVE_INPUT ].getVoltage ();
@@ -94,30 +102,28 @@ void DiatonicCV::process(const ProcessArgs &args){
94102 float chord_v = params[CHORD_PARAM ].getValue ();
95103 if (inputs[CHORD_INPUT ].isConnected ()){
96104 chord_v = inputs[CHORD_INPUT ].getVoltage ();
97- if (chord_v < 0 .0f ) chord_v = 0 .0f ;
98- if (chord_v > 7 .0f ) chord_v = 7 .0f ;
99105 }
100- chord = (int )round (chord_v);
106+ chord = (int )round (clamp ( chord_v, 0 . 0f , 6 . 0f ) );
101107
102108 float type_v = params[TYPE_PARAM ].getValue ();
103109 if (inputs[TYPE_INPUT ].isConnected ()){
104110 type_v = inputs[TYPE_INPUT ].getVoltage ();
105- if (type_v < 0 .0f ) type_v = 0 .0f ;
106- if (type_v > 3 .0f ) type_v = 3 .0f ;
107111 }
108- chord_type = (int )round (type_v);
112+ chord_type = (int )round (clamp ( type_v, 0 . 0f , 2 . 0f ) );
109113
110114 // inversion
111- inversion = ( int ) round ( params[INVERSION_PARAM ].getValue () );
112- if (inputs[INVERSION_PARAM ].isConnected ()){
113- inversion = ( int ) clamp ( round ( inputs[INVERSION_PARAM ].getVoltage ()), 0 . 0f , 3 . 0f );
115+ float inversion_v = params[INVERSION_PARAM ].getValue ();
116+ if (inputs[INVERSION_INPUT ].isConnected ()){
117+ inversion_v = inputs[INVERSION_INPUT ].getVoltage ();
114118 }
119+ inversion = (int )round (clamp (inversion_v, 0 .0f , 4 .0f ));
115120
116121 // voicing
117- voicing = ( int ) round ( params[VOICING_PARAM ].getValue () );
118- if (inputs[VOICING_PARAM ].isConnected ()){
119- voicing = ( int ) clamp ( round ( inputs[VOICING_PARAM ].getVoltage ()), 0 . 0f , 4 . 0f );
122+ float voicing_v = params[VOICING_PARAM ].getValue ();
123+ if (inputs[VOICING_INPUT ].isConnected ()){
124+ voicing_v = inputs[VOICING_INPUT ].getVoltage ();
120125 }
126+ voicing = (int )round (clamp (voicing_v, 0 .0f , 4 .0f ));
121127
122128 // Make the chord
123129 playing_chord = get_diatonic_chord (polyNotes, polyChannels, octave, chord, chord_type, inversion, voicing);
@@ -137,7 +143,7 @@ void DiatonicCV::process(const ProcessArgs &args){
137143struct DiatonicCVWidget : ModuleWidget {
138144 struct ChordDisplayWidget : TransparentWidget {
139145 DiatonicCV* module ;
140- char text[10 ];
146+ char text[13 ];
141147
142148 ChordDisplayWidget (Vec _pos, Vec _size, DiatonicCV* _module) {
143149 box.size = _size;
@@ -159,7 +165,7 @@ struct DiatonicCVWidget : ModuleWidget {
159165 if (module != NULL && module ->playing_chord .num_notes > 2 ){
160166 detect_chord_name_simple (module ->playing_chord ,text);
161167 }else {
162- snprintf (text, 9 , " " );
168+ snprintf (text, 13 , " " );
163169 }
164170
165171 nvgText (args.vg , textPos.x , textPos.y , text, NULL );
@@ -179,7 +185,7 @@ struct DiatonicCVWidget : ModuleWidget {
179185
180186 const int centerX = box.size .x / 2 ;
181187
182- ChordDisplayWidget* display = new ChordDisplayWidget (Vec (centerX, 55 ), Vec (76 , 29 ), module );
188+ ChordDisplayWidget* display = new ChordDisplayWidget (Vec (centerX, 55 ), Vec (box. size . x - 5 , 29 ), module );
183189 addChild (display);
184190
185191 addInput (createInputCentered<PJ301MPort>(Vec (centerX, 95 ), module , DiatonicCV::POLY_INPUT ));
0 commit comments