Home › Forums › General › Programming › On/Off button: 1 goes on, the other goes off
Tagged: On/Off button, radio buttons;
- This topic has 9 replies, 2 voices, and was last updated 3 years, 6 months ago by BAUS.
-
AuthorPosts
-
August 6, 2020 at 9:13 pm #119356
Hi there,
I am a new user of Ctrlr (in the programming sense) and I am looking for a few different things and how to program them.
The first thing is:
I have two ON/OFF buttons. When Button 1 is ON, Button 2 is OFF. If Button 2 is ON, Button 1 is OFF.
Could anybody be so kind to show me in the right direction.
I have looked at different panels that have what I need (Pro2 and Korg X5RW) and it’s a lot of code that I would like to understand.
Thanks in advance,
Robin Bausewein
Updating a 25 year old Editor
August 7, 2020 at 3:19 am #119358Hi BAUS,
It’s not trivial in my opinion and you need lua.
Here are two panels that emulate radio button functionality. (see attached)
One uses the onMouseDown listener and the other onValueChange:
Note that both panels have an init() function that sets the default radio button on panel load.
Regards,
- This reply was modified 3 years, 7 months ago by dnaldoog. Reason: added extra comment
- This reply was modified 3 years, 7 months ago by dnaldoog. Reason: removed buggy onValueChange panel
- This reply was modified 3 years, 7 months ago by dnaldoog. Reason: re uploaded onValueChange panel
Attachments:
You must be logged in to view attached files.August 12, 2020 at 3:21 am #119389See this post for a fuller explanation:
ctrlr.org/forums/topic/radio-button-in-a-modulator-group-needs-a-default-setting/page/2/#post-119393
August 27, 2020 at 1:43 pm #119588Thanks dndaldoog,
I finished my Panel with all the sysex codes now. I thought that would be the first thing to do.
So, I am back at the issue with the buttons. I took a look at the things you posted about that. Also I copied the code of the Radio2 onValueChange into my panel, adjusted the names according to my panel but the script is not giving any output in the Console.
I think I am missing 1 or 3 points here 😀
Like others here I am new to Lua (or even programming/scripting) and have some trouble interpreting the scripts that I am reading…but that will come with time, if I keep at it.
My two functions to fix in this Panel are basically the same:
* If OSC Pair 1 is on, OSC Pair 2 should be off and vice versa
* If Program 01 is selected (led is on) then Program 02 through 32 should be off (led off).I see how that scripts works in your example panel but can’t get it to work in mine.
Thanks,
Robin.
Attachments:
You must be logged in to view attached files.Updating a 25 year old Editor
August 27, 2020 at 1:53 pm #119594Hi Robin,
I think for me to offer an answer I would have to see your work so far.
If you don’t want to make it public, send me a private message and I’ll send you my email address then you can send it as an attachment.
Regards,
John
August 29, 2020 at 10:41 am #119609John….I sent you a PM….but I think I figured it out how to do it just now. 😀
I added a 5th button on the panel so I added “button5” to the table and changed the last line to:
(user clicked on a button – not lua generated – that would be 6 or 7)Also I understand that setting the INIT value made the difference.
Let me test some more!
Robin.
Updating a 25 year old Editor
August 29, 2020 at 11:37 am #119612Hi Robin,
All you should have to do is add the 32 button names to the
localtable in the init function, but don’t change theif source == 4
part. That’s crucial that it be left in there otherwise you’ll get an infinite loop and crash Ctrlr.You would then need to add 32 modulator names to the initial script.
There is a more elegant way to do this. In the init script each button is assigned to a variable, which is then accessed instead of
panel:getModulatorByName()
in the function loop. See attached panelRegards,
?
Attachments:
You must be logged in to view attached files.September 11, 2020 at 4:39 pm #119748Okay….. I used Dnalgood’s unelegant way of putting all the buttons in the local list….and it works…partially.
What works is that only 1 button led is ON and the other 31 are off. Good!
What’s not working is that each button that I press now outputs Program Change 32 except for button 32….that one outputs Program Change 31. I am still looking into this.
Any ideas?
Thanks,
Robin Bausewein.
Updating a 25 year old Editor
September 12, 2020 at 9:16 am #119755Hi BAUS,
You would need to remove all the sysex code from Ctrlr MIDI message type field – set to None and send the sysex all from lua.
ProgramSelect = function(--[[ CtrlrModulator --]] mod --[[ number --]], value --[[ number --]], source) if source == 4 then local sName = L(mod:getName()) local t = {"PROGRAM01", "PROGRAM02", "PROGRAM03", "PROGRAM04", "PROGRAM05", "PROGRAM06", "PROGRAM07", "PROGRAM08", "PROGRAM09", "PROGRAM10", "PROGRAM11", "PROGRAM12", "PROGRAM13", "PROGRAM14", "PROGRAM15", "PROGRAM16", "PROGRAM17", "PROGRAM18", "PROGRAM19", "PROGRAM20", "PROGRAM21", "PROGRAM22", "PROGRAM23", "PROGRAM24", "PROGRAM25", "PROGRAM26", "PROGRAM27", "PROGRAM28", "PROGRAM29", "PROGRAM30", "PROGRAM31", "PROGRAM32"} -- local table of buttons in radio for i, v in pairs(t) do if sName == v then local sysMess=string.format("F0 00 00 23 01 43 C1 00 %.2X F7",i-1) panel:sendMidiMessageNow(CtrlrMidiMessage(sysMess)) else _G[v]:setValue(0, true) end -- fi end -- for end -- source == 4 (user clicked on a button - not lua generated - that would be 5 or 6) end
Regards,
September 15, 2020 at 5:48 pm #119823Dnaldoog!!!! Thanks so much!
This is working great.
I am now getting deeper into the Lua programming language too. I have some more ideas for the Panel
with regards to requesting Patch Settings so the Panel reflects the Patch in the Mirage and possibly
also the Program Settings.Let’s see how far I can get with that.
Again….thank you so much for your help.
Updating a 25 year old Editor
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.