FredBegin Posted March 4, 2016 Share Posted March 4, 2016 Hi , I'm a beginner in scripting. I have a script with couples of menus for redirecting midi channels.It works great as is but I would like to start using arrays for the menus items instead of copying the value strings on each parameter. But i'm stock here. The first value is the midi channel. var arr = [ new Array(1,"Desk 1"), new Array(2,"Desk 2"), ]; The plugin parameter looks like this: var menuItems=['- None- ']; for(var i=0; i < arr.length; i++) {menuItems[menuItems.length]=arr[1];}; var PluginParameters = [ {name:"Player 1", type:"menu", valueStrings:menuItems, numberOfSteps: 16, minValue:0, maxValue:15, defaultValue:1,}, Now in the HandleMIDI function I want to return the midi channel value: var ch1 = new NoteOn; ch1.pitch = e.pitch; ch1.velocity = e.velocity; ch1.channel = ????); Here's a sample of my code so far: var arr = [ new Array(1,"Desk 1"), new Array(2,"Desk 2"), new Array(3,"Desk 3"), new Array(4,"Desk 4"), new Array(5,"Ensemble"), new Array(6,"Solo"), new Array(7,"Ensemble 2"), new Array(8,"Solo 2"), new Array(9,"9"), new Array(10,"10"), new Array(11,"11"), new Array(12,"12"), new Array(13,"13"), new Array(14,"14"), new Array(15,"15"), new Array(16,"16"), ]; var menuItems=['- None- ']; for(var i=0; i < arr.length; i++) {menuItems[menuItems.length]=arr[i][1];}; var PluginParameters = [ {name:"Player 1", type:"menu", valueStrings:menuItems, numberOfSteps: 16, minValue:0, maxValue:15, defaultValue:1,}, {name:"Player 2", type:"menu", valueStrings:menuItems, numberOfSteps: 16, minValue:0, maxValue:15, defaultValue:1,}, ]; function HandleMIDI(e) { var ch1 = new NoteOn; ch1.pitch = e.pitch; ch1.velocity = e.velocity; ch1.channel = GetParameter("Player 1"); //This is Wrong var ch2 = new NoteOn; ch2.pitch = e.pitch; ch2.velocity = e.velocity; ch2.channel = GetParameter("Player 2");//This is Wrong var Off1 = new NoteOff;Off1.pitch = e.pitch;Off1.velocity = e.velocity;Off1.channel = GetParameter("Player 1");// var Off2 = new NoteOff;Off2.pitch = e.pitch;Off2.velocity = e.velocity;Off2.channel = GetParameter("Player 2");// if (e instanceof NoteOn) { if (e.channel == 1) { ch1.send();ch2.send(); } } if (e instanceof NoteOff) { if (e.channel == 1) { Off1.send();Off2.send(); } } I would appreciate any help Thanks Fred Link to comment Share on other sites More sharing options...
FredBegin Posted March 4, 2016 Author Share Posted March 4, 2016 And here's the script wich is working without arrays. I use this to make different division arrangement with my Dimension strings Library. Essentially what it does is re distributing notes and CCs on one or multiple midi channels. So when using midi channel 1 it sends the notes to the instruments on channel 1,2,3 and 4, if using channel 2 it send it to channel 1 and 2 only... But my coding pretty basic ResetParameterDefaults = false; var NeedsTimingInfo = true; var PluginParameters = [ { name:"Player 1", defaultValue: 0, type:"menu", valueStrings:["Vln I Desk 1","Vln I Desk 2","Vln I Desk 3","Vln I Desk 4","Vln I Ensemble","Vln I Solo","Vln I Solo 2","Vln II desk 1", "Vln II desk 2","Vln II desk 3","Vln II desk 4","Vln II Ens","Vln II Solo","14","15","OFF"], numberOfSteps:16,defaultValue:0}, { name:"P1 Pitch", defaultValue:0, type:"lin", minValue:-14, maxValue:14, defaultValue:0, numberOfSteps:28 }, { name:"Player 2", defaultValue: 0, type:"menu", valueStrings:["Vln I Desk 1","Vln I Desk 2","Vln I Desk 3","Vln I Desk 4","Vln I Ensemble","Vln I Solo","Vln I Solo 2","Vln II desk 1", "Vln II desk 2","Vln II desk 3","Vln II desk 4","Vln II Ens","Vln II Solo","14","15","OFF"], numberOfSteps:16,defaultValue:1}, { name:"P2 Pitch", defaultValue:0, type:"lin", minValue:-14, maxValue:14, defaultValue:0, numberOfSteps:28 }, { name:"Player 3", defaultValue: 0, type:"menu", valueStrings:["Vln I Desk 1","Vln I Desk 2","Vln I Desk 3","Vln I Desk 4","Vln I Ensemble","Vln I Solo","Vln I Solo 2","Vln II desk 1", "Vln II desk 2","Vln II desk 3","Vln II desk 4","Vln II Ens","Vln II Solo","14","15","16"], numberOfSteps:16,defaultValue:2}, { name:"Player 4", defaultValue: 0, type:"menu", valueStrings:["Vln I Desk 1","Vln I Desk 2","Vln I Desk 3","Vln I Desk 4","Vln I Ensemble","Vln I Solo","Vln I Solo 2","Vln II desk 1", "Vln II desk 2","Vln II desk 3","Vln II desk 4","Vln II Ens","Vln II Solo","14","15","16"], numberOfSteps:16,defaultValue:3}, {name:"Players Vol", type: "Lin", defaultValue:100, minValue:0, maxValue:127, numberOfSteps:127}, { name:"Ensemble", defaultValue: 0, type:"menu", valueStrings:["Vln I Desk 1","Vln I Desk 2","Vln I Desk 3","Vln I Desk 4","Vln I Ensemble","Vln I Solo","Vln I Solo 2","Vln II desk 1", "Vln II desk 2","Vln II desk 3","Vln II desk 4","Vln II Ens","Vln II Solo","14","15","16"], numberOfSteps:16,defaultValue:4}, {name:"Ens. Vol", type: "Lin", defaultValue:100, minValue:0, maxValue:127, numberOfSteps:127}, { name:"Ens Pitch", defaultValue:0, type:"lin", minValue:-14, maxValue:14, defaultValue:0, numberOfSteps:28 }, { name:"Solo", defaultValue: 0, type:"menu", valueStrings:["Vln I Desk 1","Vln I Desk 2","Vln I Desk 3","Vln I Desk 4","Vln I Ensemble","Vln I Solo","Vln I Solo 2","Vln II desk 1", "Vln II desk 2","Vln II desk 3","Vln II desk 4","Vln II Ens","Vln II Solo","14","15","16"], numberOfSteps:16,defaultValue:5 }, { name:"Solo Pitch", defaultValue:0, type:"lin", minValue:-14, maxValue:14, defaultValue:0, numberOfSteps:28 }, {name:"Solo Vol", type: "Lin", defaultValue:100, minValue:0, maxValue:127, numberOfSteps:127}, ]; function HandleMIDI(e) { var ch1 = new NoteOn;ch1.pitch = e.pitch;ch1.velocity = e.velocity;ch1.channel = GetParameter("Player 1")+1; var ch1b = new NoteOn;ch1b.pitch = e.pitch+GetParameter("P1 Pitch");ch1b.velocity = e.velocity;ch1b.channel = GetParameter("Player 1")+1; var ch2 = new NoteOn;ch2.pitch = e.pitch;ch2.velocity = e.velocity;ch2.channel = GetParameter("Player 2")+1; var ch2b = new NoteOn; ch2b.pitch = e.pitch+GetParameter("P2 Pitch"); ch2b.velocity = e.velocity;ch2b.channel = GetParameter("Player 2")+1; var ch3 = new NoteOn; ch3.pitch = e.pitch;ch3.velocity = e.velocity;ch3.channel = GetParameter("Player 3")+1; var ch4 = new NoteOn;ch4.pitch = e.pitch;ch4.velocity = e.velocity;ch4.channel = GetParameter("Player 4")+1; var ch5 = new NoteOn;ch5.pitch = e.pitch;ch5.velocity = e.velocity;ch5.channel = GetParameter("Ensemble")+1; var ch5b = new NoteOn;ch5b.pitch = e.pitch+GetParameter("Ens Pitch");ch5b.velocity = e.velocity;ch5b.channel = GetParameter("Ensemble")+1; var ch6 = new NoteOn;ch6.pitch = e.pitch;ch6.velocity = e.velocity;ch6.channel = GetParameter("Solo")+1; var ch6b = new NoteOn;ch6b.pitch = e.pitch+GetParameter("Solo Pitch");ch6b.velocity = e.velocity;ch6b.channel = GetParameter("Solo")+1; var Off1 = new NoteOff;Off1.pitch = e.pitch;Off1.velocity = e.velocity;Off1.channel = GetParameter("Player 1")+1; var Off1b = new NoteOff;Off1b.pitch = e.pitch+GetParameter("P1 Pitch");Off1b.velocity = e.velocity;Off1b.channel = GetParameter("Player 1")+1; var Off2 = new NoteOff;Off2.pitch = e.pitch;Off2.velocity = e.velocity;Off2.channel = GetParameter("Player 2")+1; var Off2b = new NoteOff;Off2b.pitch = e.pitch+GetParameter("P2 Pitch");Off2b.velocity = e.velocity;Off2b.channel = GetParameter("Player 2")+1; var Off3 = new NoteOff;Off3.pitch = e.pitch;Off3.velocity = e.velocity;Off3.channel = GetParameter("Player 3")+1; var Off4 = new NoteOff;Off4.pitch = e.pitch;Off4.velocity = e.velocity;Off4.channel = GetParameter("Player 4")+1; var Off5 = new NoteOff;Off5.pitch = e.pitch;Off5.velocity = e.velocity;Off5.channel = GetParameter("Ensemble")+1; var Off5b = new NoteOff;Off5b.pitch = e.pitch+GetParameter("Ens Pitch");Off5b.velocity = e.velocity;Off5b.channel = GetParameter("Ensemble")+1; var Off6 = new NoteOff;Off6.pitch = e.pitch;Off6.velocity = e.velocity;Off6.channel = GetParameter("Solo")+1; var Off6b = new NoteOff;Off6b.pitch = e.pitch+GetParameter("Solo Pitch");Off6b.velocity = e.velocity;Off6b.channel = GetParameter("Solo")+1; var mod1 = new ControlChange;mod1.number = e.number; mod1.value = e.value;mod1.channel = GetParameter("Player 1")+1; var mod2 = new ControlChange;mod2.number = e.number; mod2.value = e.value;mod2.channel = GetParameter("Player 2")+1; var mod3 = new ControlChange;mod3.number = e.number; mod3.value = e.value;mod3.channel = GetParameter("Player 3")+1; var mod4 = new ControlChange;mod4.number = e.number; mod4.value = e.value;mod4.channel = GetParameter("Player 4")+1; var mod5 = new ControlChange;mod5.number = e.number; mod5.value = e.value;mod5.channel = GetParameter("Ensemble")+1; var mod6 = new ControlChange;mod6.number = e.number; mod6.value = e.value;mod6.channel = GetParameter("Solo")+1; ////........... if (e instanceof NoteOn) { //Group 1+2 if (e.channel == 1) { if (e.pitch < 35){ch1.send();ch2.send();ch3.send();ch4.send();} if (e.pitch >= 35){ch1b.send();ch2b.send();ch3.send();ch4.send();} } //Group 1 if (e.channel == 2) { if (e.pitch < 35){ch1.send();ch2.send();} if (e.pitch >= 35){ch1b.send();ch2b.send();} } //Group 2 if (e.channel == 3) { ch3.send();ch4.send(); } //P1 if (e.channel == 4) { if (e.pitch < 35){ch1.send();} if (e.pitch >= 35){ch1b.send();} } if (e.channel == 5) { if (e.pitch < 35){ch2.send();} if (e.pitch >= 35){ch2b.send();} } if (e.channel == 6) { ch3.send(); } //P4 if (e.channel == 7) { ch4.send(); } //P5 / Ensemble if (e.channel == 8) { ch5.send(); } //P6/Solo if (e.channel == 9) { ch6.send(); } //Group 1+2+Ens if (e.channel == 10) { if (e.pitch < 35){ch1.send();ch2.send();ch3.send();ch4.send();ch5.send();} if (e.pitch >= 35){ch1b.send();ch2b.send();ch3.send();ch4.send();ch5b.send();} } //Group 1+2+Solo if (e.channel == 11) { if (e.pitch < 35){ch1.send();ch2.send();ch3.send();ch4.send();ch6.send();} if (e.pitch >= 35){ch1b.send();ch2b.send();ch3.send();ch4.send();ch6b.send();} } } // Note OFF................................. if (e instanceof NoteOff) { if (e.channel == 1) { if (e.pitch < 35){Off1.send();Off2.send();Off3.send();Off4.send();} if (e.pitch >= 35){Off1b.send();Off2b.send();Off3.send();Off4.send();} } if (e.channel == 2) { if (e.pitch < 35){Off1.send();Off2.send();} if (e.pitch >= 35){Off1b.send();Off2b.send();} } if (e.channel == 3) { Off3.send();Off4.send(); } if (e.channel == 4) { if (e.pitch < 35){Off1.send();} if (e.pitch >= 35){Off1b.send();} } if (e.channel == 5) { if (e.pitch < 35){Off2.send();} if (e.pitch >= 35){Off2b.send();} } if (e.channel == 6) { Off3.send(); } if (e.channel == 7) { Off4.send(); } //P5 Ensemble if (e.channel == 8) { Off5.send(); } //P6 Solo if (e.channel == 9) { Off6.send(); } //Group 1+2+Ens if (e.channel == 10) { if (e.pitch < 35){Off1.send();Off2.send();Off3.send();Off4.send();Off5.send();} if (e.pitch >= 35){Off1b.send();Off2b.send();Off3.send();Off4.send();Off5b.send();} } //Group 1+2+Solo if (e.channel == 11) { if (e.pitch < 35){Off1.send();Off2.send();Off3.send();Off4.send();Off6.send();} if (e.pitch >= 35){Off1b.send();Off2b.send();Off3.send();Off4.send();Off6b.send();} } } // CCs................................. if (e instanceof ControlChange) { if (e.channel == 1){mod1.send();mod2.send();mod3.send();mod4.send();;mod5.send();mod6.send();} if (e.channel == 2){mod1.send();mod2.send();} if (e.channel == 3){mod3.send();mod4.send();} if (e.channel == 4){mod1.send();} if (e.channel == 5){mod2.send();} if (e.channel == 6){mod3.send();} if (e.channel == 7){mod4.send();} if (e.channel == 8){mod5.send();} if (e.channel == 9){mod6.send();} if (e.channel == 10){mod1.send();mod2.send();mod3.send();mod4.send();;mod5.send();} if (e.channel == 11){mod1.send();mod2.send();mod3.send();mod4.send();;mod6.send();} if (e.channel == 12){mod5.send();mod6.send();mod7.send();mod8.send();} } } function ParameterChanged(param, value) { if(param == 4){ var vol1 =GetParameter("Players Vol"); var cc7 = new ControlChange; cc7.number = 7; cc7.value = vol1; cc7.channel = GetParameter("Player 1")+1; cc7.send(); cc7.channel = GetParameter("Player 2")+1; cc7.send(); cc7.channel = GetParameter("Player 3")+1; cc7.send(); cc7.channel = GetParameter("Player 4")+1; cc7.send(); } if(param == 6){ var vol1 =GetParameter("Ens. Vol"); var cc7 = new ControlChange; cc7.channel = GetParameter("Ensemble")+1; cc7.number = 7; cc7.value = vol1; cc7.send(); } if(param == 8){ var vol1 =GetParameter("Solo Vol"); var cc7 = new ControlChange; cc7.channel = GetParameter("Solo")+1; cc7.number = 7; cc7.value = vol1; cc7.send(); } } Link to comment Share on other sites More sharing options...
Unheardofski Posted March 4, 2016 Share Posted March 4, 2016 Hi, In this case I'd probably peek at PluginParameters and do it the same way; with an array consisting of objects. For the menu you can then just easily map the specific property of the objects in the array: //Implementation var channels = [ {channel: 1, name : 'Desk 1'}, {channel: 2, name : 'Desk 2'}, {channel: 3, name : 'Desk 3'}, {channel: 4, name : 'Desk 4'}, {channel: 5, name : 'Ensemble'}, {channel: 6, name : 'Solo'}, {channel: 7, name : 'Ensemble 2'}, {channel: 8, name : 'Solo 2'}, {channel: 9, name : '9'}, {channel: 10, name : '10'}, {channel: 11, name : '11'}, {channel: 12, name : '12'}, {channel: 13, name : '13'}, {channel: 14, name : '14'}, {channel: 15, name : '15'}, {channel: 16, name : '16'}, ]; //ex. use for ValueStrings (you can go about it in a couple different ways) var chanMenu = channels.map(function(object){ return object.name }); Link to comment Share on other sites More sharing options...
FredBegin Posted March 4, 2016 Author Share Posted March 4, 2016 Thanks a lot Unheardof! I Will have a look at this Link to comment Share on other sites More sharing options...
Unheardofski Posted March 4, 2016 Share Posted March 4, 2016 Edited original post. Code was jumbled with the Access description Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.