Old 05-24-2019, 09:23 AM   #481
DaveKeehl
Human being with feelings
 
DaveKeehl's Avatar
 
Join Date: Nov 2015
Location: Switzerland
Posts: 1,781
Default

Hi, I just started coding some scripts in lua for reaper and I don't understand what HWND means (for example in reaper.GetMainHwnd). Can someone explain it to me?
DaveKeehl is offline   Reply With Quote
Old 05-24-2019, 09:26 AM   #482
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,313
Default

Quote:
Originally Posted by DaveKeehl View Post
Hi, I just started coding some scripts in lua for reaper and I don't understand what HWND means (for example in reaper.GetMainHwnd). Can someone explain it to me?
It's an object, that reflects a window or a gui-element in a window.

For instance GetMainHwnd returns the object of Reaper's main window(the one with the arrangeview in it) and you can manipulate it using appropriate functions.
If you use the most recent version of SWS and/or the js-extension, there are functions, who allow you to do that, like getting/changing position, title, scrollstate of the window, etc.

When I say, gui-element: not all Gui-elements in Reaper have a hwnd, only the ones that are system-dialogs/elements. For instance, all elements in the Render to File-dialog have hwnds, the solo button of a track has not(afaik)


Edit: try experimenting with JS_Window_SetTitle to get an idea.
https://mespotin.uber.space/Ultrasch...indow_SetTitle

Needs the js-extension-plugin, which you can get here: https://forum.cockos.com/showthread.php?t=212174
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 05-29-2019, 06:50 AM   #483
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 8,846
Default

Adding to mespotine,
https://docs.microsoft.com/en-us/cpp...d?view=vs-2019

So, a handle (specific type of pointer)* to a window.

*Though handle and pointer are not fully equivalent:
https://stackoverflow.com/questions/...things/1923646
nofish is offline   Reply With Quote
Old 05-31-2019, 07:30 AM   #484
sw_
Human being with feelings
 
Join Date: Oct 2018
Posts: 22
Default

How do I convert the volume and pan from GetTrackUIVolPan to a 0-127 CC value? In other words I'd like to convert the pan (-1 to 1) range to 0-127 and the tracks max and min volume to 0-127.

I get the internal values in the console, it's just that I have to reformat them before passing the values along with StuffMIDIMessage since that wound pass negative values. Please help ! I need this for my diy motorized fader to work.
sw_ is offline   Reply With Quote
Old 05-31-2019, 02:26 PM   #485
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,682
Default

Code:
round((floatValue + 1.0) * (127.0 / 2.0))

Last edited by cfillion; 05-31-2019 at 02:37 PM.
cfillion is offline   Reply With Quote
Old 06-01-2019, 08:32 AM   #486
sw_
Human being with feelings
 
Join Date: Oct 2018
Posts: 22
Default

Quote:
Originally Posted by cfillion View Post
Code:
round((floatValue + 1.0) * (127.0 / 2.0))
Amazing!! Thanks!! Do you by any chance know this?

How do I send a 14 bit midi message over midi? I only seem to be able to send up to 255 with stufffmidimessage.
sw_ is offline   Reply With Quote
Old 06-01-2019, 10:46 AM   #487
Breeder
Human being with feelings
 
Breeder's Avatar
 
Join Date: Nov 2010
Location: Croatia
Posts: 2,109
Default

TrackFX_GetInstrument() returns -1 if instrument is offline? Any simple way around this?
__________________
My contributions
Breeder is offline   Reply With Quote
Old 06-16-2019, 11:19 PM   #488
danerius
Human being with feelings
 
Join Date: Oct 2018
Posts: 38
Default Help explaining code

Hi. Im having trouble understanding this bit of code. Its from Losers Waveshaping Distortion.

Mostly the second line "hdistr =....". How does the "100,.999" bit work? I get that It gives a value for "foo" to be calculated and then used in the formula. How would I enter these values in a regular calculator? Slider range is 0-100.

/thx

@slider
hdistr = min(slider1/100,.999);
foo = 2*hdistr/(1-hdistr);

@sample
spl0 = min(max(spl0,-1),1);
spl1 = min(max(spl1,-1),1);

spl0 = (1+foo)*spl0/(1+foo*abs(spl0));
spl1 = (1+foo)*spl1/(1+foo*abs(spl1));
danerius is offline   Reply With Quote
Old 06-17-2019, 12:16 AM   #489
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 5,314
Default

