|
|
|
08-14-2015, 12:49 PM
|
#1
|
Human being with feelings
Join Date: Aug 2006
Location: Berlin
Posts: 11,818
|
Item/Take volume with Mousewheel
Change the item(or take) volume with the mousewheel and this script.
Promptly written by Justin Frankel after a "this would be really useful" request.
Download here :https://stash.reaper.fm/24815/ItemTak...Mousewheel.eel Use:
Place the script in the "Scripts" directory in your Reaper Resources Directory. (Options/Show ... to get to that)
Load and bind this script to the mousewheel(with any or no modifiers) in the Action window to use it. Configuration:want_item = 1; // set to 0 for take volume rather than item volume
In the The line:
vol = DB2VAL(VAL2DB(abs(vol)) + (val > 0 ? 0.5 : -0.5));
Those last two numbers, 0.5 and -0.5 are the mousewheel up/down step width.
Last edited by airon; 08-14-2015 at 12:58 PM.
|
|
|
08-14-2015, 01:49 PM
|
#2
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
A script by Justin Frankel ???
|
|
|
08-14-2015, 02:09 PM
|
#3
|
Human being with feelings
Join Date: Jul 2009
Posts: 7,595
|
Quote:
Originally Posted by X-Raym
A script by Justin Frankel ???
|
Yeah, who dat? LOL
Works great. I'm using CMD+Option
|
|
|
08-14-2015, 02:33 PM
|
#4
|
Human being with feelings
Join Date: Mar 2007
Location: I'm in a barn
Posts: 4,467
|
But but.. I was the first one to do a script with the "get_action_context" mousewheel trick... Pouty face
...or not
(it was all from spk77)
|
|
|
08-14-2015, 04:06 PM
|
#5
|
Human being with feelings
Join Date: Aug 2006
Location: Berlin
Posts: 11,818
|
I'd been editing dialogue in Protools 11, and a friend told me about how you can change the item gain with WIN+SHIFT+Mousewheel for selected items.
"This is actually a good idea. In Protools. Whoda thunk."
So the search began. I couldn't do it with vanilla or SWS actions. Justin wrote this in 20 minutes, and hey, I was off to the races.
Using the mousewheel makes it even easier to edit the item/take volume as you don't even have to point the mouse anywhere. And since Reaper has marquee selection, it's even faster than Protools at this particular thing(again).
I really wish I was editing dialogue in Reaper these days.
|
|
|
08-14-2015, 04:53 PM
|
#6
|
Human being with feelings
Join Date: Jun 2008
Location: Whales, UK
Posts: 6,010
|
mousewheel should be a mouse modifier option.
|
|
|
08-15-2015, 06:55 AM
|
#7
|
Human being with feelings
Join Date: Aug 2006
Location: Berlin
Posts: 11,818
|
Put it up in the issue tracker as a request.
I'll certainly vote for it. The first place I looked to do this was the preferences page for the mouse modifiers.
|
|
|
08-15-2015, 10:20 AM
|
#8
|
Human being with feelings
Join Date: Oct 2008
Location: Right Hear
Posts: 15,618
|
love this script... thanks much Justin and Airon... works a treat! ...and indeed VERY useful and fast.
|
|
|
08-15-2015, 12:42 PM
|
#9
|
Human being with feelings
Join Date: Nov 2013
Location: Argentina
Posts: 326
|
Any idea if the script has any advantages over this?
Edit: Forget it, they do the same. I was hoping the script to be context sensitive to the take under cursor, and mousewheeling mouseovering the take. But no, you had to click the take first, in the script and in my custom action too. I can´t find a way to do that with the actions, because there is no "select take under mouse cursor", only "select item". But maybe it´s posible to alter a bit the script for that...? What do you think?
__________________
Living la vida loca
Last edited by Pasajeromoronmoreno; 08-15-2015 at 01:13 PM.
|
|
|
08-15-2015, 01:15 PM
|
#10
|
Human being with feelings
Join Date: Mar 2007
Location: I'm in a barn
Posts: 4,467
|
search actions for
"activate take under mouse"
|
|
|
08-15-2015, 01:29 PM
|
#11
|
Human being with feelings
Join Date: Nov 2013
Location: Argentina
Posts: 326
|
Well, it´s not the first, and it´s not gonna be the last time me not finding something in that list, Every thing has a hundred different names...
Anyways, that do the trick James, it´s working mousovering over the takes now. Thanks for the help!!!!!
__________________
Living la vida loca
|
|
|
08-15-2015, 03:56 PM
|
#12
|
Human being with feelings
Join Date: Jun 2008
Location: Whales, UK
Posts: 6,010
|
Quote:
Originally Posted by airon
Put it up in the issue tracker as a request.
I'll certainly vote for it. The first place I looked to do this was the preferences page for the mouse modifiers.
|
Unfortunately imo the Issue tracker may as well be the side of the sofa as a good place for things, it was cool in v3 days now just where ideas go to decay slowly.
Polite mentions in a pre thread is the only way to seed a developer!
|
|
|
08-15-2015, 04:39 PM
|
#13
|
Human being with feelings
Join Date: Sep 2009
Location: Virginia
Posts: 2,068
|
Nice script!
Could a similar script be made to control the TCP volumes for selected tracks using the mousewheel as well?
I like the dB steps.
|
|
|
08-16-2015, 02:27 AM
|
#14
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Adjust take volume via mousewheel (take under mouse cursor):
Code:
function VAL2DB(x)(
x < 0.0000000298023223876953125 ? -150 : max(-150, log(x)* 8.6858896380650365530225783783321);
);
function DB2VAL(x) ( exp((x)*0.11512925464970228420089957273422 ));
function adjust_take_vol()
(
extension_api("BR_GetMouseCursorContext", "", "", "");
get_action_context(#foo,0,0, mode, res, val);
val != 0 ? (
(tk = extension_api("BR_GetMouseCursorContext_Take")) ? (
vol = GetMediaItemTakeInfo_Value(tk,"D_VOL");
ph = vol < 0.0;
vol = DB2VAL(VAL2DB(abs(vol)) + (val > 0 ? 0.5 : -0.5));
SetMediaItemTakeInfo_Value(tk,"D_VOL",ph ? -vol : vol);
UpdateTimeline();
Undo_OnStateChangeEx("Adjust take volume", -1, -1);
);
);
);
defer("adjust_take_vol()");
|
|
|
08-16-2015, 02:31 AM
|
#15
|
Human being with feelings
Join Date: Nov 2013
Location: Argentina
Posts: 326
|
Hi Wyatt!!
Maybe you prefer a script, but in the meantime this custom actions is what i use to accomplish that.
Assign to Mousewheel and done.
Need Sws, and you had to configure the steps you want for the volume nudges in the xenaxios command parameter window. (search command parameter in actions). I have it in 0.5 db steps, for example. Hope it helps!!
Edit: Hehehe, Ok, never mind, too late... spk77 did it already...
Edit 2: Sorry, he make the script for the takes, not for the TCP, so, this actions are still usefull. (Hahaha, for a bunch of minutes until someone come up with the scripts).
__________________
Living la vida loca
Last edited by Pasajeromoronmoreno; 08-16-2015 at 04:37 AM.
|
|
|
08-16-2015, 02:36 AM
|
#16
|
Human being with feelings
Join Date: Nov 2013
Location: Argentina
Posts: 326
|
Thanks spk77!!, gonna test it instead of the custom action. any advantages over that?
Edit: Yeah, you Script it´s better, with the custom action i had to select the track first, the script does not need that extra step. Thanks Again spk77!!
__________________
Living la vida loca
Last edited by Pasajeromoronmoreno; 08-16-2015 at 02:50 AM.
|
|
|
08-16-2015, 04:40 AM
|
#17
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by WyattRice
Nice script!
Could a similar script be made to control the TCP volumes for selected tracks using the mousewheel as well?
I like the dB steps.
|
Edit: ("Undo" should work now) Undo isn't working correctly - I'll see if I can fix it.
TrackItemTakeVolume_via_Mousewheel.eel- Mouse cursor on TCP -> adjust track volume (selected tracks)
- Mouse cursor on arrange view-> adjust item or take volume (selected items)
Code:
function VAL2DB(x)(
x < 0.0000000298023223876953125 ? -150 : max(-150, log(x)* 8.6858896380650365530225783783321);
);
function DB2VAL(x) ( exp((x)*0.11512925464970228420089957273422 ));
want_item = 1; // set to 0 for take volume rather than item volume
cnt=0;
tr=0;
get_action_context(#foo,0,0, mode, res, val);
extension_api("BR_GetMouseCursorContext", #window, "", "");
val != 0 && match("tcp", #window) ? (
i = 0;
loop(CountSelectedTracks(0),
trh = GetSelectedTrack(0, i);
vol = GetMediaTrackInfo_Value(trh, "D_VOL");
ph = vol < 0.0;
vol = DB2VAL(VAL2DB(abs(vol)) + (val > 0 ? 0.5 : -0.5));
SetMediaTrackInfo_Value(trh,"D_VOL",ph ? -vol : vol);
i=i+1;
);
Undo_OnStateChangeEx("Adjust track volume", -1, -1);
):
val != 0 && match("arrange", #window) ? (
loop(GetNumTracks(),
trh = GetTrack(0,tr);
idx=0;
loop(GetTrackNumMediaItems(trh),
item = GetTrackMediaItem(trh,idx);
IsMediaItemSelected(item) && (want_item || (tk = GetActiveTake(item))) ? (
vol = want_item ? GetMediaItemInfo_Value(item,"D_VOL") : GetMediaItemTakeInfo_Value(tk,"D_VOL");
ph = vol < 0.0;
vol = DB2VAL(VAL2DB(abs(vol)) + (val > 0 ? 0.5 : -0.5));
want_item ? SetMediaItemInfo_Value(item,"D_VOL",vol) : SetMediaItemTakeInfo_Value(tk,"D_VOL",ph ? -vol : vol);
cnt+=1;
z=1;
);
idx+=1
);
tr+=1;
);
Undo_OnStateChangeEx("Adjust item or take volume", 4, -1);
);
cnt ? UpdateTimeline();
Thanks to Breeder for the GetMouseCursorContext functions!
Quote:
Originally Posted by Pasajeromoronmoreno
Thanks spk77!!, gonna test it instead of the custom action. any advantages over that?
Edit: Yeah, you Script it´s better, with the custom action i had to select the track first, the script does not need that extra step. Thanks Again spk77!!
|
Thanks, glad it worked!
Last edited by spk77; 08-16-2015 at 04:58 AM.
Reason: "Undo" fixed
|
|
|
08-16-2015, 04:43 AM
|
#18
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,689
|
Sorry to post here, but is it possible to move Selected Envelope Points +- 0,2 with mousewheel ?
|
|
|
08-16-2015, 04:48 AM
|
#19
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by Sexan
Sorry to post here, but is it possible to move Selected Envelope Points +- 0,2 with mousewheel ?
|
Yes, I think. (More difficult, but possible )
|
|
|
08-16-2015, 07:39 AM
|
#20
|
Human being with feelings
Join Date: Sep 2009
Location: Virginia
Posts: 2,068
|
Quote:
Originally Posted by spk77
Edit: ("Undo" should work now) Undo isn't working correctly - I'll see if I can fix it.
TrackItemTakeVolume_via_Mousewheel.eel[LIST][*]Mouse cursor on TCP -> adjust track volume (selected tracks)[*]Mouse cursor on arrange view-> adjust item or take volume (selected items)
|
Thanks spk77.
For some reason, I can't get the TCP track volume to work.
Media items are working.
I have the script assigned to just the mousewheel.
I'm on v5.01 pre2 with the latest sws extension (2.8.0)
Thanks, Wyatt
|
|
|
08-16-2015, 07:50 AM
|
#21
|
Human being with feelings
Join Date: Oct 2008
Location: Right Hear
Posts: 15,618
|
Quote:
Originally Posted by spk77
Edit: ("Undo" should work now) Undo isn't working correctly - I'll see if I can fix it.
TrackItemTakeVolume_via_Mousewheel.eel- Mouse cursor on TCP -> adjust track volume (selected tracks)
- Mouse cursor on arrange view-> adjust item or take volume (selected items)
Code:
function VAL2DB(x)(
x < 0.0000000298023223876953125 ? -150 : max(-150, log(x)* 8.6858896380650365530225783783321);
);
function DB2VAL(x) ( exp((x)*0.11512925464970228420089957273422 ));
want_item = 1; // set to 0 for take volume rather than item volume
cnt=0;
tr=0;
get_action_context(#foo,0,0, mode, res, val);
extension_api("BR_GetMouseCursorContext", #window, "", "");
val != 0 && match("tcp", #window) ? (
i = 0;
loop(CountSelectedTracks(0),
trh = GetSelectedTrack(0, i);
vol = GetMediaTrackInfo_Value(trh, "D_VOL");
ph = vol < 0.0;
vol = DB2VAL(VAL2DB(abs(vol)) + (val > 0 ? 0.5 : -0.5));
SetMediaTrackInfo_Value(trh,"D_VOL",ph ? -vol : vol);
i=i+1;
);
Undo_OnStateChangeEx("Adjust track volume", -1, -1);
):
val != 0 && match("arrange", #window) ? (
loop(GetNumTracks(),
trh = GetTrack(0,tr);
idx=0;
loop(GetTrackNumMediaItems(trh),
item = GetTrackMediaItem(trh,idx);
IsMediaItemSelected(item) && (want_item || (tk = GetActiveTake(item))) ? (
vol = want_item ? GetMediaItemInfo_Value(item,"D_VOL") : GetMediaItemTakeInfo_Value(tk,"D_VOL");
ph = vol < 0.0;
vol = DB2VAL(VAL2DB(abs(vol)) + (val > 0 ? 0.5 : -0.5));
want_item ? SetMediaItemInfo_Value(item,"D_VOL",vol) : SetMediaItemTakeInfo_Value(tk,"D_VOL",ph ? -vol : vol);
cnt+=1;
z=1;
);
idx+=1
);
tr+=1;
);
Undo_OnStateChangeEx("Adjust item or take volume", 4, -1);
);
cnt ? UpdateTimeline();
Thanks to Breeder for the GetMouseCursorContext functions!
Thanks, glad it worked!
|
spk77.... I assumed this is a lua script, yes?
I copied the text and loaded it as lua, but get this when trying to run it:
..reaper 64 Portable\Scripts\Volume by MW Track and Item.lua:2: ')' expected (to close '(' at line 1) near '?'
what did I do wrong? I wonder if you can post it to the stash so I can just dl it as you intended it to be?
|
|
|
08-16-2015, 08:00 AM
|
#22
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by WyattRice
Thanks spk77.
For some reason, I can't get the TCP track volume to work.
Media items are working.
I have the script assigned to just the mousewheel.
I'm on v5.01 pre2 with the latest sws extension (2.8.0)
Thanks, Wyatt
|
Hmmm...it seems it doesn't work without a modifier key - don't know why.
Quote:
Originally Posted by hopi
spk77.... I assumed this is a lua script, yes?
I copied the text and loaded it as lua, but get this when trying to run it:
..reaper 64 Portable\Scripts\Volume by MW Track and Item.lua:2: ')' expected (to close '(' at line 1) near '?'
what did I do wrong? I wonder if you can post it to the stash so I can just dl it as you intended it to be?
|
It's an EEL script - save as Volume by MW Track and Item.eel
|
|
|
08-16-2015, 12:26 PM
|
#23
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by Sexan
Sorry to post here, but is it possible to move Selected Envelope Points +- 0,2 with mousewheel ?
|
Here:
http://forum.cockos.com/showthread.p...68#post1559068
(Adjust volume envelope points (values) via mousewheel)
|
|
|
08-16-2015, 12:27 PM
|
#24
|
Human being with feelings
Join Date: Nov 2009
Location: Belgium
Posts: 10,474
|
spk77
Why the hell it don't work over mcp?
Code:
function VAL2DB(x)(
x < 0.0000000298023223876953125 ? -150 : max(-150, log(x)* 8.6858896380650365530225783783321);
);
function DB2VAL(x) ( exp((x)*0.11512925464970228420089957273422 ));
want_item = 1; // set to 0 for take volume rather than item volume
cnt=0;
tr=0;
get_action_context(#foo,0,0, mode, res, val);
extension_api("BR_GetMouseCursorContext", #window, "", "");
val != 0 && match("tcp", #window) ? (
i = 0;
loop(CountSelectedTracks(0),
trh = GetSelectedTrack(0, i);
vol = GetMediaTrackInfo_Value(trh, "D_VOL");
ph = vol < 0.0;
vol = DB2VAL(VAL2DB(abs(vol)) + (val > 0 ? 0.5 : -0.5));
SetMediaTrackInfo_Value(trh,"D_VOL",ph ? -vol : vol);
i=i+1;
);
Undo_OnStateChangeEx("Adjust track volume", -1, -1);
):
val != 0 && match("mcp", #window) ? (
i = 0;
loop(CountSelectedTracks(0),
trh = GetSelectedTrack(0, i);
vol = GetMediaTrackInfo_Value(trh, "D_VOL");
ph = vol < 0.0;
vol = DB2VAL(VAL2DB(abs(vol)) + (val > 0 ? 0.5 : -0.5));
SetMediaTrackInfo_Value(trh,"D_VOL",ph ? -vol : vol);
i=i+1;
);
Undo_OnStateChangeEx("Adjust track volume", -1, -1);
):
val != 0 && match("arrange", #window) ? (
loop(GetNumTracks(),
trh = GetTrack(0,tr);
idx=0;
loop(GetTrackNumMediaItems(trh),
item = GetTrackMediaItem(trh,idx);
IsMediaItemSelected(item) && (want_item || (tk = GetActiveTake(item))) ? (
vol = want_item ? GetMediaItemInfo_Value(item,"D_VOL") : GetMediaItemTakeInfo_Value(tk,"D_VOL");
ph = vol < 0.0;
vol = DB2VAL(VAL2DB(abs(vol)) + (val > 0 ? 0.5 : -0.5));
want_item ? SetMediaItemInfo_Value(item,"D_VOL",vol) : SetMediaItemTakeInfo_Value(tk,"D_VOL",ph ? -vol : vol);
cnt+=1;
z=1;
);
idx+=1
);
tr+=1;
);
Undo_OnStateChangeEx("Adjust item or take volume", 4, -1);
);
cnt ? UpdateTimeline();
And it would be very cool to make it all context
|
|
|
08-16-2015, 12:32 PM
|
#25
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by Reno.thestraws
spk77
Why the hell it don't work over mcp?
And it would be very cool to make it all context
|
I don't know . I was wondering that too.
Yes, this should work
Code:
val != 0 && match("mcp", #window)
Don't know which one is broken, get_action_context or BR_GetMouseCursorContext
|
|
|
08-16-2015, 12:35 PM
|
#26
|
Human being with feelings
Join Date: Nov 2009
Location: Belgium
Posts: 10,474
|
I got the same issue with this
http://forum.cockos.com/showthread.php?t=159151
work in every context 100% of times exept mcp
Sometimes it works... sometimes it doesn't!
and if I restart REAPER it works again :S
|
|
|
08-16-2015, 12:44 PM
|
#27
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,689
|
Quote:
Originally Posted by spk77
|
Sir You are amazing!!! Thank you!
Edit: It works great as custom action with this one!
Last edited by Sexan; 08-16-2015 at 12:54 PM.
|
|
|
08-16-2015, 02:26 PM
|
#28
|
Human being with feelings
Join Date: Oct 2008
Location: Right Hear
Posts: 15,618
|
thanks for that info spk.... works nicely now... what a difference a day makes, ...and the diff is SPK!
|
|
|
08-17-2015, 04:44 AM
|
#29
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,689
|
I know I'm asking too much,but could these two scripts be merged into one (Item/Track Volume and Envelope)?I know EEL would need to be ported to LUA
|
|
|
09-14-2015, 02:08 AM
|
#30
|
Human being with feelings
Join Date: Aug 2006
Location: Berlin
Posts: 11,818
|
Little bump. Some folks are starting to miss this.
|
|
|
12-30-2015, 12:59 PM
|
#31
|
Human being with feelings
Join Date: Aug 2006
Location: Berlin
Posts: 11,818
|
Tiny bump. Pointing some folks to this.
|
|
|
12-30-2015, 02:19 PM
|
#32
|
Human being with feelings
Join Date: Jan 2010
Location: Kalispell
Posts: 14,759
|
Quote:
Originally Posted by airon
Tiny bump. Pointing some folks to this.
|
Thanks airon, I DLed it and will check it out.
|
|
|
12-30-2015, 03:37 PM
|
#33
|
Human being with feelings
Join Date: Jan 2012
Location: Germany
Posts: 1,133
|
Thanks for bumping. I would have missed it. Life is way easier now
|
|
|
12-30-2015, 10:06 PM
|
#34
|
Human being with feelings
Join Date: Dec 2010
Posts: 3,826
|
so there is no way to have this adjust volume on items when over items, but zoom when over empty arrange ?
__________________
Stop posting huge images, smaller images or thumbnail, it's not rocket science!
|
|
|
01-02-2016, 11:35 AM
|
#35
|
Human being with feelings
Join Date: Jun 2006
Location: UK
Posts: 3,221
|
thanks to those who bumped!
lovely little script!
Subz
|
|
|
01-03-2016, 04:50 PM
|
#36
|
Human being with feelings
Join Date: Jun 2012
Posts: 2,173
|
Yeah, I missed it the first time too I guess.
My question is, does this:
get_action_context(#foo,0,0, mode, res, val);
have any connection to the clicker buttons on the mouse? I'd like to be able to suspend or enable defer functions with it. Looks like "no", but figured I'd ask.
I would guess partial answer to gpunk_w might be: Probably could trigger the keyboard (one direction) zoom actions like that. Don't know about passing wheel through it. Can't try now.
|
|
|
02-09-2016, 09:46 AM
|
#37
|
Human being with feelings
Join Date: Dec 2011
Location: Oslo
Posts: 29
|
Quote:
Originally Posted by BenK-msx
mousewheel should be a mouse modifier option.
|
I agree!
|
|
|
07-13-2016, 11:01 AM
|
#38
|
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 15,746
|
Here's a version of the script that waits to process undo until after mouse tweaking has finished:
Code:
function VAL2DB(x)(
x < 0.0000000298023223876953125 ? -150 : max(-150, log(x)* 8.6858896380650365530225783783321);
);
function DB2VAL(x) ( exp((x)*0.11512925464970228420089957273422 ));
want_item = 1; // set to 0 for take volume rather than item volume
function run(first) (
val=cnt=tr=0;
get_action_context(#foo,0,0, mode, res, val)||first ? (
pc=time_precise();
val != 0 ? loop(GetNumTracks(),
trh = GetTrack(0,tr);
idx=0;
loop(GetTrackNumMediaItems(trh),
item = GetTrackMediaItem(trh,idx);
IsMediaItemSelected(item) && (want_item || (tk = GetActiveTake(item))) ? (
vol = want_item ? GetMediaItemInfo_Value(item,"D_VOL") : GetMediaItemTakeInfo_Value(tk,"D_VOL");
ph = vol < 0.0;
vol = DB2VAL(VAL2DB(abs(vol)) + (val > 0 ? 0.5 : -0.5));
want_item ? SetMediaItemInfo_Value(item,"D_VOL",vol) : SetMediaItemTakeInfo_Value(tk,"D_VOL",ph ? -vol : vol);
cnt+=1;
z=1;
);
idx+=1
);
tr+=1
);
cnt != 0 ? UpdateTimeline();
);
time_precise() < pc+1 ? defer("run(0)") : Undo_OnStateChange("Adjust Item Volume");
);
run(1);
|
|
|
07-13-2016, 12:02 PM
|
#39
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by Justin
Here's a version of the script that waits to process undo until after mouse tweaking has finished:
|
That's nice, thank you!
(..And a weird coincidence: I was trying to do the same "delayed undo point" thing yesterday .
Actually I tried different things with time_precise, Undo_BeginBlock/ Undo_EndBlock and Get/SetExtState combination, but couldn't get it to work).
|
|
|
07-15-2016, 11:05 AM
|
#40
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Edit: fixed - thanks cfillion! The code below is also updated.
So, this...
reaper.defer(main(false))
is replaced with...
reaper.defer(function() main(false) end)
I'm not able to get this undo thing working in Lua...
Can we pass functions with parameters to "reaper.defer" function? Like this: reaper.defer(main(false))?
I get Adjust hue via mousewheel.lua:164: stack overflow -error with this code:
Code:
--------------
-- Settings --
--------------
-- If track has default color, this value is used (as a starting point):
local default_color = 9732439 -- blue
--local default_color = 9211010 -- default track color of REAPER 5 theme
-- These variables define how many steps (mouse wheel turns) it takes to go from min val to max val
local hue_steps = 36
local sat_steps = 25
local lum_steps = 25
-- Min and max values for saturation and luminosity
local min_sat = 0.1
local max_sat = 1
local min_lum = 0.1
local max_lum = 0.9
-- End of settings --
local floor = math.floor
local min_v = math.min
local max_v = math.max
local defer_count = 0
local pc
function msg(m)
return reaper.ShowConsoleMsg(tostring(m) .. "\n")
end
function intToRgb(color_int)
local r = color_int & 255
local g = (color_int >> 8) & 255
local b = (color_int >> 16) & 255
r = r/255
g = g/255
b = b/255
return r, g, b
end
function rgbToHsl(r, g, b)
--r, g, b = r / 255, g / 255, b / 255
local max, min = max_v(r, g, b), min_v(r, g, b)
local h, s, l
l = (max + min) / 2
if max == min then
h, s = 0, 0 -- achromatic
else
local d = max - min
--local s
if l > 0.5 then s = d / (2 - max - min) else s = d / (max + min) end
if max == r then
h = (g - b) / d
if g < b then h = h + 6 end
elseif max == g then h = (b - r) / d + 2
elseif max == b then h = (r - g) / d + 4
end
h = h / 6
end
return h, s, l
end
function hslToRgb(h, s, l)
local r, g, b
if s == 0 then
r, g, b = l, l, l -- achromatic
else
function hue2rgb(p, q, t)
if t < 0 then t = t + 1 end
if t > 1 then t = t - 1 end
if t < 1/6 then return p + (q - p) * 6 * t end
if t < 1/2 then return q end
if t < 2/3 then return p + (q - p) * (2/3 - t) * 6 end
return p
end
local q
if l < 0.5 then q = l * (1 + s) else q = l + s - l * s end
local p = 2 * l - q
r = hue2rgb(p, q, h + 1/3)
g = hue2rgb(p, q, h)
b = hue2rgb(p, q, h - 1/3)
end
--return r * 255, g * 255, b * 255
return r, g, b
end
function adjust_hsl(val, adjust_hue, adjust_sat, adjust_lum)
--local is_new_value, filename, sectionID, cmdID, mode, resolution, val = reaper.get_action_context()
--msg(is_new_value)
--msg(mode)
--msg(resolution)
--msg(val)
--[[
if val == -1 then
return
end
--]]
for i=1, reaper.CountSelectedTracks(0) do
local tr = reaper.GetSelectedTrack(0, i-1)
local color_int = reaper.GetTrackColor(tr)
if color_int == 0 then color_int = default_color end
local r,g,b = intToRgb(color_int)
local h,s,l = rgbToHsl(r,g,b)
if val < -1 then
if adjust_hue then
h = h + 1/(hue_steps)
end
if adjust_sat then
s = s + 1/(sat_steps)
if s > max_sat then
s = max_sat
elseif s < min_sat then
s = min_sat
end
end
if adjust_lum then
l = l + 1/(lum_steps)
if l > max_lum then
l = max_lum
elseif l < min_lum then
l = min_lum
end
end
elseif val > -1 then
if adjust_hue then
h = h - 1/(hue_steps)
end
if adjust_sat then
s = s - 1/(sat_steps)
if s < min_sat then
s = min_sat
elseif s > max_sat then
s = max_sat
end
end
if adjust_lum then
l = l - 1/(lum_steps)
if l < min_lum then
l = min_lum
elseif l > max_lum then
l = max_lum
end
end
end
r,g,b = hslToRgb(h,s,l)
reaper.SetTrackColor(tr, reaper.ColorToNative(floor(r*255+0.5), floor(g*255+0.5), floor(b*255+0.5)))
end
end
function main(first_time)
local is_new_value, filename, sectionID, cmdID, mode, resolution, val = reaper.get_action_context()
if is_new_value or first_time then
pc = reaper.time_precise()
if val ~= 0 then
-- Desc: adjust_hsl(boolean adjust_hue, boolean adjust_sat, boolean adjust_lum)
adjust_hsl(val, true, false, false)
-- adjust_hsl(false, true, false) -- adjust saturation
-- adjust_hsl(false, false, true) -- adjust luminosity
end
end
---[[
if reaper.time_precise() < pc + 1 then
--defer_count = defer_count+1
--reaper.ClearConsole()
--msg(val)
reaper.defer(function() main(false) end)
else
reaper.Undo_OnStateChangeEx("Adjust track color", -1, -1)
end
--]]
end
main(true)
Remove the red text and it works, but it creates an undo point every time:
Last edited by spk77; 07-15-2016 at 11:43 AM.
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 11:07 PM.
|