Skip to content

Instantly share code, notes, and snippets.

@trentgill
Created July 8, 2020 01:43
Show Gist options
  • Save trentgill/5699e7810ea8c26601657ebaef2f768e to your computer and use it in GitHub Desktop.
Save trentgill/5699e7810ea8c26601657ebaef2f768e to your computer and use it in GitHub Desktop.
#define NUM_OSCS 6
void ii_vox( uint8_t* d )
{
if( !jt_state.smode ){ return; } // ignore if *not* in syn mode
int8_t voice = (int8_t)d[0] -1;
if( voice >= NUM_OSCS ){ return; } // voice out of range
int16_t note = (d[1] << 8) + d[2];
int16_t velo = (d[3] << 8) + d[4];
if( friends.speed ){ // synth mode
if(velo){ // note on
if( voice < 0 ){ // voice[0] == assign all
for( int i=0; i<NUM_OSCS; i++ ){
poly_assign_voice( poly, i, note );
}
} else { // single voice
poly_assign_voice( poly, voice, note );
}
_set_pitch( voice, note );
} else { // note off
if( voice < 0 ){ // voice[0] == kill all
for( int i=0; i<NUM_OSCS; i++ ){
poly_kill_voice( poly, i );
}
} else { // single voice
poly_kill_voice( poly, voice );
}
}
_velocity_trigger( voice, velo );
} else {
// geode
}
}
void ii_note( uint8_t* d )
{
if( !jt_state.smode ){ return; } // ignore if *not* in syn mode
static int8_t voice; // static for geo mode
int16_t note = (d[0] << 8) + d[1];
int16_t velo = (d[2] << 8) + d[3];
if( friends.speed ){ // synth
if(velo){ // note on
voice = poly_assign_note( poly, note );
if( voice != -1 ){ // check allocator succeeded
_set_pitch( voice, note );
}
} else { // note off
voice = poly_kill_note( poly, note );
}
if( voice != -1 ){
_velocity_trigger( voice, velo );
}
} else {
// geode
}
}
void _velocity_trigger( int8_t ch, int16_t velocity )
{
// set boolean triggers
_trigger( ch, !!velocity ); // mask to on/off
if(!velocity) { return; } // don't set velocity if zero
if(ch < 0){ // all
if(velocity > MAXJFSOUND){
for( uint8_t i=0; i<NUM_OSCS; i++ ){
jt_state.velo[i] = 1.0f;
}
} else {
float v = iMAXJFSOUND * (float)velocity;
for( uint8_t i=0; i<NUM_OSCS; i++ ){
jt_state.velo[i] = v;
}
}
} else if(ch < NUM_OSCS){ // individual
(velocity > MAXJFSOUND) // assume SOUND for now
? (jt_state.velo[ch] = 1.0f)
: (jt_state.velo[ch] = iMAXJFSOUND * (float)velocity);
}
}
#define JT_iOCTAVE ((float)1.0/(float)1638.3)
void _set_pitch( int8_t ch, int16_t pitch )
{
if(ch < 0){ // all
float mul = powf( 2.0f
, JT_iOCTAVE * (float)pitch );
mul *= jt_state.base_pitch
* jt_state.shift_pitch;
for( uint8_t i=0; i<NUM_OSCS; i++ ){
jt_state.pitch[i] = mul;
}
} else if(ch < NUM_OSCS){ // individual
float mul = powf( 2.0f
, JT_iOCTAVE * (float)pitch );
jt_state.pitch[ch] = mul
* jt_state.base_pitch
* jt_state.shift_pitch;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment