@ -67,6 +67,7 @@ Dexed::Dexed(int rate)
voices [ i ] . keydown = false ;
voices [ i ] . keydown = false ;
voices [ i ] . sustained = false ;
voices [ i ] . sustained = false ;
voices [ i ] . live = false ;
voices [ i ] . live = false ;
voices [ i ] . key_pressed_timer = 0 ;
}
}
max_notes = MAX_NOTES ;
max_notes = MAX_NOTES ;
@ -115,9 +116,6 @@ void Dexed::getSamples(uint16_t n_samples, int16_t* buffer)
uint8_t note ;
uint8_t note ;
float sumbuf [ n_samples ] ;
float sumbuf [ n_samples ] ;
if ( max_notes = = 0 )
return ;
if ( refreshVoice )
if ( refreshVoice )
{
{
for ( i = 0 ; i < max_notes ; i + + )
for ( i = 0 ; i < max_notes ; i + + )
@ -198,13 +196,37 @@ void Dexed::keydown(int16_t pitch, uint8_t velo) {
voices [ i ] . sustained = sustain ;
voices [ i ] . sustained = sustain ;
voices [ i ] . live = true ;
voices [ i ] . live = true ;
voices [ i ] . dx7_note - > init ( data , pitch , velo , pitch , porta , & controllers ) ;
voices [ i ] . dx7_note - > init ( data , pitch , velo , pitch , porta , & controllers ) ;
voices [ i ] . key_pressed_timer = millis ( ) ;
return ;
return ;
}
}
}
}
}
}
for ( uint8_t i = 0 ; i < max_notes ; i + + )
for ( uint8_t i = 0 ; i < = max_notes ; i + + )
{
{
if ( i = = max_notes )
{
uint32_t min_timer = 0xffff ;
if ( monoMode )
break ;
// no free sound slot found, so use the oldest note slot
for ( uint8_t n = 0 ; n < max_notes ; n + + )
{
if ( voices [ n ] . key_pressed_timer < min_timer )
{
min_timer = voices [ n ] . key_pressed_timer ;
note = n ;
}
}
voices [ note ] . keydown = false ;
voices [ note ] . sustained = false ;
voices [ note ] . live = false ;
voices [ note ] . key_pressed_timer = 0 ;
keydown_counter - - ;
}
if ( ! voices [ note ] . keydown )
if ( ! voices [ note ] . keydown )
{
{
currentNote = ( note + 1 ) % max_notes ;
currentNote = ( note + 1 ) % max_notes ;
@ -216,6 +238,8 @@ void Dexed::keydown(int16_t pitch, uint8_t velo) {
voices [ note ] . dx7_note - > init ( data , pitch , velo , srcnote , porta , & controllers ) ;
voices [ note ] . dx7_note - > init ( data , pitch , velo , srcnote , porta , & controllers ) ;
if ( data [ 136 ] )
if ( data [ 136 ] )
voices [ note ] . dx7_note - > oscSync ( ) ;
voices [ note ] . dx7_note - > oscSync ( ) ;
voices [ i ] . key_pressed_timer = millis ( ) ;
keydown_counter + + ;
break ;
break ;
}
}
else
else
@ -225,6 +249,7 @@ void Dexed::keydown(int16_t pitch, uint8_t velo) {
note = ( note + 1 ) % max_notes ;
note = ( note + 1 ) % max_notes ;
}
}
if ( keydown_counter = = 0 )
if ( keydown_counter = = 0 )
lfo . keydown ( ) ;
lfo . keydown ( ) ;
@ -254,6 +279,8 @@ void Dexed::keyup(int16_t pitch) {
if ( pitch < 0 ) // for disabling the oldest note when cpu overload is detected
if ( pitch < 0 ) // for disabling the oldest note when cpu overload is detected
{
{
voices [ currentNote ] . keydown = false ;
voices [ currentNote ] . keydown = false ;
voices [ currentNote ] . key_pressed_timer = 0 ;
if ( - - max_notes = = currentNote )
if ( - - max_notes = = currentNote )
currentNote = 0 ;
currentNote = 0 ;
}
}
@ -266,6 +293,8 @@ void Dexed::keyup(int16_t pitch) {
for ( note = 0 ; note < max_notes ; note + + ) {
for ( note = 0 ; note < max_notes ; note + + ) {
if ( voices [ note ] . midi_note = = pitch & & voices [ note ] . keydown ) {
if ( voices [ note ] . midi_note = = pitch & & voices [ note ] . keydown ) {
voices [ note ] . keydown = false ;
voices [ note ] . keydown = false ;
voices [ note ] . key_pressed_timer = 0 ;
break ;
break ;
}
}
}
}
@ -287,6 +316,7 @@ void Dexed::keyup(int16_t pitch) {
if ( highNote ! = - 1 & & voices [ note ] . live ) {
if ( highNote ! = - 1 & & voices [ note ] . live ) {
voices [ note ] . live = false ;
voices [ note ] . live = false ;
voices [ note ] . key_pressed_timer = 0 ;
voices [ target ] . live = true ;
voices [ target ] . live = true ;
voices [ target ] . dx7_note - > transferState ( * voices [ note ] . dx7_note ) ;
voices [ target ] . dx7_note - > transferState ( * voices [ note ] . dx7_note ) ;
}
}
@ -412,7 +442,7 @@ void Dexed::setMaxNotes(uint8_t n) {
{
{
notesOff ( ) ;
notesOff ( ) ;
max_notes = n ;
max_notes = n ;
panic ( ) ;
//panic();
controllers . refresh ( ) ;
controllers . refresh ( ) ;
}
}
}
}