@ -86,6 +86,11 @@ int process (jack_nframes_t frames, void* arg) {
jack_nframes_t N ;
jack_nframes_t i ;
//Transport Status
jack_position_t pos ;
jack_transport_state_t state = jack_transport_query ( client , & pos ) ;
bool transportRolling = state ! = JackTransportStopped ;
//Melody Midi Input
buffer = jack_port_get_buffer ( midi_port_in_melody , frames ) ;
//assert (buffer);
@ -188,21 +193,24 @@ int process (jack_nframes_t frames, void* arg) {
bool during_noteOn = instrument_isPlaying ( & instrument_melody ) ;
if ( programState . autoplayMelody & & ! during_noteOn ) {
bool we_want_autoplayMelody = programState . autoplayMelody & & ( ! programState . autoplayNeedsJackTransportRolling | | ( programState . autoplayNeedsJackTransportRolling & & transportRolling ) ) ;
if ( we_want_autoplayMelody & & ! during_noteOn ) {
//We need to activate the autoplaying note
instrument_setNoteOn ( & instrument_melody , programState . autoplayMelody_fallbackPitch ) ;
}
else if ( programState . autoplayMelody & & during_noteOn & & programState . autoplayMelody_fallbackPitch ! = autoplayMelody_lastNote ) {
else if ( we_want_ autoplayMelody & & during_noteOn & & programState . autoplayMelody_fallbackPitch ! = autoplayMelody_lastNote ) {
//We need to change the autoplaying note.
//This will interrupt a user note, but that is fine. We want immediate audible feedback
instrument_setNoteOn ( & instrument_melody , programState . autoplayMelody_fallbackPitch ) ;
}
else if ( ! programState . autoplayMelody & & during_noteOn & & programState . autoplayMelody_fallbackPitch = = autoplayMelody_lastNote ) {
else if ( ! we_want_ autoplayMelody & & during_noteOn & & programState . autoplayMelody_fallbackPitch = = autoplayMelody_lastNote ) {
//We need to stop the autoplaying note
instrument_setNoteOff ( & instrument_melody , programState . autoplayMelody_fallbackPitch ) ;
}
if ( programState . autoplayMelody ) {
if ( we_want_ autoplayMelody) {
autoplayMelody_lastNote = programState . autoplayMelody_fallbackPitch ;
}
else {
@ -218,6 +226,8 @@ int process (jack_nframes_t frames, void* arg) {
instrument_setForce ( & instrument_melody , programState . forceMelody ) ;
instrument_setForce ( & instrument_drone , programState . forceDrone ) ;
bool we_want_autoplayDrone = programState . autoplayDrone & & ( ! programState . autoplayNeedsJackTransportRolling | | ( programState . autoplayNeedsJackTransportRolling & & transportRolling ) ) ;
//Drone Midi Input
buffer = jack_port_get_buffer ( midi_port_in_drone , frames ) ;
//assert (buffer);
@ -235,7 +245,7 @@ int process (jack_nframes_t frames, void* arg) {
uint8_t type = event . buffer [ 0 ] & 0xf0 ;
//uint8_t channel = event.buffer[0] & 0xf;
if ( ! programState . autoplayDrone ) {
if ( ! we_want_ autoplayDrone) {
if ( type = = 0x90 ) {
instrument_setNoteOn ( & instrument_drone , event . buffer [ 1 ] ) ;
}
@ -251,15 +261,15 @@ int process (jack_nframes_t frames, void* arg) {
//Eventhough the instrument model has it's own guard against repeated note-ons on the same pitch we guard here as well.
//Also detect when the programState changes so we can send note on and off.
if ( ! programState . autoplayDrone & & ! autoplayDrone_lastState ) {
if ( ! we_want_ autoplayDrone & & ! autoplayDrone_lastState ) {
//Midi Mode was active, and still is. Do nothing.
}
else if ( programState . autoplayDrone & & ! autoplayDrone_lastState ) {
else if ( we_want_ autoplayDrone & & ! autoplayDrone_lastState ) {
//Previously midi mode was active, but not anymore. Switch on permanent note.
instrument_setAllNotesOff ( & instrument_drone ) ; //in case a midi note was still active. //TODO: I believe that reset() in note on does this anyway?
instrument_setNoteOn ( & instrument_drone , programState . droneRootMidiPitch ) ;
}
else if ( programState . autoplayDrone & & autoplayDrone_lastState ) {
else if ( we_want_ autoplayDrone & & autoplayDrone_lastState ) {
// No midi mode. Permanent root note was active and still is. Check if note has changed. If not do nothing.
if ( programState . droneRootMidiPitch ! = autoplayDrone_lastNote ) {
instrument_setNoteOff ( & instrument_drone , autoplayDrone_lastNote ) ;
@ -272,7 +282,8 @@ int process (jack_nframes_t frames, void* arg) {
instrument_setNoteOff ( & instrument_drone , programState . droneRootMidiPitch ) ;
}
autoplayDrone_lastNote = programState . droneRootMidiPitch ;
autoplayDrone_lastState = programState . autoplayDrone ;
//autoplayDrone_lastState = programState.autoplayDrone;
autoplayDrone_lastState = we_want_autoplayDrone ;
if ( pthread_mutex_trylock ( & msg_thread_lock ) = = 0 ) {
pthread_cond_signal ( & data_ready ) ;
@ -386,6 +397,12 @@ void jack_client_process_eventloop() {
}
//Call this once on startup before entering the main loop with the GUI etc.
void jack_client_init ( ) {