Quote:
Originally Posted by danerius View Post
Hi. Im having trouble understanding this bit of code. Its from Losers Waveshaping Distortion.

Mostly the second line "hdistr =....". How does the "100,.999" bit work? I get that It gives a value for "foo" to be calculated and then used in the formula. How would I enter these values in a regular calculator? Slider range is 0-100.

/thx

@slider
hdistr = min(slider1/100,.999);
foo = 2*hdistr/(1-hdistr);

@sample
spl0 = min(max(spl0,-1),1);
spl1 = min(max(spl1,-1),1);

spl0 = (1+foo)*spl0/(1+foo*abs(spl0));
spl1 = (1+foo)*spl1/(1+foo*abs(spl1));
I am not sure exactly what you are asking. Do you mean
Code:
min(slider1/100,.999)
It divides the value of slider1 by 100, then takes the minimum of that value and 0.999. Is this what you mean?

Or do you mean to ask why the value of foo is calculated the way it is? Of that, I have no idea, sorry.
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian is offline   Reply With Quote
Old 06-17-2019, 02:45 AM   #490
danerius
Human being with feelings
 
Join Date: Oct 2018
Posts: 38
Default

Quote:
Originally Posted by Fabian View Post
I am not sure exactly what you are asking. Do you mean
Code:
min(slider1/100,.999)
It divides the value of slider1 by 100, then takes the minimum of that value and 0.999. Is this what you mean?

Or do you mean to ask why the value of foo is calculated the way it is? Of that, I have no idea, sorry.
Hi + massor med tack Both actually. But theyre kind of separate questions

I understand the 'slider1 divided by 100'. But is it adding .0999 to the result? Multiplying?

/thx
danerius is offline   Reply With Quote
Old 06-17-2019, 03:28 AM   #491
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 5,314
Default

Quote:
Originally Posted by danerius View Post
Hi + massor med tack Both actually. But theyre kind of separate questions

I understand the 'slider1 divided by 100'. But is it adding .0999 to the result? Multiplying?

/thx
Code:
min(x, y)
returns the smallest value of x and y.

So in the particular case of
Code:
min(slider1/100, 0.999)
when slider1 is 100, 0.999 will be returned, not 1. This is to not get a divide by zero on the next line
Code:
foo = 2*hdistr/(1-hdistr);
as hdistr is guaranteed to never be exactly 1.
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian is offline   Reply With Quote
Old 06-17-2019, 05:01 AM   #492
danerius
Human being with feelings
 
Join Date: Oct 2018
Posts: 38
Default

Quote:
Originally Posted by Fabian View Post
Code:
min(x, y)
returns the smallest value of x and y.

So in the particular case of
Code:
min(slider1/100, 0.999)
when slider1 is 100, 0.999 will be returned, not 1. This is to not get a divide by zero on the next line
Code:
foo = 2*hdistr/(1-hdistr);
as hdistr is guaranteed to never be exactly 1.
Oh... Excellent. Got it now

Im guessing its best practice to include a minimum value?

/thx
danerius is offline   Reply With Quote
Old 06-17-2019, 05:52 AM   #493
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 5,314
Default

Quote:
Originally Posted by danerius View Post
Oh... Excellent. Got it now

Im guessing its best practice to include a minimum value?

/thx
Well... Not necessarily, it depends on what you want to do.

In this case it is definitely good. Divide by zero is something you absolutely want to avoid.
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian is offline   Reply With Quote
Old 06-17-2019, 06:32 AM   #494
danerius
Human being with feelings
 
Join Date: Oct 2018
Posts: 38
Default

Quote:
Originally Posted by Fabian View Post
Well... Not necessarily, it depends on what you want to do.

In this case it is definitely good. Divide by zero is something you absolutely want to avoid.
Awesome. Thanks again
danerius is offline   Reply With Quote
Old 06-17-2019, 09:35 AM   #495
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,313
Default

Are extension-functions able to find out, in which script they run? Like get_action_context for C++ in ReaScripts or something?

And if yes, can they run automatically at script-startup, before the script is run actually?
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 06-19-2019, 01:35 AM   #496
danerius
Human being with feelings
 
Join Date: Oct 2018
Posts: 38
Default Flipping Waveforms

Hi

Chris from Airwindows told me he often converts negative waves to positive ones for processing. Then flips them back again. Is thats whats happening in this bit of code? The "abs" flips the negative part to positive. And the lines above that flips it backa again?

