Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
custom-actions [2023/12/15 19:43] – steve.wang | custom-actions [2024/02/08 23:23] (current) – removed steve.wang | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== How to write an action function ====== | ||
- | This tutorial will teach you how to make your own action function by going through the steps of making a new action function called // | ||
- | |||
- | Setup: | ||
- | <code javascript> | ||
- | const K = require(' | ||
- | let e = K.setUpMusicalEnvironment(1) | ||
- | </ | ||
- | |||
- | The action function arguments should be in this order for Konduktiva to be able to use it properly: player name, beat, MusicalEnvironment. | ||
- | So we will start this function like this: | ||
- | <code javascript> | ||
- | function testAction (playerName, | ||
- | </ | ||
- | Next we will make the action function do something very simple like log messages in the console. When making an action function, it is important to keep in mind that because JavaScript is single threaded, a computationally heavy action function could block the next events, and that's especially weird for events that are supposed to be simultaneous or temporally near. | ||
- | <code javascript> | ||
- | function testAction (playerName, | ||
- | console.log(' | ||
- | console.log(' | ||
- | console.log(' | ||
- | } | ||
- | </ | ||
- | |||
- | Next we have to make it so the players in the MusicalEnvironment can use it. To do so, we have the add it to the actions object of the MusicalEnvironment: | ||
- | <code javascript> | ||
- | e.actions.testAction = testAction | ||
- | </ | ||
- | Now to get a player to use it, modify the action variable of the Player: | ||
- | <code javascript> | ||
- | e.players.exampleMidiPlayer1.action = ' | ||
- | </ | ||
- | Now if you play the player you will see that it will use the // | ||
- | <code javascript> | ||
- | e.play(' | ||
- | </ | ||
- | |||
- | [[http:// |