Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER General Discussion Forum

Reply
 
Thread Tools Display Modes
Old 03-23-2020, 10:48 AM   #1
JonasHAnd
Human being with feelings
 
Join Date: Apr 2015
Posts: 102
Default How do I make a toolbar button that changes color along with a lua script state?

Hi!

I have a lua script that mimics Pro Tools "Insertion Follows playback".
Pressing N toggles between the two states.

I'd like to create a toolbar button that becomes blue when "insertion follows playback is" Active. This way I can see the state of the script visually.

The problem is that this only works with regular toggle actions from the action menu, not scripts.

I've read something about the actions "Dummy toggle" and "Exclusive toggle" perhaps being able to do what I need, but I'm not sure how...

If someone could teach me how to do this I'd be grateful.

/Jonas
JonasHAnd is offline   Reply With Quote
Old 03-23-2020, 10:57 AM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,970
Default

It's up to the script to set and update its toggle state.
cfillion is offline   Reply With Quote
Old 03-23-2020, 11:30 AM   #3
JonasHAnd
Human being with feelings
 
Join Date: Apr 2015
Posts: 102
Default

Ok, can I assume that this script does not report its toggle state?
(Since I can get regular toggle actions to toggle toolbar button color but not this script)
JonasHAnd is offline   Reply With Quote
Old 03-24-2020, 03:04 AM   #4
JonasHAnd
Human being with feelings
 
Join Date: Apr 2015
Posts: 102
Default

So how do I modify this script so it reports it's toggle state;

Quote:
state = reaper.HasExtState("playtoggle", "togglevalue")

if state then
value = reaper.GetExtState("playtoggle", "togglevalue")
if value == "1" then
reaper.SetExtState("playtoggle", "togglevalue", "0", true)
else
reaper.SetExtState("playtoggle", "togglevalue", "1", true)
end
end
JonasHAnd is offline   Reply With Quote
Old 03-24-2020, 08:31 AM   #5
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,970
Default

Code:
if not reaper.HasExtState("playtoggle", "togglevalue") then
  return
end

local scriptSection = ({reaper.get_action_context()})[3]
local scriptId = ({reaper.get_action_context()})[4]

local value = reaper.GetExtState("playtoggle", "togglevalue")
value = value == '1' and 0 or 1

reaper.SetExtState("playtoggle", "togglevalue", value, true)
reaper.SetToggleCommandState(scriptSection, scriptId, value)
reaper.RefreshToolbar2(scriptSection, scriptId)
cfillion is offline   Reply With Quote
Old 03-25-2020, 04:31 AM   #6
JonasHAnd
Human being with feelings
 
Join Date: Apr 2015
Posts: 102
Default

Donated.

Thanks alot, Christian, works perfectly!
JonasHAnd is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:53 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.