Skip to content

Commit e29e3ce

Browse files
committed
free transpose fixes and improvements
fix MIDI semitone offset Red led when transpose is out of valid range
1 parent d36a023 commit e29e3ce

File tree

3 files changed

+48
-27
lines changed

3 files changed

+48
-27
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## Next release
44

5+
## v2.1.2 - 2021-10-28
6+
7+
### Changed
8+
- Red led when transpose is out of valid range
9+
10+
### Fixed
11+
- MIDI semitone offset (introduced in v2.1.1)
12+
- Free transpose improvements
13+
514
## v2.1.1 - 2021-10-20
615

716
This release brings the new button read algoritm to rev0 hardware (white aux buttons).

config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#endif
5252

5353
// #define CALIBRATION_MODE TRUE // don't linearize or calibrate sensor data
54-
#define DETECT_STUCK_NOTES // zero level detection at start
54+
#define DETECT_STUCK_NOTES // zero level detection
5555
// #define BREAKPOINT_CALIBRATION // button sensitivity correction using a breakpoint fit
5656

5757
#define CALIB_FORCE ((1<<18)/64 + 1) // +1 to signify hardware revision, 1k adc pull up resistors

synth_control.cpp

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,9 @@ class Instrument {
286286
buttons[n].note = start_note_offset +
287287
notegen0 * buttons[n].coord0 +
288288
notegen1 * buttons[n].coord1;
289-
buttons[n].midinote_base = (int)(buttons[n].note - start_note_offset + 0.5); // careful to keep rounded value above zero
290-
buttons[n].midinote = buttons[n].midinote_base;
289+
buttons[n].midinote_base = (int)(notegen0 * buttons[n].coord0 +
290+
notegen1 * buttons[n].coord1 + 0.5 + 100) - 100; // careful to keep rounded value above zero
291+
buttons[n].midinote = buttons[n].midinote_base + (int)(start_note_offset + 0.5);
291292
}
292293
for (n = 0; n < MAX_VOICECOUNT; n++) {
293294
voices[n] = -1;
@@ -347,19 +348,16 @@ class Instrument {
347348
}
348349

349350
int change_note_offset(float offset) {
350-
float n = start_note_offset + offset;
351-
if (n >= min_note_offset && n <= max_note_offset) {
352-
start_note_offset = n;
353-
return 0;
354-
}
355-
return 1;
351+
return set_note_offset(start_note_offset + offset);
356352
}
357353

358354
int set_note_offset(float offset) {
359355
if (offset >= min_note_offset && offset <= max_note_offset) {
360356
start_note_offset = offset;
357+
update_leds();
361358
return 0;
362359
}
360+
led_rgb3(255,0,0);
363361
return 1;
364362
}
365363

@@ -378,8 +376,8 @@ class Instrument {
378376
buttons[n].note = start_note_offset +
379377
notegen0 * buttons[n].coord0 +
380378
notegen1 * buttons[n].coord1;
381-
buttons[n].midinote_base = (int)(buttons[n].note - start_note_offset + 0.5); // careful to keep rounded value above zero
382-
buttons[n].midinote = buttons[n].midinote_base;
379+
buttons[n].midinote_base = -buttons[n].midinote_base;
380+
buttons[n].midinote = buttons[n].midinote_base + (int)(start_note_offset + 0.5);
383381
}
384382
}
385383

