// Poem 2: 22 //assigning standard lengths 0.57692307692 => float quarter; quarter/2 => float eighth; eighth/2 => float sixteenth; // adjusting note lengths with buffer 0.05 => float spacing; quarter - spacing => quarter; eighth - spacing => eighth; sixteenth - spacing => sixteenth; //assigning integers to note names for easier mtof assignment 71 => int b; 69 => int a; 74 => int d; 67 => int g; //setting up sine wave SinOsc foo => dac; 0.1 => foo.gain; //creating function for playing a note of a certain gain, pitch, & length fun void note(float gain, int pitch, float length) { gain => foo.gain; Std.mtof(pitch) => foo.freq; length::second +=> now; 0 => foo.gain; spacing::second +=> now; } //function to play a messier note with a messfactor to influence pitch, gain, and length fun void messynote(float gain, int pitch, float length, float messfactor) { gain + messfactor/1 => foo.gain; Std.mtof(Math.random2f(pitch - 3*messfactor, pitch + 3*messfactor)) => foo.freq; Math.random2f(length - messfactor*0.1, length + messfactor*0.2)::second +=> now; 0 => foo.gain; spacing::second +=> now; } // say a word with space after fun void say( string word ) { say( word, " " ); } // say a word fun void say( string word, string append ) { // print it chout <= word <= append; chout.flush(); } // instantiate Word2Vec model; // pre-trained model to load me.dir() + "glove-wiki-gigaword-50-tsne-2.txt" => string filepath; // load pre-trained model (see URLs above for download) if( !model.load( filepath ) ) { <<< "cannot load model:", filepath >>>; me.exit(); } // current word string lyric; //function to replace current lyric, input controls variability of replacement fun string replace(string lyric, int numwords) { // number of nearest words to retrieve for each word // higher this number the higher the variance per word numwords => int K_NEAREST; // word vector float vec[model.dim()]; // search results string words[K_NEAREST]; // get similar words model.getSimilar( lyric, words.size(), words ); // choose one at random words[Math.random2(0,words.size()-1)] => lyric; //output new word return lyric; } // MEASURE 1 (perfect) say("it"); note( 0.1, b, quarter); say("feels"); note( 0.1, b, eighth); say("like"); note( 0.1, b, sixteenth); say("a"); note( 0.1, a, sixteenth); say("perfect"); note( 0.1, b, eighth); note( 0.1, d, eighth); say("night"); note( 0.1, b, quarter); // MEASURE 2 (perfect) chout <= IO.newline(); chout.flush(); note( 0.0, g, sixteenth); say("to"); note( 0.1, b, sixteenth); say("dress"); note( 0.1, b, eighth); say("up"); note( 0.1, b, eighth); say("like"); note( 0.1, a, eighth); say("hipsters"); note( 0.1, b, quarter); note( 0.1, b, quarter); // MEASURE 3 (perfect) chout <= IO.newline(); chout.flush(); note( 0.0, g, sixteenth); say("and"); note( 0.1, b, sixteenth); say("make"); note( 0.1, b, eighth); say("fun"); note( 0.1, b, sixteenth); say("of"); note( 0.1, b, sixteenth); say("our"); note( 0.1, a, eighth); say("exes"); note( 0.1, b, quarter); note( 0.1, b, quarter); // MEASURE 4 (perfect) chout <= IO.newline(); chout.flush(); note( 0.0, g, eighth); say("Ah"); note( 0.1, a, eighth); say("ah."); note( 0.1, g, quarter); note( 0.0, g, eighth); say("Ah"); note( 0.1, a, eighth); say("ah."); note( 0.1, g, quarter); chout <= IO.newline(); chout.flush(); // MEASURE 1 (messfactor 0.25, numwords = 2) chout <= IO.newline(); chout.flush(); replace("it", 1) => lyric; say(lyric); messynote( 0.1, b, quarter, 0.25); replace("feels", 1) => lyric; say(lyric); messynote( 0.1, b, eighth, 0.25); replace("like", 1) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 0.25); replace("a", 1) => lyric; say(lyric); messynote( 0.1, a, sixteenth, 0.25); replace("perfect", 3) => lyric; say(lyric); messynote( 0.1, b, eighth, 0.25); messynote( 0.1, d, eighth, 0.25); replace("night", 3) => lyric; say(lyric); messynote( 0.1, b, quarter, 0.25); // MEASURE 2 (messfactor 0.25, numwords = 2) chout <= IO.newline(); chout.flush(); note( 0.0, g, sixteenth); replace("to", 1) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 0.25); replace("dress", 1) => lyric; say(lyric); messynote( 0.1, b, eighth, 0.25); replace("up", 1) => lyric; say(lyric); messynote( 0.1, b, eighth, 0.25); replace("like", 1) => lyric; say(lyric); messynote( 0.1, a, eighth, 0.25); replace("hipsters", 4) => lyric; say(lyric); messynote( 0.1, b, quarter, 0.25); messynote( 0.1, b, quarter, 0.25); // MEASURE 3 (messfactor 0.25, numwords = 2) chout <= IO.newline(); chout.flush(); note( 0.0, g, sixteenth); replace("and", 1) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 0.25); replace("make", 1) => lyric; say(lyric); messynote( 0.1, b, eighth, 0.25); replace("fun", 1) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 0.25); replace("of", 1) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 0.25); replace("our", 2) => lyric; say(lyric); messynote( 0.1, a, eighth, 0.25); replace("exes", 3) => lyric; say(lyric); messynote( 0.1, b, quarter, 0.25); messynote( 0.1, b, quarter, 0.25); // MEASURE 4 (messfactor 0.25, numwords = 2) chout <= IO.newline(); chout.flush(); note( 0.0, g, eighth); say("Ah"); messynote( 0.1, a, eighth, 0.25); say("ah."); messynote( 0.1, g, quarter, 0.25); note( 0.0, g, eighth); say("Ah"); messynote( 0.1, a, eighth, 0.25); say("ah."); messynote( 0.1, g, quarter, 0.25); chout <= IO.newline(); chout.flush(); // MEASURE 1 (messfactor 0.5, numwords = 5) chout <= IO.newline(); chout.flush(); replace("it", 1) => lyric; say(lyric); messynote( 0.1, b, quarter, 0.5); replace("feels", 1) => lyric; say(lyric); messynote( 0.1, b, eighth, 0.5); replace("like", 1) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 0.5); replace("a", 5) => lyric; say(lyric); messynote( 0.1, a, sixteenth, 0.5); replace("perfect", 7) => lyric; say(lyric); messynote( 0.1, b, eighth, 0.5); messynote( 0.1, d, eighth, 0.5); replace("night", 8) => lyric; say(lyric); messynote( 0.1, b, quarter, 0.5); // MEASURE 2 (messfactor 0.5, numwords = 5) chout <= IO.newline(); chout.flush(); note( 0.0, g, sixteenth); replace("to", 1) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 0.5); replace("dress", 5) => lyric; say(lyric); messynote( 0.1, b, eighth, 0.5); replace("up", 5) => lyric; say(lyric); messynote( 0.1, b, eighth, 0.5); replace("like", 5) => lyric; say(lyric); messynote( 0.1, a, eighth, 0.5); replace("hipsters", 5) => lyric; say(lyric); messynote( 0.1, b, quarter, 0.5); messynote( 0.1, b, quarter, 0.5); // MEASURE 3 (messfactor 0.5, numwords = 5) chout <= IO.newline(); chout.flush(); note( 0.0, g, sixteenth); replace("and", 1) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 0.5); replace("make", 3) => lyric; say(lyric); messynote( 0.1, b, eighth, 0.5); replace("fun", 4) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 0.5); replace("of", 2) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 0.5); replace("our", 4) => lyric; say(lyric); messynote( 0.1, a, eighth, 0.5); replace("exes", 5) => lyric; say(lyric); messynote( 0.1, b, quarter, 0.5); messynote( 0.1, b, quarter, 0.5); // MEASURE 4 (messfactor 0.5, numwords = 5) chout <= IO.newline(); chout.flush(); note( 0.0, g, eighth); say("Ah"); messynote( 0.1, a, eighth, 0.5); say("ah."); messynote( 0.1, g, quarter, 0.5); note( 0.0, g, eighth); say("Ah"); messynote( 0.1, a, eighth, 0.5); say("ah."); messynote( 0.1, g, quarter, 0.5); chout <= IO.newline(); chout.flush(); // MEASURE 1 (messfactor 0.75, numwords = 10) chout <= IO.newline(); chout.flush(); replace("it", 1) => lyric; say(lyric); messynote( 0.1, b, quarter, 0.75); replace("feels", 5) => lyric; say(lyric); messynote( 0.1, b, eighth, 0.75); replace("like", 5) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 0.75); replace("a", 5) => lyric; say(lyric); messynote( 0.1, a, sixteenth, 0.75); replace("perfect", 10) => lyric; say(lyric); messynote( 0.1, b, eighth, 0.75); messynote( 0.1, d, eighth, 0.75); replace("night", 10) => lyric; say(lyric); messynote( 0.1, b, quarter, 0.75); // MEASURE 2 (messfactor 0.75, numwords = 10) chout <= IO.newline(); chout.flush(); note( 0.0, g, sixteenth); replace("to", 2) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 0.75); replace("dress", 2) => lyric; say(lyric); messynote( 0.1, b, eighth, 0.75); replace("up", 5) => lyric; say(lyric); messynote( 0.1, b, eighth, 0.75); replace("like", 10) => lyric; say(lyric); messynote( 0.1, a, eighth, 0.75); replace("hipsters", 10) => lyric; say(lyric); messynote( 0.1, b, quarter, 0.75); messynote( 0.1, b, quarter, 0.75); // MEASURE 3 (messfactor 0.75, numwords = 10) chout <= IO.newline(); chout.flush(); note( 0.0, g, sixteenth); replace("and", 1) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 0.75); replace("make", 5) => lyric; say(lyric); messynote( 0.1, b, eighth, 0.75); replace("fun", 7) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 0.75); replace("of", 7) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 0.75); replace("our", 10) => lyric; say(lyric); messynote( 0.1, a, eighth, 0.75); replace("exes", 10) => lyric; say(lyric); messynote( 0.1, b, quarter, 0.75); messynote( 0.1, b, quarter, 0.75); // MEASURE 4 (messfactor 0.75, numwords = 10) chout <= IO.newline(); chout.flush(); note( 0.0, g, eighth); say("Ah"); messynote( 0.1, a, eighth, 0.75); say("ah."); messynote( 0.1, g, quarter, 0.75); note( 0.0, g, eighth); say("Ah"); messynote( 0.1, a, eighth, 0.75); say("ah."); messynote( 0.1, g, quarter, 0.75); chout <= IO.newline(); chout.flush(); // MEASURE 1 (messfactor 1, numwords = 50) chout <= IO.newline(); chout.flush(); replace("it", 10) => lyric; say(lyric); messynote( 0.1, b, quarter, 1); replace("feels", 10) => lyric; say(lyric); messynote( 0.1, b, eighth, 1); replace("like", 10) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 1); replace("a", 20) => lyric; say(lyric); messynote( 0.1, a, sixteenth, 1); replace("perfect", 50) => lyric; say(lyric); messynote( 0.1, b, eighth, 1); messynote( 0.1, d, eighth, 1); replace("night", 50) => lyric; say(lyric); messynote( 0.1, b, quarter, 1); // MEASURE 2 (messfactor 1, numwords = 50) chout <= IO.newline(); chout.flush(); note( 0.0, g, sixteenth); replace("to", 5) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 1); replace("dress", 20) => lyric; say(lyric); messynote( 0.1, b, eighth, 1); replace("up", 20) => lyric; say(lyric); messynote( 0.1, b, eighth, 1); replace("like", 50) => lyric; say(lyric); messynote( 0.1, a, eighth, 1); replace("hipsters", 50) => lyric; say(lyric); messynote( 0.1, b, quarter, 1); messynote( 0.1, b, quarter, 1); // MEASURE 3 (messfactor 1, numwords = 50) chout <= IO.newline(); chout.flush(); note( 0.0, g, sixteenth); replace("and", 5) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 1); replace("make", 5) => lyric; say(lyric); messynote( 0.1, b, eighth, 1); replace("fun", 30) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 1); replace("of", 20) => lyric; say(lyric); messynote( 0.1, b, sixteenth, 1); replace("our", 50) => lyric; say(lyric); messynote( 0.1, a, eighth, 1); replace("exes", 50) => lyric; say(lyric); messynote( 0.1, b, quarter, 1); messynote( 0.1, b, quarter, 1); // MEASURE 4 (messfactor 1, numwords = 50) chout <= IO.newline(); chout.flush(); note( 0.0, g, eighth); say("Ah"); messynote( 0.1, a, eighth, 1); say("ah."); messynote( 0.1, g, quarter, 1); note( 0.0, g, eighth); say("Ah"); messynote( 0.1, a, eighth, 1); say("ah."); messynote( 0.1, g, quarter, 1); chout <= IO.newline(); chout.flush(); chout <= IO.newline(); chout.flush(); note( 0.0, g, eighth); say("I "); note( 0.0, g, eighth); say("don't "); note( 0.0, g, eighth); say("know "); note( 0.0, g, eighth); say("about "); note( 0.0, g, eighth); say("you, "); note( 0.0, g, eighth); say("but "); note( 0.0, g, eighth); say("I'm "); note( 0.0, g, eighth); say("feeling "); note( 0.0, g, eighth); say("23..."); note( 0.0, g, eighth);