Mainstage Script: Drone

After I started messing with Scripter in Mainstage I wanted to implement a Drone-script: it needed to be able to start a note by pressing a button and hold it until the button was pressed again. Basic requirements:

  1. A single On/Off button. Activated with a ControlChange Message from a midi controller I had available.
  2. Set Root Note

Which led me to this:

var note = new NoteOn;
var noteoff = new NoteOff;
var toggle = 0;
note.channel = 1;
note.velocity = 100;

var CC_NUM=11;

function HandleMIDI(event) {
	var dronenote = GetParameter("Root Note")+60;
    if((event instanceof ControlChange) && (event.number == CC_NUM)) {
    		if (event.value == 127) {
    			if (toggle == 1) {
    				noteoff.pitch = dronenote;
    				noteoff.velocity = 0;
        			noteoff.send();
      			noteoff.trace();
      			toggle = 0;
         		}
    			else if (toggle == 0) {
        	 		note.pitch = dronenote;
         		note.velocity = 100;
         		note.send();
         		note.trace();
         		toggle = 1;
         		}
    			
         else if(event.value == 0) {
    		}
    }
}
}
var PluginParameters = [{
		name: "Root Note", 
		type:"menu", 
		valueStrings:["C","C#","D","D#","E","F","F#","G","G#","A","A#","B",],  
		numberOfSteps:12, 
		defaultValue:0
}];

Having played with this script for a few minutes I thought it would be nice to add a few extras:

  • Option to add 1 octave lower
  • Option to add a fifth

As you can see I added a parameter for velocity on the octave below. The fifth has the same velocity as the root note.

Code:

var note = new NoteOn;
var note_12 = new NoteOn;
var note5 = new NoteOn
var noteoff = new NoteOff;
var noteoff_12 = new NoteOff;
var noteoff5 = new NoteOff; 

var toggle = 0;
note.channel = 1;
note.velocity = 100;
note_12.velocity = 100


var CC_NUM=11;

function HandleMIDI(event) {
	var dronenote = GetParameter("Root Note")+60;
	
    if((event instanceof ControlChange) && (event.number == CC_NUM)) {
    		if (event.value == 127) {
    			if (toggle == 1) {
    				noteoff.pitch = dronenote;
    				noteoff.velocity = 0;
        			noteoff.send();
        			noteoff.trace();
        			if (GetParameter("Add Octave -12") == 1){
         			noteoff_12.pitch = dronenote -12;
         			noteoff_12.velocity = 0;
         			noteoff_12.send();
         			noteoff_12.trace();
         			}
         		if (GetParameter("Add +5") == 1){
         			noteoff5.pitch = dronenote +7;
         			noteoff5.velocity = 0;
         			noteoff5.send();
         			noteoff5.trace();
         			}
      			toggle = 0;
         		}
    			else if (toggle == 0) {
        	 		note.pitch = dronenote;
         		note.velocity = GetParameter("Velocity");
         		note.send();
         		note.trace();
         		if (GetParameter("Add Octave -12") == 1){
         			note_12.pitch = dronenote -12;
         			note_12.velocity = GetParameter("Velocity -12");
         			note_12.send();
         			note_12.trace();
         			}
				if (GetParameter("Add +5") == 1){
         			note5.pitch = dronenote +7;
         			note5.velocity = note.velocity;
         			note5.send();
         			note5.trace();
         			}

         		toggle = 1;
         		}
    			
         else if(event.value == 0) {
    		}
    }
}
}
var PluginParameters = [{
		name: "Root Note", 
		type:"menu", 
		valueStrings:["C","C#","D","D#","E","F","F#","G","G#","A","A#","B",],  
		numberOfSteps:12, 
		defaultValue:0
		},
		{
		name:"Velocity",
		type: "lin",
		numberOfSteps: 127,
		minValue: 0,
		maxValue: 127,
		defaultValue: 110,
		},
		{ 
		name:"Add Octave -12",
		type:"menu", 
		valueStrings:["Off","On"],  
		numberOfSteps:2, 
		defaultValue:0
		},
		{
		name:"Velocity -12",
		type: "lin",
		numberOfSteps: 127,
		minValue: 0,
		maxValue: 127,
		defaultValue: 110,
		},
		{ 
		name:"Add +5",
		type:"menu", 
		valueStrings:["Off","On"],  
		numberOfSteps:2, 
		defaultValue:0
		}]

Leave a Reply