FredBegin Posted September 23, 2013 Share Posted September 23, 2013 Anybody knows if it possible to control a menu (or fader) with incoming midi CC? Not with smart control and midi learn. I guest it is with the function: function HandleMIDI(e) { if (e instanceof ControlChange) { if (e.number == 1 && e.value == 10) But I can't get it to work. I don't know what to do after that code. I have this script for keyswitch but I wish I could control the first menu with incoming midi CCs. The smart controls is not the best solution in that case because it create a new automation lane which is not 'scaled' properly. // Global Definition for controller X Y for switching in the artikulation row. Feel free to change the number. var x = new ControlChange; var y = new ControlChange; var z = new ControlChange; x.number = 0; y.number = 4; z.number = 5; // standart Event Handling function HandleMIDI(event) { event.trace(); event.send(); } // For Switching the Articulation (Expression) Every Name in the Plugin Parameter does have an own number // the First is 0, Second 1 , Third 2 and so on. function parameterSwitch(){ if (expression == 0) { x.value = 0; y.value = 0; } if (expression == 1) { x.value = 65; y.value = 127; } if (expression == 2) { x.value = 19; y.value = 0; } if (expression == 3) { x.value = 35; y.value = 0; } if (expression == 4) { x.value = 45; y.value = 0; } if (expression == 5) { x.value = 57; y.value = 0; } if (expression == 6) { x.value = 127; y.value = 0; } if (expression == 10) { x.value = 45; y.value = 0; } if (expression == 11) { x.value = 40; y.value = 127; } if (expression == 12) { x.value = 60; y.value = 127; } if (matrix == 0) { z.value = 0; } if (matrix == 1) { z.value = 10; } if (matrix == 2) { z.value = 20; } if (matrix == 3) { z.value = 30; } if (matrix == 4) { z.value = 40; } if (matrix == 5) { z.value = 50; } } //----------------------------------------- // Define the Names as u Wish. var PluginParameters = [ {name:"Keyswitch", type: "menu", unit:'Menu Item', defaultValue:0, numberOfSteps:13, valueStrings: [ "Staccato", "Spiccato", "Sustain", "Legato", "Portamento", "pTrill", "Pizz", "rep", "FastRep,", "fp", "SecRow1", "SecRow2", "SecRow3"] }, {name:"Matrix", type: "menu",unit:'Menu Item',defaultValue:0,numberOfSteps:13, valueStrings: [ "chamber", "Orchestral", "Appassionata", "Chamb. Sordino", "Orch. Sordino", "App. Sordino", ] }, ]; var expression = 0; var matrix = 1; // Now these happens when i change something // First i say the Var expression should get the Value of PluginParameters // then the function parameterSwitch(); should be called. And then send x and y. function ParameterChanged(param, value) { if (param == 0) { expression = value; parameterSwitch(); x.send(); y.send(); x.trace(); y.trace(); } if (param == 1) { matrix = value; parameterSwitch(); z.send(); z.trace(); } }; Thanks for any help. Quote Link to comment Share on other sites More sharing options...
ski Posted September 25, 2013 Share Posted September 25, 2013 There is no apparent way to do what you want. It would be great if we could, but there's no function for causing a GUI control to update in response to incoming MIDI. Quote Link to comment Share on other sites More sharing options...
FredBegin Posted September 25, 2013 Author Share Posted September 25, 2013 Thanks for the reply. I thought it was possible Quote Link to comment Share on other sites More sharing options...
Unheardofski Posted March 9, 2015 Share Posted March 9, 2015 Maybe I misunderstand, but you are wanting to control the menu of a scripter plugin with CC right? In that case, it should be doable. Try this just to confirm (If I am not mistaken moving the modwheel with this plugin active should also switch the scripter menu choice): edit: at my mac now, tried it and it works. still not sure this is what you want though //Test - changing Menu parameters with mod wheel var PluginParameters = []; var artVS = ["some", "some other", "yet another", "yawn"]; createParam("My articulations", "menu", artVS, 0, 3, 3); function createParam(n, t, vs, miv, mav, def, nos) { PluginParameters.push( { name : n, type : t, valueStrings : vs, minValue : miv, maxValue : mav, defaultValue : def, numberOfSteps : nos, } ); } function HandleMIDI(e){ if (e instanceof ControlChange && e.number == 1) { SetParameter(0, Math.floor((e.value + 1) / 32)); } e.send(); } Quote Link to comment Share on other sites More sharing options...
Jordi Torres Posted April 5, 2015 Share Posted April 5, 2015 Maybe I misunderstand, but you are wanting to control the menu of a scripter plugin with CC right?In that case, it should be doable. Try this just to confirm (If I am not mistaken moving the modwheel with this plugin active should also switch the scripter menu choice): edit: at my mac now, tried it and it works. still not sure this is what you want though //Test - changing Menu parameters with mod wheel var PluginParameters = []; var artVS = ["some", "some other", "yet another", "yawn"]; createParam("My articulations", "menu", artVS, 0, 3, 3); function createParam(n, t, vs, miv, mav, def, nos) { PluginParameters.push( { name : n, type : t, valueStrings : vs, minValue : miv, maxValue : mav, defaultValue : def, numberOfSteps : nos, } ); } function HandleMIDI(e){ if (e instanceof ControlChange && e.number == 1) { SetParameter(0, Math.floor((e.value + 1) / 32)); } e.send(); } This works as expected. I have a question on a related matter: How can I tell the HandleMIDI function to use a single instance of a particular CC event? Example: When asigning a particular CC to a push button in TouchOSC (say CC14 with a value of 0), the way the TouchOSC push button works, is by sending the message: 1- once when you put your finger on the button, 2- and a second time when releasing. (in the style of a note on/note off pair). I want to be able to use only the message that gets sent when taping the button, ignoring the copy of the same message that gets sent when releasing the button. Here's concrete example of how what I'm tryng to achieve: I have a menu with a certain amount of values. I want to navigate through the values in this menu by incrementing by one whenever the script receives say CC14 with a value of 1, and decrementing by one whenever it receives CC14 with a value of 0. I know how to do this in Max and in Logic's MIDI Environment window, no clue how to do it in Javascript. It's killing me. Thanks for any help. J. Quote Link to comment Share on other sites More sharing options...
Unheardofski Posted April 5, 2015 Share Posted April 5, 2015 is the value sent always 0 ? Quote Link to comment Share on other sites More sharing options...
Unheardofski Posted April 5, 2015 Share Posted April 5, 2015 (edited) here's a toggle script for a cc 14 message. The number -1 has magical built in toggle voodoo edit : this will make HandleMIDI ignore CC 14 every other time it is received. Now if I could find a script that teaches me how to spell receive believe and relieve relive ... //Jordi's dirty 14 var toggle = -1; function HandleMIDI(e){ if (e instanceof ControlChange && e.number == 14){ toggle *= -1; toggle == 1 ? e.send() : false; } else { e.send() } } Edited April 5, 2015 by Unheardofski Quote Link to comment Share on other sites More sharing options...
Jordi Torres Posted April 5, 2015 Share Posted April 5, 2015 Hi, Thanks for replying. is the value sent always 0 ? That depends. If you set up a button to send CC14 value of 0, the value will always be zero when you hit the button but the message will come in twice. If you trace the event in the console it looks like this: ***Creating a new MIDI engine with script*** Evaluating MIDI-processing script... Script evaluated successfully! [ControlChange channel:1 number:14 [Ctrl 14] value:0] [ControlChange channel:1 number:14 [Ctrl 14] value:0] > And I want this: ***Creating a new MIDI engine with script*** Evaluating MIDI-processing script... Script evaluated successfully! [ControlChange channel:1 number:14 [Ctrl 14] value:0] > J. Quote Link to comment Share on other sites More sharing options...
Unheardofski Posted April 5, 2015 Share Posted April 5, 2015 solved ? Quote Link to comment Share on other sites More sharing options...
Jordi Torres Posted April 5, 2015 Share Posted April 5, 2015 here's a toggle script for a cc 14 message. The number -1 has magical built in toggle voodooedit : this will make HandleMIDI ignore CC 14 every other time it is received. Now if I could find a script that teaches me how to spell receive believe and relieve relive ... //Jordi's dirty 14 var toggle = -1; function HandleMIDI(e){ if (e instanceof ControlChange && e.number == 14){ toggle *= -1; toggle == 1 ? e.send() : false; } else { e.send() } } Perfect! Thanks man J. Quote Link to comment Share on other sites More sharing options...
Unheardofski Posted April 5, 2015 Share Posted April 5, 2015 You're welcome. Speaking of Max, how steep is the learning curve? Quote Link to comment Share on other sites More sharing options...
Jordi Torres Posted April 5, 2015 Share Posted April 5, 2015 Not as steep as JavaScript if you ask me. But you can also use JavaScript within Max, which is cool. Apparently some things are easier to implement in JavaScript as opposed to doing it strictly with Max objects. I still can't get my head around how your code works...or why it works J. Quote Link to comment Share on other sites More sharing options...
Unheardofski Posted April 5, 2015 Share Posted April 5, 2015 Thanks. I have had several request in my store to port the scripts to able ton... Here's a walk through : We initially set the toggle variable to - 1. This number is the lightswitch of math. You can constantly multiply it with itself and it only switches between two states Negative 1 and 1. Handle midi flicks the switch (blind) every time cc14 is received. Then it checks if the switch is on. If yes it sends else it does Nadal. edit: toggle == 1 ? e.send() : false ; is the same as if you would write if (toggle == 1) { e,send(); } else { } https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator i use the ternary (conditional) operators a lot after accidentally discovering them. It's more flexible than "if" and less space demanding than switch(x){} Quote Link to comment Share on other sites More sharing options...
Jordi Torres Posted April 5, 2015 Share Posted April 5, 2015 Thanks. I have had several request in my store to port the scripts to able ton... I see. Max for Live. That could be good for your business since like I said, you could implement your JavaScript within Max or Max for Live. Max for Live has its own particularities because it needs to interface with Live, but you'll probably learn it quickly. Here's a walk through :We initially set the toggle variable to - 1. This number is the lightswitch of math. You can constantly multiply it with itself and it only switches between two states Negative 1 and 1. Handle midi flicks the switch (blind) every time cc14 is received. Then it checks if the switch is on. If yes it sends else it does Nadal. Thanks! J. Quote Link to comment Share on other sites More sharing options...
Jordi Torres Posted April 5, 2015 Share Posted April 5, 2015 edit: toggle == 1 ? e.send() : false ; is the same as if you would write if (toggle == 1) { e,send(); } else { } https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator i use the ternary (conditional) operators a lot after accidentally discovering them. It's more flexible than "if" and less space demanding than switch(x){} Yes, I have also recently become acquainted with the ternary conditional operator. The part I couldn't get was the bit with the -1, which you explained here: We initially set the toggle variable to - 1.This number is the lightswitch of math. You can constantly multiply it with itself and it only switches between two states Negative 1 and 1. J. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.