Browse Source

Add mode to make autoplay depend on jack transport

master
Nils 1 year ago
parent
commit
5db07f4a10
  1. 3
      src/gui.c
  2. 35
      src/jackclient.c
  3. 3
      src/programstate.c
  4. 1
      src/programstate.h

3
src/gui.c

@ -267,6 +267,9 @@ void gui_process_eventloop() {
nk_layout_row_dynamic(ctx, v_spacing, 1);
nk_label(ctx, "Aftertouch & Pitchbend Sensitivity", NK_TEXT_ALIGN_LEFT);
horizontalFloatFader(ctx,"","CC 5", 0.0f, 0.025f, 0.00001f, &programState.afterTouchPitchbendSensitivity, defaultState.afterTouchPitchbendSensitivity, true, ""); //Very sensitive
nk_layout_row_dynamic(ctx, v_spacing, 1);
programState.autoplayNeedsJackTransportRolling = nk_check_label(ctx, "Autoplay only with Jack Transport", (nk_bool)programState.autoplayNeedsJackTransportRolling);
}
nk_end(ctx);

35
src/jackclient.c

@ -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() {

3
src/programstate.c

@ -80,6 +80,7 @@ void initProgramState(bool nsm, const char * filePath, const char * programName,
pState->wheelSpeedMelody = 0.5; //we got that value from the original project
pState->wheelSpeedDrone = 0.2; //we got that value from the original project
pState->aftertouchRaisesPitch = true;
pState->autoplayNeedsJackTransportRolling = false;
pState->autoplayMelody = false;
pState->autoplayDrone = false;
pState->forceMelody = 2.5; //between 0 and 10
@ -164,6 +165,7 @@ void loadStateFromFile() {
programState.forceMelody = (float)jRead_double(buffer, "{'forceMelody'", NULL);
programState.forceDrone = (float)jRead_double(buffer, "{'forceDrone'", NULL);
programState.autoplayNeedsJackTransportRolling = (bool)jRead_int(buffer, "{'autoplayNeedsJackTransportRolling'", NULL);
programState.autoplayMelody = (bool)jRead_int(buffer, "{'autoplayMelody'", NULL);
programState.autoplayDrone = (bool)jRead_int(buffer, "{'autoplayDrone'", NULL);
@ -219,6 +221,7 @@ void saveStateToFile() {
jwObj_double( "wheelSpeedMelody", (double)programState.wheelSpeedMelody );
jwObj_double( "wheelSpeedDrone", (double)programState.wheelSpeedDrone );
jwObj_int( "aftertouchRaisesPitch", (int)programState.aftertouchRaisesPitch );
jwObj_int( "autoplayNeedsJackTransportRolling", (int)programState.autoplayNeedsJackTransportRolling );
jwObj_int( "autoplayMelody", (int)programState.autoplayMelody );
jwObj_int( "autoplayDrone", (int)programState.autoplayDrone );
jwObj_double( "forceMelody", (double)programState.forceMelody );

1
src/programstate.h

@ -59,6 +59,7 @@ typedef struct {
float wheelSpeedMelody;
float wheelSpeedDrone;
bool aftertouchRaisesPitch;
bool autoplayNeedsJackTransportRolling;
bool autoplayMelody;
bool autoplayDrone;
float forceMelody; //between 0 and 10

Loading…
Cancel
Save