Does anyone have any useful ideas or design patterns for implementing a (simple) state machine in Capytalk?
Sometimes I make Sounds that do several different modes of operation. For instance record the audio input then carry out a sequence of modifications to the contents of the recorded buffer. So far my approach to this has been ad hoc using logic on various EventValues (eg. !Record) to prevent or enable certain activities.
I'm starting to think that using a state machine might be more reliable and easier to understand.
For the above example I might have something like the following states:
- ready
- recording
- processing
- stopped
and the following state transition events:
- start_recording
- stop_recording
- end_processing_sequence
Then my state machine would encode which events are recognised in each state and what the resultant state is.
Also writing it out as a state machine makes me consider state transitions I might otherwise miss - like do I allow start_recording during the processing state?
Has anyone tried to do something like this and did you come up with any useful patterns?