How to use the tone.Midi function in tone

To help you get started, we’ve selected a few tone examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stc / HackPact / Day-05-Markov-Chain / src / index.js View on Github external
p.keyPressed = () => {
		if(p.key == 'm') {
			p.save(Date.now() + ".jpg");
		}
	
		cRandZ = p.random(-200,200);
		cRandX = p.random(-200,200);
  		let keyIndex = keyOrder.indexOf(p.key);
  		// Check if valid note key pressed
  		if (keyIndex >= 0) {
  		  // Play synth
  		  let midiNoteNumber = notes[keyIndex]; // 0-127; 60 is Middle C (C4)
  		  fm.triggerAttackRelease(Tone.Midi(midiNoteNumber).toFrequency(), "64n");
  		  feedbackDelay.delayTime.value = p.random(10)/1000;
  		  triggerAlpha = 200;
  		  // Update time
  		  var timeSincePrevEvent = p.min(p.millis() - prevEventMillis, maxDuration);
  		  prevEventMillis = p.millis();
  		  var quantizedTimeSincePrevEvent = p.round(timeSincePrevEvent / timeQuantizationStep) * timeQuantizationStep;
  		  // Register node
  		  graph.registerNewNode(1, midiNoteNumber, quantizedTimeSincePrevEvent);
  		  // Activate key state
  		  keyStates[keyIndex] = 1;
  		}
	}
github googlecreativelab / creatability-seeing-music / src / visualization / Grid.js View on Github external
drawNote(note, context, width, height){
		context.textAlign='right'
		context.textBaseline='bottom' 
		const y = height - scaleMidi(Midi(note).toMidi()) * height
		context.fillStyle = 'white'
		context.fillText(note, width - this.padding - this.dashLen, y)		
		// context.fillRect(width - this.padding - this.dashLen, y, this.dashLen, this.lineWidth)

		//fill a faint line all the way across
		context.fillStyle = 'rgba(255, 255, 255, 0.1)'
		context.fillRect(this.padding, y, width - this.padding*2, this.lineWidth)
	}
}
github stc / HackPact / Day-18-Initial-Conditions / src / index.js View on Github external
this.m2 = 10;
            this.a1 = 0;
            this.a2 = 0;
            this.a1_v = 0;
            this.a2_v = 0;
            this.g = param;
            this.px2 = -1;
            this.py2 = -1;
            this.cx = x;
            this.cy = y;
            this.cz = z;
            this.id = id;
            
            this.init();
            this.vol = new Tone.Volume(-500);
            this.osc = new Tone.Oscillator(Tone.Midi(id + 66).toFrequency(), "sine").chain(this.vol, Tone.Master).start();
        }
        init() {
github stc / HackPact / Day-27-Random-Forest / src / index.js View on Github external
p.frameRate(30);
            g = p.createVector(0, .2);
            parts = [];

            p.smooth();
        }

        let obj1Param = [p.random(-200, -100), p.random(-300,-100), 3, p.random(100,300)];
        let obj2Param = [p.random(-50, 150), p.random(-100,200), 3, p.random(100,300)];
        let obj3Param = [p.random(0, 100), p.random(0,-200), 10, p.random(80,120)];

        var chorus = new Tone.Chorus(0.8, 2.5, 0.2).toMaster();  

        let v1 = new Tone.Volume(-100).connect(chorus);
        let f1 = new Tone.Filter(300, "highpass");
        let mosc1 = new Tone.Oscillator(Tone.Midi(40).toFrequency(), "sine").chain(f1, v1).start();

        let v2 = new Tone.Volume(-100).connect(chorus);
        let f2 = new Tone.Filter(400, "highpass");
        let mosc2 = new Tone.Oscillator(Tone.Midi(47).toFrequency(), "sine").chain(f2, v2).start();

        let v3 = new Tone.Volume(-100).connect(chorus);
        let f3 = new Tone.Filter(500, "highpass");
        let mosc3 = new Tone.Oscillator(Tone.Midi(52).toFrequency(), "sine").chain(f3, v3).start();

        let v4 = new Tone.Volume(-100).connect(chorus);
        let f4 = new Tone.Filter(600, "highpass");
        let mosc4 = new Tone.Oscillator(Tone.Midi(59).toFrequency(), "sine").chain(f4, v4).start();

        p.draw = () => {
            //p.camera(p.mouseX, 0, 400, 0, 0, 0, 0, 1, 0);
            p.background(0);
github stc / HackPact / Day-30-Birds-On-Wires / src / index.js View on Github external
}
    }).connect(chorus);

    autoFilter.start()    

    let v1 = new Tone.Volume(-100).connect(autoFilter);
    let f1 = new Tone.Filter(300, "highpass");
    let mosc1 = new Tone.Oscillator(Tone.Midi(53).toFrequency(), "sine").chain(f1, v1).start();

    let v2 = new Tone.Volume(-100).connect(autoFilter);
    let f2 = new Tone.Filter(400, "highpass");
    let mosc2 = new Tone.Oscillator(Tone.Midi(60).toFrequency(), "sine").chain(f2, v2).start();

    let v3 = new Tone.Volume(-100).connect(autoFilter);
    let f3 = new Tone.Filter(500, "highpass");
    let mosc3 = new Tone.Oscillator(Tone.Midi(65).toFrequency(), "sine").chain(f3, v3).start();

    let v4 = new Tone.Volume(-100).connect(autoFilter);
    let f4 = new Tone.Filter(600, "highpass");
    let mosc4 = new Tone.Oscillator(Tone.Midi(79).toFrequency(), "sine").chain(f4, v4).start();

    let wiresynths = [];
    let wireMelody = [53, 56, 60, 65, 68, 69, 74 , 77];
    for(let i=0; i< 8; i++) {
      wiresynths.push (new Tone.FMSynth({
                    "harmonicity": 28,
                    "modulationIndex": 2,
                    "detune": 0,
                    "oscillator": {
                        "type": "sawtooth"
                    },
                    "envelope": {
github stc / HackPact / Day-14-Polyrhythmia / src / index.js View on Github external
p.push();
                //p.translate( p.sin( step * i + this.counter) * this.r, p.cos( step * i + this.counter) * this.r, 0 );
                p.translate( p.sin( step * i - p.millis() / (this.sequence.length * 100.0))* this.r, p.cos( step * i - p.millis() / (this.sequence.length * 100.0))* this.r);
                p.noStroke();
                p.fill(255);
                p.sphere(this.sphereSizes[i]);
                if(this.sequence[i] == 0) {
                    //p.fill(255,100);
                } else {
                    if( p.sin( step * i - p.millis() / (this.sequence.length * 100.0)) > 0 ) {
                        if( this.triggers[i]==false) {
                            this.colors[i] = 255;
                            this.sphereSizes[i] = 8;
                            synths[this.id].envelope.sustain = p.random(2) + 0.01;
                            synths[this.id].envelope.release = p.random(2) + 0.02;
                            synths[this.id].triggerAttackRelease(Tone.Midi(notes[this.id]).toFrequency(), "32n");
                        }
                        this.triggers[i] = true;
                    } else {
                        this.triggers[i] = false;
                    }
                    p.fill(this.colors[i],0,0,200);
                }
                p.sphere(this.sphereSizes[i]);
                p.pop();
                this.colors[i] -= 4;
                if(this.sphereSizes[i] > 2)this.sphereSizes[i] -= 1;
            }
            p.pop();
            this.counter += this.speed;
        }
    }
github stc / HackPact / Day-24-Noise-Pianist / src / index.js View on Github external
let rnd = p.random(2);
                if(rnd > 0.5) {
                    alpha = 255;
                    piano.triggerAttackRelease(Tone.Midi(melody[p.ceil(val1*42)] + 6).toFrequency(),"132n");
                    piano.triggerAttackRelease(Tone.Midi(melody[p.ceil(val2*42)] + 6).toFrequency(),"132n");
                    
                }
            }
            ptick = tick;

            let tick2 = p.floor(p.millis()/400);
            if(ptick2!=tick2) {
                let rnd = p.random(2);
                if(rnd > 0.6) {
                    alpha = 255;
                    piano.triggerAttackRelease(Tone.Midi(melody[p.ceil(val2*42)] + 6).toFrequency(),"64n");
                    //piano.triggerAttackRelease(Tone.Midi(p.floor(val2*100) + 30).toFrequency(),"128n");  
                }
            }
            ptick2 = tick2;

                            
        }
    }