Im trying to learn... so any other examples of this practice would be awesome. thx

@sample
spl0 = min(max(spl0,-1),1);
spl1 = min(max(spl1,-1),1);

spl0 = (1+foo)*spl0/(1+foo*abs(spl0));
spl1 = (1+foo)*spl1/(1+foo*abs(spl1));
danerius is offline   Reply With Quote
Old 07-07-2019, 08:50 AM   #497
sai'ke
Human being with feelings
 
sai'ke's Avatar
 
Join Date: Aug 2009
Location: Germoney
Posts: 621
Default

Ask him what he means. The sentence is ambiguous and could refer to any number of things.

Quote:
Originally Posted by danerius View Post
@sample
spl0 = min(max(spl0,-1),1);
spl1 = min(max(spl1,-1),1);
Clamps the input between -1 and 1, any higher signal will be clipped to -1 or 1.

Quote:
Originally Posted by danerius View Post
spl0 = (1+foo)*spl0/(1+foo*abs(spl0));
spl1 = (1+foo)*spl1/(1+foo*abs(spl1));
This interpolates between no distortion to a smooth clipper for positive values of foo. For negative values all hell can break loose.

I don't really see why you would want to clip the signal before the smooth function in this case, since the smooth function already nicely goes into saturation.
__________________
[Tracker Plugin: Thread|Github|Reapack] | [Routing Plugin: Thread|Reapack] | [Filther: Thread|Github|Reapack] | [More JSFX: Thread|Reapack]
sai'ke is offline   Reply With Quote
Old 07-07-2019, 08:54 AM   #498
sai'ke
Human being with feelings
 
sai'ke's Avatar
 
Join Date: Aug 2009
Location: Germoney
Posts: 621
Default

Have a question of my own, is there a non-ambiguous way to detect whether a user has changed a preset on a JSFX?
__________________
[Tracker Plugin: Thread|Github|Reapack] | [Routing Plugin: Thread|Reapack] | [Filther: Thread|Github|Reapack] | [More JSFX: Thread|Reapack]
sai'ke is offline   Reply With Quote
Old 07-07-2019, 09:14 AM   #499
danerius
Human being with feelings
 
Join Date: Oct 2018
Posts: 38
Default

Quote:
Originally Posted by sai'ke View Post
I don't really see why you would want to clip the signal before the smooth function in this case, since the smooth function already nicely goes into saturation.
Me neither. Im still a bit befuddled by what the actual numbers are for audio samples. Between -1 to 1. with a bit of leeway for overs? How much is that?

Thanks /Bo
danerius is offline   Reply With Quote
Old 07-07-2019, 09:40 AM   #500
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,313
Default

Quote:
Originally Posted by sai'ke View Post
Have a question of my own, is there a non-ambiguous way to detect whether a user has changed a preset on a JSFX?
Changed a preset or selected another preset?
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 07-07-2019, 09:44 AM   #501
sai'ke
Human being with feelings
 
sai'ke's Avatar
 
Join Date: Aug 2009
Location: Germoney
Posts: 621
Default

Quote:
Originally Posted by mespotine View Post
Changed a preset or selected another preset?
Ah sorry, selected.
__________________
[Tracker Plugin: Thread|Github|Reapack] | [Routing Plugin: Thread|Reapack] | [Filther: Thread|Github|Reapack] | [More JSFX: Thread|Reapack]
sai'ke is offline   Reply With Quote
Old 07-07-2019, 09:47 AM   #502
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,313
Default

You could monitor them, using
https://mespotin.uber.space/Ultrasch...GetPresetIndex
https://mespotin.uber.space/Ultrasch...GetPresetIndex

Would that work?
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 07-07-2019, 09:51 AM   #503
sai'ke
Human being with feelings
 
sai'ke's Avatar
 
Join Date: Aug 2009
Location: Germoney
Posts: 621
Default

Quote:
Originally Posted by mespotine View Post
Ah, sorry, I should have specified. I meant in JSFX. I'd rather not use an additional extra script for monitoring it.

That's a nice function though! Good to know it exists for future reference.
__________________
[Tracker Plugin: Thread|Github|Reapack] | [Routing Plugin: Thread|Reapack] | [Filther: Thread|Github|Reapack] | [More JSFX: Thread|Reapack]
sai'ke 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 10:25 PM.


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