Skip to content

Commit 01a6b0b

Browse files
committed
add sostenuto
Based on Kirtai's comment probonopd/MiniDexed#750 (comment)
1 parent 149e19e commit 01a6b0b

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/dexed.cpp

+45-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Dexed::Dexed(uint8_t maxnotes, uint16_t rate)
6060
lastKeyDown = -1;
6161
lfo.reset(data + 137);
6262
sustain = false;
63+
sostenuto = false;
6364
hold = false;
6465
voices = NULL;
6566

@@ -72,6 +73,7 @@ Dexed::Dexed(uint8_t maxnotes, uint16_t rate)
7273
voices[i].dx7_note = new Dx7Note; // sizeof(Dx7Note) = 692
7374
voices[i].keydown = false;
7475
voices[i].sustained = false;
76+
voices[i].sostenuted = false;
7577
voices[i].held = false;
7678
voices[i].live = false;
7779
voices[i].key_pressed_timer = 0;
@@ -284,13 +286,14 @@ void Dexed::keydown(uint8_t pitch, uint8_t velo) {
284286
}
285287
voices[note].keydown = false;
286288
voices[note].sustained = false;
289+
voices[note].sostenuted = false;
287290
voices[note].held = false;
288291
voices[note].live = false;
289292
voices[note].key_pressed_timer = 0;
290293
keydown_counter--;
291294
}
292295

293-
if (!voices[note].keydown)
296+
if (!voices[note].keydown && !voices[note].sostenuted)
294297
{
295298
if ( hold )
296299
{
@@ -321,6 +324,7 @@ void Dexed::keydown(uint8_t pitch, uint8_t velo) {
321324
voices[note].midi_note = pitch;
322325
voices[note].velocity = velo;
323326
voices[note].sustained = sustain;
327+
voices[note].sostenuted = false;
324328
voices[note].held = hold;
325329
voices[note].keydown = true;
326330
int32_t srcnote = (previousKeyDown >= 0) ? previousKeyDown : pitch;
@@ -399,6 +403,9 @@ void Dexed::keyup(uint8_t pitch) {
399403
}
400404
}
401405

406+
if ( voices[note].sostenuted )
407+
return;
408+
402409
if ( sustain ) {
403410
voices[note].sustained = true;
404411
} else if ( hold ) {
@@ -459,6 +466,41 @@ bool Dexed::getSustain(void)
459466
return sustain;
460467
}
461468

469+
void Dexed::setSostenuto(bool s)
470+
{
471+
if (sostenuto == s)
472+
return;
473+
474+
sostenuto = s;
475+
476+
if (sostenuto)
477+
{
478+
for (uint8_t note = 0; note < getMaxNotes(); note++)
479+
{
480+
if (voices[note].keydown)
481+
{
482+
voices[note].sostenuted = true;
483+
}
484+
}
485+
}
486+
else
487+
{
488+
for (uint8_t note = 0; note < getMaxNotes(); note++)
489+
{
490+
if (voices[note].sostenuted)
491+
{
492+
voices[note].dx7_note->keyup();
493+
voices[note].sostenuted = false;
494+
}
495+
}
496+
}
497+
}
498+
499+
bool Dexed::getSostenuto(void)
500+
{
501+
return sostenuto;
502+
}
503+
462504
void Dexed::setHold(bool h)
463505
{
464506
if (hold == h)
@@ -492,6 +534,7 @@ void Dexed::panic(void)
492534
voices[i].keydown = false;
493535
voices[i].live = false;
494536
voices[i].sustained = false;
537+
voices[i].sostenuted = false;
495538
voices[i].held = false;
496539
voices[i].key_pressed_timer = 0;
497540
if ( voices[i].dx7_note != NULL ) {
@@ -567,6 +610,7 @@ uint8_t Dexed::getNumNotesPlaying(void)
567610
// all carrier-operators are silent -> disable the voice
568611
voices[i].live = false;
569612
voices[i].sustained = false;
613+
voices[i].sostenuted = false;
570614
voices[i].held = false;
571615
voices[i].keydown = false;
572616
#if defined(MICRODEXED_VERSION) && defined(DEBUG)

src/dexed.h

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct ProcessorVoice {
5656
int16_t porta;
5757
bool keydown;
5858
bool sustained;
59+
bool sostenuted;
5960
bool held;
6061
bool live;
6162
uint32_t key_pressed_timer;
@@ -218,6 +219,8 @@ class Dexed
218219
void keydown(uint8_t pitch, uint8_t velo);
219220
void setSustain(bool sustain);
220221
bool getSustain(void);
222+
void setSostenuto(bool sostenuto);
223+
bool getSostenuto(void);
221224
void setHold(bool hold);
222225
bool getHold(void);
223226
void panic(void);
@@ -369,6 +372,7 @@ class Dexed
369372
uint16_t render_time_max;
370373
int16_t currentNote;
371374
bool sustain;
375+
bool sostenuto;
372376
bool hold;
373377
bool monoMode;
374378
bool noteRefreshMode;

0 commit comments

Comments
 (0)