Controlling analog synths with computers

Mikko Helin MHELIN at tne01.tele.nokia.fi
Fri Nov 22 10:37:55 CET 1996


>State machine is the best way to do it.  I've seen it done in hardware, and
>software.  Pass the realtime messages, go into another state for sysex and
>running status...I guess I should look at this source code sometime...
>
>

Here is a sample code for state machine in SDL. It is not complete, but shows
the idea. To implement it in C (or assembler) you could use table struct, where
state, input, next state and pointer to action routine  are defined in
each row. There should actually be two next states depending on the
return value of action function (success or failure), but in midi parser
I don't easily find such a situation where some failure could take place.
If you are into OOP, you could define class for each state and actions
as methods. 

-Mikko

---------------------------------------------------------------------------

/* MIDIMACH.SDL */

START;
    init;
    NEXTSTATE wait_for_status;

STATE wait_for_status;
    INPUT note_on;
        /* action */
        NEXTSTATE wait_for_on_note;
    INPUT note_off;
        /* action */
        NEXTSTATE wait_for_off_note;
    INPUT program_change;
        /* action */
        NEXTSTATE wait_for_program;
    INPUT midi_controller;
        /* action */
        NEXTSTATE wait_for_ctrl_value;
    INPUT pitch_bend;
        /* action */
        NEXTSTATE wait_for_msb;

ENDSTATE wait_for_status;

STATE wait_for_on_note;
        INPUT note;
        /* action */
        NEXTSTATE wait_for_on_velocity;

        INPUT status;
        OUTPUT status TO self;
        NEXTSTATE wait_for_status;
ENDSTATE wait_for_on_note;

STATE wait_for_off_note;
        INPUT note;
        /* action */
        NEXTSTATE wait_for_off_velocity;

        INPUT status;
        OUTPUT status TO self;
        NEXTSTATE wait_for_status;
ENDSTATE wait_for_off_note;

STATE wait_for_on_velocity;
        INPUT velocity;
        /* action */
        NEXTSTATE wait_for_on_note; /* running status */
ENDSTATE wait_for_on_velocity;

STATE wait_for_off_velocity;
        INPUT velocity;
        /* action */
        NEXTSTATE wait_for_off_note; /* running status */
ENDSTATE wait_for_off_note;


/*                              
 * All states are not show here 
 */ 

STATE *; /* in all states */
        /* real time messages */
        INPUT midi_clock;
        NEXTSTATE -; /* don't change state */

        INPUT midi_start;
        NEXTSTATE -; 

        INPUT midi_stop;
        NEXTSTATE -; 

        INPUT midi_continue;
        NEXTSTATE -; 

        INPUT active_sensing;
        NEXTSTATE -; 
ENDSTATE *;






More information about the Synth-diy mailing list