Example #1
0
/*
 * hexter_handle_event
 */
static inline void
hexter_handle_event(hexter_instance_t *instance, snd_seq_event_t *event)
{
    DEBUG_MESSAGE(DB_DSSI, " hexter_handle_event called with event type %d\n", event->type);

    switch (event->type) {
      case SND_SEQ_EVENT_NOTEOFF:
        hexter_instance_note_off(instance, event->data.note.note, event->data.note.velocity);
        break;
      case SND_SEQ_EVENT_NOTEON:
        if (event->data.note.velocity > 0)
            hexter_instance_note_on(instance, event->data.note.note, event->data.note.velocity);
        else
            hexter_instance_note_off(instance, event->data.note.note, 64); /* shouldn't happen, but... */
        break;
      case SND_SEQ_EVENT_KEYPRESS:
        hexter_instance_key_pressure(instance, event->data.note.note, event->data.note.velocity);
        break;
      case SND_SEQ_EVENT_CONTROLLER:
        hexter_instance_control_change(instance, event->data.control.param, event->data.control.value);
        break;
      case SND_SEQ_EVENT_CHANPRESS:
        hexter_instance_channel_pressure(instance, event->data.control.value);
        break;
      case SND_SEQ_EVENT_PITCHBEND:
        hexter_instance_pitch_bend(instance, event->data.control.value);
        break;
      /* SND_SEQ_EVENT_PGMCHANGE - shouldn't happen */
      /* SND_SEQ_EVENT_SYSEX - shouldn't happen */
      /* SND_SEQ_EVENT_CONTROL14? */
      /* SND_SEQ_EVENT_NONREGPARAM? */
      /* SND_SEQ_EVENT_REGPARAM? */
      default:
        break;
    }
}
Example #2
0
/*
 * hexter_instance_control_change
 */
void
hexter_instance_control_change(hexter_instance_t *instance, unsigned int param,
                               signed int value)
{
    switch (param) {  /* these controls we act on always */

      case MIDI_CTL_SUSTAIN:
        DEBUG_MESSAGE(DB_NOTE, " hexter_instance_control_change: got sustain control of %d\n", value);
        instance->cc[param] = value;
        if (value < 64)
            hexter_instance_damp_voices(instance);
        return;

      case MIDI_CTL_ALL_SOUNDS_OFF:
        instance->cc[param] = value;
        hexter_instance_all_voices_off(instance);
        return;

      case MIDI_CTL_RESET_CONTROLLERS:
        instance->cc[param] = value;
        hexter_instance_init_controls(instance);
        return;

      case MIDI_CTL_ALL_NOTES_OFF:
        instance->cc[param] = value;
        hexter_instance_all_notes_off(instance);
        return;
    }

    if (param == MIDI_CTL_REGIST_PARM_NUM_LSB ||
        param == MIDI_CTL_REGIST_PARM_NUM_MSB) {

        /* reset NRPN numbers on receipt of RPN */
        instance->cc[MIDI_CTL_NONREG_PARM_NUM_LSB] = 127;
        instance->cc[MIDI_CTL_NONREG_PARM_NUM_MSB] = 127;
    }

    if (instance->cc[param] == value)  /* do nothing if control value has not changed */
        return;

    instance->cc[param] = value;

    switch (param) {

#ifdef HEXTER_DEBUG_CONTROL
      case MIDI_CTL_MSB_PAN: /* panning */
        // hexter_instance_channel_pressure(instance, value);
        // { float f;
        //     f = 52.75f / (instance->sample_rate * 0.001f * (float)value);
        //     instance->amp_mod_max_slew = FLOAT_TO_FP(f);
        //     printf("new amp_mod_max_slew, %dms => %f = %d\n", value, f, instance->amp_mod_max_slew);
        // }
        {
            if (value == 0)
                instance->ramp_duration = 1;
            else
                instance->ramp_duration = (int)(instance->sample_rate * 0.001f * (float)value);  /* value ms ramp */
            printf("new ramp_duration, %dms => %d frames\n", value, instance->ramp_duration);
            dx7_lfo_set_speed_x(instance);
        }
        break;

      case MIDI_CTL_MSB_EXPRESSION: /* 'expression' */
        hexter_instance_key_pressure(instance, 60, value);
        break;
#endif /* HEXTER_DEBUG_CONTROL */

      case MIDI_CTL_MSB_MODWHEEL:
      case MIDI_CTL_LSB_MODWHEEL:
        hexter_instance_update_mod_wheel(instance);
        break;

      case MIDI_CTL_MSB_BREATH:
      case MIDI_CTL_LSB_BREATH:
        hexter_instance_update_breath(instance);
        break;

      case MIDI_CTL_MSB_FOOT:
      case MIDI_CTL_LSB_FOOT:
        hexter_instance_update_foot(instance);
        break;

      case MIDI_CTL_MSB_MAIN_VOLUME:
      case MIDI_CTL_LSB_MAIN_VOLUME:
        hexter_instance_update_volume(instance);
        break;

      case MIDI_CTL_MSB_GENERAL_PURPOSE1:
      case MIDI_CTL_MSB_GENERAL_PURPOSE2:
      case MIDI_CTL_MSB_GENERAL_PURPOSE3:
      case MIDI_CTL_MSB_GENERAL_PURPOSE4:
        hexter_instance_update_fc(instance, param - MIDI_CTL_MSB_GENERAL_PURPOSE1,
                                  value);
        break;

      case MIDI_CTL_GENERAL_PURPOSE5:
      case MIDI_CTL_GENERAL_PURPOSE6:
        hexter_instance_update_fc(instance, param - MIDI_CTL_GENERAL_PURPOSE5 + 4,
                                  value);
        break;

      /* handle NRPN as real-time parameter change */
      case MIDI_CTL_MSB_DATA_ENTRY:
      case MIDI_CTL_LSB_DATA_ENTRY:
        if (instance->cc[MIDI_CTL_NONREG_PARM_NUM_MSB] != 127 &&
            instance->cc[MIDI_CTL_NONREG_PARM_NUM_LSB] != 127) {
            hexter_instance_handle_nrpn(instance);
        }
        break;

      /* what others should we respond to? */

      /* these we ignore (let the host handle):
       *  BANK_SELECT_MSB
       *  BANK_SELECT_LSB
       *  RPN_MSB
       *  RPN_LSB
       * (may want to eventually implement RPN (0, 0) Pitch Bend Sensitivity)
       */
    }
}