music_generation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
music_generation [2024/02/25 18:46] – old revision restored (2024/02/25 18:25) steve.wangmusic_generation [2024/05/15 02:04] (current) steve.wang
Line 3: Line 3:
 **Overview: ** Konduktiva provides some example algorithms for music generation, including patterns of notes, octaves, and chords. This page will document those example algorithms and how they can be used. **Overview: ** Konduktiva provides some example algorithms for music generation, including patterns of notes, octaves, and chords. This page will document those example algorithms and how they can be used.
  
-**Things To Note:** This tutorial assumes you have already installed Konduktiva successfully using the [[https://github.com/renickbell/konduktiva|Konduktiva installation]] instructions and have read through and understood the [[:first_steps|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.+ 
 +**Things To Note:** This tutorial assumes you have already installed Konduktiva successfully using the [[https://github.com/renickbell/konduktiva|Konduktiva installation]] instructions and have read through and understood the [[:first_steps|first steps tutorial]]. The tutorial also assumes 2 things. One, Konduktiva has been assigned to the //K// variable. Two, user created a Musical Environment using the //setUpMusicalEnvironment// function using //K.defaultConfigurationObject// as the first argument and //'exampleMidiPlayer'// as the third argument then, assigned the output to the //e// variable. 
 +<code javascript> 
 +const K = require('konduktiva'
 +let e = K.setUpMusicalEnvironment(K.defaultConfigurationObject,4,'exampleMidiPlayer', K.exampleMusicalEnvironmentsExtraConfig) 
 +</code>
  
 <markdown> <markdown>
Line 13: Line 18:
 String -> {String} -> Number -> String String -> {String} -> Number -> String
  
-Use the ```K.lsystem``` function to generate L-system with more control.+Use the ```K.lsystem``` function to generate L-system with more control. use the ```K.workerLsystem``` that does the same thing but with worker threads 9smae syntax).
  
 #### Syntax #### Syntax
Line 44: Line 49:
 #### How It Works: #### How It Works:
 If the generations the lsystem function has to generate is more than 0, it will recursively call itself with one less generation. If the generations it has to generate reaches 0, it will return the string that has been inputted. If the generations the lsystem function has to generate is more than 0, it will recursively call itself with one less generation. If the generations it has to generate reaches 0, it will return the string that has been inputted.
 +
 +### variousLsystems
 +An lsystem is generated each individual character is assigned a number. The code will go through the lsystem and placing the characters in number form into an array. The array is then assigned a name in an object. The object is then returned.
 +
 +#### Syntax
 +
 +```
 +variousLsystems(baseName,n,patternLength,rules,generations,replacementValues,inputString, allChars = getAllAlphabets())
 +```
 +
 +#### Parameters
 +##### baseName
 +This is the base string for all the keys in the returned object. So, the names of the resulting object will be baseName+number. number starts from 0.
 +
 +##### n 
 +The amount of arrays in the returned object.
 +
 +##### patternLength
 +The total value of all the numbers in each array.
 +
 +##### rules
 +L-system rules. Object
 +
 +##### generations
 +
 +L-system generations. Number
 +
 +##### replacementValues
 +
 +The number each character should be assigned to.
 +
 +##### inputString
 +The string L-system should start with. The axiom of the L-system.
 +
 +##### allChars
 +All characters used by the L-system it will default to all the English alphabets if nothing is filled in.
 +
 +#### Examples
 +```
 +//Might need to wait a few seconds depending on speed of your device.
 +let varyingLsystem = await K.variousLsystems('testing', 1, 32, {'a': 'b', 'b': 'ab'}, 20, [0.5, 1, 2, 3], 'a')
 +/*
 +> varyingLsystem
 +{
 +  testing0: [
 +      1, 0.5, 0.5,   1, 0.5, 0.5,   1, 0.5,   1, 0.5,
 +    0.5,   1, 0.5, 0.5,   1, 0.5,   1, 0.5, 0.5,   1,
 +    0.5,   1, 0.5, 0.5,   1, 0.5, 0.5,   1, 0.5,   1,
 +    0.5, 0.5,   1, 0.5, 0.5,   1, 0.5,   1, 0.5, 0.5,
 +      1, 0.5,   1, 0.5, 0.5,   1
 +  ]
 +}
 +*/
 +```
  
 ### generateLsystemByAssigningNumberToLetter ### generateLsystemByAssigningNumberToLetter
Line 109: Line 168:
 #### How It Works: #### How It Works:
 First, the octaves and the notes are generated. They are generated via the same process. An lsystem is generated in string form. Then converted  First, the octaves and the notes are generated. They are generated via the same process. An lsystem is generated in string form. Then converted 
 +
  
 ## Random  ## Random 
Line 180: Line 240:
 ## Circle Of Fifths ## Circle Of Fifths
  
-Generate circle of fifths chord progressions using the ``generateCircleOfFifthsChordProgressions`` function. The ``generateCircleOfFifthsChordProgressions`` function uses the ``createCircleOfFifths`` function.+Generate circle of fifths chord progressions using the ``generateCircleOfFifthsChordProgression`` function. The ``generateCircleOfFifthsChordProgression`` function uses the ``createCircleOfFifths`` function.
  
 ### createCircleOfFifths ### createCircleOfFifths
Line 216: Line 276:
 ``` ```
  
-### generateCircleOfFifthsChordProgressions+### generateCircleOfFifthsChordProgression
 [Number] -> String -> Number -> [String] [Number] -> String -> Number -> [String]
  
Line 223: Line 283:
 ### Syntax ### Syntax
 ``` ```
-K.generateCircleOfFifthsChordProgressions(chordLengths, key, counterClockwiseChance) +K.generateCircleOfFifthsChordProgression(chordLengths, key, counterClockwiseChance) 
 ``` ```
  
Line 238: Line 298:
 ### Example ### Example
 ``` ```
-let circleOfFifthsProgression = K.generateCircleOfFifthsChordProgressions([1,1,1,1], "C", 0.5)+let circleOfFifthsProgression = K.generateCircleOfFifthsChordProgression([1,1,1,1], "C", 0.5)
 //Add the information to MusicalEnvironment: //Add the information to MusicalEnvironment:
 //1. Convert information to musical letter notation: //1. Convert information to musical letter notation:
Line 269: Line 329:
 ``` ```
 //Generate the random notes: //Generate the random notes:
-randomMelodyExample = K.generateRandomMelody('C', 'bluesPentatonicScale', 10, 4, 6)+randomMelodyExample = K.generateRandomMelody('C', 'blues', 10, 4, 6)
 /*output: /*output:
 [ [
Line 314: Line 374:
 ] ]
 */ */
 +```
 +
 +### Pass Melodies through Chord Filters
 +
 +Filters that a player can use are stored in the modeFilters variable in the MusicalEnvironment. The modeFilters the player chooses to use is controlled by the modeMaps variable in the MusicalEnvironment. 
 +
 +For example, I want the chords to filter through an aeolian filter then a dorian filter. I will have to create a modeMap that tells the player to do that.
 +```
 +e.modeMaps.aeolianAndDorian = new K.QuantizedMap(20, [0, 10], ['aeolian', 'dorian'])
 +
 +//configure player to use it:
 +e.players.exampleMidiPlayer1.modeMap = 'aeolianAndDorian'
 +
 +//make that player play:
 +e.play('exampleMidiPlayer1')
 +
 +```
 +
 +You can also create your own modeFilters like so:
 +```
 +//In this example, I will use the controlled L-system generator to generate a modeFilter
 +let lsystemModefilter = K.lsystem('a', {'a': 'ab', 'b': 'bab'}, 5)
 +let lsystemModeFilterChanges = K.countLetterChanges(lsystemModefilter)
 +
 +//Create a modeFilter:
 +e.modeFilters.lsystemModeFilter = new K.QuantizedMap(lsystemModeFilterChanges.length, lsystemModeFilterChanges, lsystemModeFilterChanges)
 +
 +//Create a modeMap to use modeFilter:
 +e.modeMaps.lsystem = new K.QuantizedMap(1, [1], ['lsystemModeFilter'])
 +
 +//Make Player use the created modeMap:
 +e.players.exampleMidiPlayer1.modeMap = 'lsystem'
 +
 +//Play player:
 +e.play('exampleMidiPlayer1')
 ``` ```
  
Line 338: Line 433:
  
 </markdown> </markdown>
 +
  • music_generation.1708915605.txt.gz
  • Last modified: 2024/02/25 18:46
  • by steve.wang