No description, website, or topics provided.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
audio/piano
css
img
js
.gitignore
README.md
index.html

README.md

Simple music with Markov Chain using Tone.js

Live example: https://blog.lukaszogan.com/informatyka/algorytmiczne-generowanie-muzyki-poczatek-cyklu/#Interaktywny_przyklad

Example:

Alt Text

Main script markov.js:

 function trainMarkovChain(data) {
           const result = {};
           for (let i = 0; i < data.length - 1; i++) {
               const from = data[i];
               const to = data[i + 1];
               result[from] = result[from] || [];
               result[from].push(to);
           }
           return result;
       }
   
 function predictWithMarkovChain(chain, from) {
   
      let options;
  
      if (from && chain.hasOwnProperty(from)) {
         options = chain[from];
      } else {
        options = Object.keys(chain);
      }
      return options[Math.floor(Math.random() * options.length)];
  }