Skip to content

Commit 5d7d780

Browse files
committed
Various bugfixes
1 parent f40555c commit 5d7d780

4 files changed

Lines changed: 44 additions & 32 deletions

File tree

src/ChordCV.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void ChordCV::process(const ProcessArgs &args){
108108
struct ChordCVWidget : ModuleWidget {
109109
struct ChordDisplayWidget : TransparentWidget {
110110
ChordCV* module;
111-
char text[10];
111+
char text[13];
112112

113113
ChordDisplayWidget(Vec _pos, Vec _size, ChordCV* _module) {
114114
box.size = _size;
@@ -130,7 +130,7 @@ struct ChordCVWidget : ModuleWidget {
130130
if (module != NULL){
131131
get_chord_name(module->root_semi,module->chord_type,module->inverted,module->bass_note,text);
132132
}else{
133-
snprintf(text, 9, " ");
133+
snprintf(text, 13, " ");
134134
}
135135

136136
nvgText(args.vg, textPos.x, textPos.y, text, NULL);

src/DiatonicCV.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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){
137143
struct 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));

src/musiclib.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ float voltage_to_note(float value) {
1717
return semi;
1818
}
1919

20+
int voltage_to_note_with_octave(float value) {
21+
float octave = round(value);
22+
float rest = value - 1.0*octave;
23+
int semi = (int)(octave * 12.0f) + round(rest * 12.0);
24+
return semi;
25+
}
26+
2027
int voltage_to_note_int(float value) {
2128
float octave = round(value);
2229
float rest = value - 1.0*octave;
@@ -177,18 +184,12 @@ struct chord get_diatonic_chord(int* notes, int num_notes, int octave, int chord
177184
int transpose = 0;
178185

179186
//Wrap if needed
180-
if(index >= num_notes){
181-
index -= num_notes;
182-
transpose++;
183-
}
184-
185-
//Wrap again if needed
186-
if(index >= num_notes){
187+
while(index >= num_notes){
187188
index -= num_notes;
188189
transpose++;
189190
}
190191

191-
if(index < num_notes){
192+
if(index < num_notes && index > -1){
192193
return_chord.notes_pre[t] = (transpose * 12) + notes[index];
193194
actual_length++;
194195
}
@@ -364,13 +365,17 @@ void detect_chord_name_simple(struct chord chord, char* text){
364365
if(intervals[0] == MAJOR_SECOND && intervals[1] == PERFECT_FOURTH) chord_type = 5; //sus2
365366
if(intervals[0] == PERFECT_FOURTH && intervals[1] == MAJOR_SECOND) chord_type = 6; //sus4
366367
}
367-
}
368368

369-
if(chord.inversion > 0){
370-
int bass_note = chord.notes[0] % 12;
371-
sprintf(text, "%s%s/%s", NOTE_NAMES[chord.notes_pre[0]], CHORD_TYPE_NAMES[chord_type], NOTE_NAMES[bass_note]);
372-
}else{
373-
sprintf(text, "%s%s", NOTE_NAMES[chord.notes_pre[0]], CHORD_TYPE_NAMES[chord_type]);
369+
int root_note = chord.notes_pre[0] % 12;
370+
371+
if(chord.inversion > 0){
372+
int bass_note = chord.notes[0] % 12;
373+
sprintf(text, "%s%s/%s", NOTE_NAMES[root_note], CHORD_TYPE_NAMES[chord_type], NOTE_NAMES[bass_note]);
374+
}else{
375+
sprintf(text, "%s%s", NOTE_NAMES[root_note], CHORD_TYPE_NAMES[chord_type]);
376+
}
377+
}else{
378+
sprintf(text, " ");
374379
}
375380
}
376381

src/musiclib.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using namespace rack;
77
float note_to_voltage(int v);
88
float voltage_to_note(float value);
99
int voltage_to_note_int(float value);
10+
int voltage_to_note_with_octave(float value);
1011

1112
//DSP Stuff (credit Marc Boule / Impromptu Modular)
1213
struct Trigger : dsp::SchmittTrigger {

0 commit comments

Comments
 (0)