@@ -655,7 +653,7 @@ class Instrument {
655653
// Note on detection
656654
if (buttons[but].state == STATE_OFF) {
657655
buttons[but].state = STATE_ON;
658-
buttons[but].midinote = buttons[but].midinote_base + start_note_offset;
656+
buttons[but].midinote = buttons[but].midinote_base + (int)(start_note_offset + 0.5);
659657
buttons[but].start_note_offset = start_note_offset;
660658
// multiply velo by 2 to cover full midi range on note on
661659
int velo = 0 + buttons[but].vpres * velo_sensitivity * 128 * 2;
@@ -770,7 +768,7 @@ class Instrument {
770768
// Note on detection
771769
if (buttons[but].state == STATE_OFF && buttons[but].pres > 0.0) {
772770
// calculate midinote only at note on
773-
buttons[but].midinote = (int)(buttons[but].midinote_base + start_note_offset + 0.5);
771+
buttons[but].midinote = buttons[but].midinote_base + (int)(start_note_offset + 0.5);
774772
buttons[but].start_note_offset = start_note_offset;
775773

776774
if (portamento) {
@@ -848,9 +846,17 @@ class Instrument {
848846
}
849847
else if (but == transpose_button && transpose_button2) {
850848
// calculate combined transpose buttons
851-
// TODO: quick and dirty, x/y not calculated
852849
float temp_pres = buttons[but].pres; // save pres for note off detection
853850

851+
float sw = buttons[but].pres + buttons[transpose_button2].pres;
852+
if (sw > 0.0f) {
853+
buttons[but].but_x = (buttons[but].pres * buttons[but].but_x +
854+
buttons[transpose_button2].pres * buttons[transpose_button2].but_x)
855+
/ sw;
856+
buttons[but].but_y = (buttons[but].pres * buttons[but].but_y +
857+
buttons[transpose_button2].pres * buttons[transpose_button2].but_y)
858+
/ sw;
859+
}
854860
buttons[but].pres = max(buttons[but].pres, buttons[transpose_button2].pres);
855861
buttons[but].vpres = buttons[but].vpres + buttons[transpose_button2].vpres;
856862

@@ -1143,6 +1149,7 @@ void int2float(int *msg, float *fmsg, int n) {
11431149
unsigned int aux_button_map = 0;
11441150

11451151
int synth_message(int size, int* msg) {
1152+
static float note_offset_old;
11461153
float fmsg[7];
11471154
int src = msg[0];
11481155
int id = msg[1];
@@ -1152,31 +1159,36 @@ int synth_message(int size, int* msg) {
11521159
if (src == ID_CONTROL) {
11531160
if (id == IDC_ALT) {
11541161
dis.set_altmode(msg[0]);
1162+
update_leds();
11551163
}
11561164
else if (id == IDC_PORTAMENTO) {
11571165
// Portamento button
11581166
dis.set_portamento(msg[0]);
1167+
update_leds();
11591168
}
11601169
else if (msg[0]) {
11611170
aux_button_map |= 1<<id;
1162-
int dif = 12;
1163-
if (dis.altmode) dif = 1;
1164-
if (id == IDC_OCT_UP) {
1165-
dis.change_note_offset(dif);
1166-
}
1167-
if (id == IDC_OCT_DOWN) {
1168-
dis.change_note_offset(-dif);
1169-
}
1170-
if (aux_button_map == (1<<IDC_OCT_UP) | (1<<IDC_OCT_DOWN)) {
1171+
if (aux_button_map == ((1<<IDC_OCT_UP) | (1<<IDC_OCT_DOWN))) {
1172+
dis.set_note_offset(note_offset_old);
11711173
dis.set_free_transpose_mode(1);
1174+
} else {
1175+
note_offset_old = dis.start_note_offset;
1176+
int dif = 12;
1177+
if (dis.altmode) dif = 1;
1178+
if (id == IDC_OCT_UP) {
1179+
dis.change_note_offset(dif);
1180+
}
1181+
if (id == IDC_OCT_DOWN) {
1182+
dis.change_note_offset(-dif);
1183+
}
11721184
}
11731185
} else {
1174-
aux_button_map &= !(1<<id);
1175-
if (aux_button_map != (1<<IDC_OCT_UP) | (1<<IDC_OCT_DOWN)) {
1186+
aux_button_map &= ~(1<<id);
1187+
if (aux_button_map != ((1<<IDC_OCT_UP) | (1<<IDC_OCT_DOWN))) {
11761188
dis.set_free_transpose_mode(0);
11771189
}
1190+
update_leds();
11781191
}
1179-
update_leds();
11801192
}
11811193
else if (src == ID_ACCEL && size == 7) {
11821194
motion.message(msg);
@@ -1392,7 +1404,7 @@ void update_leds(void) {
13921404
}
13931405
#endif
13941406

1395-
int note_offset = (int)(dis.start_note_offset - 62 + 0.5f);
1407+
int note_offset = (int)(dis.start_note_offset + 0.5f) - 62;
13961408
if (note_offset < -12) led_updown(0x1100);
13971409
else if (note_offset < 0) led_updown(0x0100);
13981410
else if (note_offset > 12) led_updown(0x0011);

0 commit comments

Comments
 (0)