This is an old revision of the document!
Action Functions
Overview: This tutorial will teach you about what actions function do in Konduktiva and how they work.
Things To Note: This tutorial assumes you have already installed Konduktiva successfully using the Konduktiva installation instructions and have read through and understood the first steps tutorial. The tutorial also assumes that you have imported Konduktiva to the K variable and assigned any of the example MusicalEnvironments to the e variable.
An Action Function is the function the player calls when the Konduktiva scheduler tells it that to do something. The action function the player uses can be controlled at the variable e.players.playerName.action. It should be a string and the strings refer to a variable which is a function in the e.actions object.
//Code will work if you have imported Konduktiva to K variable and assigned any of the example MusicalEnvironments to e. //View all the actions functions. console.log(e.actions) //View the action function players exampleMidiPlayer1 is using: console.log(e.players.exampleMidiPlayer1.action)
To test if the action function is being triggered you can assign the player to use the default action function and turn on verbose:
e.players.exampleMidiPlayer1.action = 'default' e.players.exampleMidiPlayer1.verbose = true e.play("exampleMidiPlayer1")
And assuming that you have the other maps left configured like the example MusicalEnvironment configured it you should see logging like this:
Hi this is the default action function being triggered This is the session: exampleMidiPlayer1 This is the beat: 1561
If you do not, restart Konduktiva and assign the MusicalEnvironment to e again.
Action Functions
default:
midiSequencedRhythm/callMusicSynthesizerRhythm:
sendNotesMidiInfo:
sendChordMidiInfo:
superDirt/playSuperDirtSample:
How to write an action function
Overview: This tutorial will teach you how to make your own action function by going through the steps of making a new action function called testAction.
Things To Note: This tutorial assumes you have already installed Konduktiva successfully using the Konduktiva installation instructions and have read through and understood the first steps tutorial. The tutorial also assumes that you have imported Konduktiva to the K variable and assigned any of the example MusicalEnvironments to the e variable. The action functions tutorial should also be read.
Setup:
const K = require('konduktiva') 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:
function testAction (playerName, b, e) {
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.
function testAction (playerName, b, e) { console.log('Hi this is my new action function called testAction.') console.log('testAction playerName: ', playerName) console.log('testAction beat: ', b) }
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:
e.actions.testAction = testAction
Now to get a player to use it, modify the action variable of the Player:
e.players.exampleMidiPlayer1.action = 'testAction'
Now if you play the player you will see that it will use the testAction action function:
e.play('exampleMidiPlayer1')
Click here to learn about QuantizedMaps OR Click her to see full Konduktiva documentation