This is an old revision of the document!
What Are QuantizedMaps?
Overview: This tutorial will teach you about QuantizedMaps and how they are used inside of Konduktiva.
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.
QuantizedMap is a class to nodejs:
K.QuantizedMap //[class QuantizedMap]
The instance of QuantizedMap is used to store data in Konduktiva. You will see it used everywhere. For example, assuming you have e as a default MusicalEnvironment:
//Make e variable a default MusicalEnvironment: let e = K.setUpDefaultMusicalEnvironment() console.log(e.noteMaps) //It is full of QuantizedMaps. We can know that because after the variable name, it will say QuantizedMap like this "p2: QuantizedMap {". We can also verify that using code: console.log(e.noteMaps.p2 instanceof K.QuantizedMap)
The full QuantizedMap documentation can be found here but generally keys represents the timing. Values represents the values that should be used at a specific timing and keyspan is the total.
The QuantizedMaps are all recorded in different variables in the MusicalEnvironment but they are only used when the players are told to use them. For example:
//The modeMap variable in e.players.exampleMidiPlayer4.noteMap is p4 console.log(e.players.exampleMidiPlayer4.noteMap) //So that means when the player is going to play something, it will look at: console.log(e.noteMaps.p4)
Adding QuantizedMaps To The MusicalEnvironment
The recommended way to change specific variables in the MusicalEnvironment is to use the addMap method because it checks for many different types of errors and common mistakes when coding quickly. However, if you are confident and need more speed you can choose to directly interact with the MusicalEnvironment object. Here are some examples
Changing Octaves
For example, if I wanted to change the octaves of exampleMidiPlayer4 without changing timing I would do this:
//Identify which octave map exampleMidiPlayer4 is looking at: e.players.exampleMidiPlayer4.octaveMap //Next (the safer way): e.addMap('octaveMaps', e.players.exampleMidiPlayer4.octaveMap, e.octaveMaps[e.players.exampleMidiPlayer4.octaveMap].keyspan, e.octaveMaps[e.players.exampleMidiPlayer4.octaveMap].keys, [[ 6 ], [ 6 ], [ 6 ], [ 6 ], [ 6 ], [ 6 ], [ 6 ], [ 6 ], [ 6 ], [ 6 ], [ 6 ], [ 6 ]] ) //to see the changes: console.log(e.octaveMaps[e.players.exampleMidiPlayer4.octaveMap].values) //OR do this the less safe way but potentially faster with more control: e.octaveMaps[e.players.exampleMidiPlayer4.octaveMap].values =[[ 6 ], [ 6 ], [ 6 ], [ 6 ], [ 6 ], [ 6 ], [ 6 ], [ 6 ], [ 6 ], [ 6 ], [ 6 ], [ 6 ]] //to see the changes: console.log(e.octaveMaps[e.players.exampleMidiPlayer4.octaveMap].values)
Changing RhythmMap
Example changing rhythmMap for exampleMidiPlayer4 without changing timing. Similar to changing octave.
//Recommended safe way: e.addMap('rhythmMaps', e.players.exampleMidiPlayer4.rhythmMap, e.rhythmMaps[e.players.exampleMidiPlayer4.rhythmMap].values[0].keyspan, e.rhythmMaps[e.players.exampleMidiPlayer4.rhythmMap].values[0].keys, [2, 4, 6] ) //other potentially faster way: e.rhythmMaps[e.players.exampleMidiPlayer4.rhythmMap].values[0].values = [2, 4, 6]
Changing Melody, Notes or Chords
Example of changing notes played for exampleMidiPlayer4 Similar to changing octave.:
//Recommended way e.addMap('noteMaps', e.players.exampleMidiPlayer4.noteMap, 5, [0, 1, 2, 3, 4], [ [40],[50], [60], [70], [80]] ) //OR e.noteMaps[e.players.exampleMidiPlayer4.noteMap] = new QuantizedMap(5, [0, 1, 2, 3, 4], [ [40],[50], [60], [70], [80]])
Changing The MusicalEnvironment In General
To change things in the MusicalEnviornment, one should use the addMap method. The documentation is in konduktiva-documentation.md
Or read about the different ways to generate music here
Changing The QuantizedMaps Used By A Player
The sound output can be easily changed by simply switching the data the player looks at without creating any new data.
Changing notes played
This will cause the notes to loop between 0 to 11.
e.players.exampleMidiPlayer1.noteMap = 'default' //To look at the information being used: console.log(e.noteMaps.default)
Changing modeMap used
This will cause the chord progression chromatic to be used.
e.players.exampleMidiPlayer1.modeMap = 'default' //To look at the information being used: console.log(e.modeMaps.default)
Changing melody used
This will cause the player to cycle between the notes 0 to 3.
e.players.exampleMidiPlayer1.noteMap = 'default' //To look at the information being used: console.log(e.noteMaps.default)
Playing Chords
To play chords another action function will have to be used. To switch action functions do this:
e.players.exampleMidiPlayer1.action = 'sendChordMidiInfo'
Or click here to learn more about action functions.