github stc / HackPact / Day-30-Birds-On-Wires / src / index.js View on Github external
"filter"  : {
"type"  : "highpass" ,
"rolloff"  : -12 ,
"Q"  : 1
}
    }).connect(chorus);

    autoFilter.start()    

    let v1 = new Tone.Volume(-100).connect(autoFilter);
    let f1 = new Tone.Filter(300, "highpass");
    let mosc1 = new Tone.Oscillator(Tone.Midi(53).toFrequency(), "sine").chain(f1, v1).start();

    let v2 = new Tone.Volume(-100).connect(autoFilter);
    let f2 = new Tone.Filter(400, "highpass");
    let mosc2 = new Tone.Oscillator(Tone.Midi(60).toFrequency(), "sine").chain(f2, v2).start();

    let v3 = new Tone.Volume(-100).connect(autoFilter);
    let f3 = new Tone.Filter(500, "highpass");
    let mosc3 = new Tone.Oscillator(Tone.Midi(65).toFrequency(), "sine").chain(f3, v3).start();

    let v4 = new Tone.Volume(-100).connect(autoFilter);
    let f4 = new Tone.Filter(600, "highpass");
    let mosc4 = new Tone.Oscillator(Tone.Midi(79).toFrequency(), "sine").chain(f4, v4).start();

    let wiresynths = [];
    let wireMelody = [53, 56, 60, 65, 68, 69, 74 , 77];
    for(let i=0; i< 8; i++) {
      wiresynths.push (new Tone.FMSynth({
                    "harmonicity": 28,
                    "modulationIndex": 2,
                    "detune": 0,
github stc / HackPact / Day-04-Logic-Gates / src / index.js View on Github external
nextStep() {
			this.ta = 255;
			if(this.gates[this.index].state == 0) {
				this.index = this.index + this.index + 1;
			} else if(this.gates[this.index].state == 1) {
				this.index = this.index + this.index + 2;
			}
			if(this.index > 14) {
				this.gates = [];
				this.addGates();
				this.index= 0;
			}
			this.fm.triggerAttackRelease(Tone.Midi(notes[this.index]).toFrequency(), "16n");
		}
github stc / HackPact / Day-01-Harmonic-Motion / src / index.js View on Github external
p.fill(255,0,0,colors[i]);
			p.sphere(3);
			
			p.pop();

			p.push();
			p.stroke(255,50);
			p.noFill();
			p.rotateY(p.PI/2);
			p.translate(0,0,(i - 5) * 40);
			p.ellipse(0, 0, (i+1) * 10 * 2, (i+1) * 10 * 2);
			p.pop();

			if(Math.sin(tempo)>0) {
				if(triggers[i]==false) {
					synths[i].triggerAttackRelease(Tone.Midi(i+1 + 60).toFrequency(), "8n");
					colors[i] = 255;
				}
				triggers[i] = true;
			} else {
				triggers[i] = false;
			}

			colors[i] -= 4;
		}
	}
	p.keyPressed = () => {