First time here? Check out the FAQ!
x

Implementing a State Machine in Capytalk

0 votes
432 views

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?

asked Jul 10, 2023 in Capytalk & Smalltalk by alan-jackson (Virtuoso) (15,840 points)

1 Answer

0 votes

Hi Alan,

Here's a mini state machine constructed from a MapEventValues and a TriggeredSoundToGlobalController.

The states are numbered 0 (Ready), 1 (Recording), 2 (Processing) and the transition triggers

!Start_proc \/ !Start_rec \/ !Stop_rec \/ !Stop_proc \/ !Reset

have different effects depending on the current state.

Have fun!

answered Jul 14, 2023 by ssc (Savant) (128,200 points)
Hi SSC,
I am unable to download the mini state machine linked here, the download fails for some reason. Can you assist
Gah! cancel that ;)
I managed to find the temp file that was downloaded and renamed it with a .kym extension and it works
...