Old 08-14-2018, 10:21 AM   #1
JeffreyET
Human being with feelings
 
JeffreyET's Avatar
 
Join Date: Dec 2012
Location: Raleigh, NC, USA
Posts: 405
Default LUA command terms?

With much appreciation to VanHaze, who got me to this point -
I have a script for mouse selection behavior, but it doesn't work because (presumably) I am using a Lenovo laptop touchpad. Are there touchpad-specific commands that can be edited in? I pasted the script below.


local window, segment, details = r.BR_GetMouseCursorContext()
local mouse = r.BR_GetMouseCursorContext_Position()
if not mouse then bla() return end

local mouse_tr = r.BR_TrackAtMouseCursor()
if not mouse_tr then bla() return end

local items = r.CountTrackMediaItems(mouse_tr)

local min_d = math.huge

local item_c

for i = 0, items - 1 do
local item = r.GetTrackMediaItem(mouse_tr,i)
local it_x = r.GetMediaItemInfo_Value(item, 'D_POSITION')
local it_y = r.GetMediaItemInfo_Value(item, 'D_LENGTH')+it_x


if it_x < mouse and it_y > mouse then
item_c = item
break
else
local min = math.min(math.abs(it_x-mouse),math.abs(it_y-mouse))
if min_d > min then
min_d = min
item_c = item
end
end
end
__________________
Jeffrey's REAPER tracks Are on Spotify as well as most other streaming services, under the name Karmic Cage.
JeffreyET is offline   Reply With Quote
Old 08-14-2018, 10:43 AM   #2
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,984
Default

Quote:
doesn't work because (presumably) I am using a Lenovo laptop touchpad
It is just full of misundestandings of how REAPER API and lua itself works. What do you want to do?
mpl is offline   Reply With Quote
Old 08-14-2018, 10:50 AM   #3
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,630
Default

What does "it doesn't work" mean. Does it display an error message or doesn't it do anything at all?

What is the script supposed to do in the first place and what do you mean by Lua command terms(as stated in the thread-title)?


Edit:
just one thing I noticed instantly:
Code:
if not mouse then bla() return end
can't work, as there is no function bla defined anywhere.


Another thing, please use the code-BB-codes for displaying source-codes, as this makes your code much more readable, and some comments, what the code is supposed to do at a given point(or what you think it should do, even if it doesn't)

Code:
local window, segment, details = r.BR_GetMouseCursorContext()
local mouse = r.BR_GetMouseCursorContext_Position()
if not mouse then 
    bla() 
    return 
end

local mouse_tr = r.BR_TrackAtMouseCursor()
if not mouse_tr then 
    bla() 
    return 
end

local items = r.CountTrackMediaItems(mouse_tr)
local min_d = math.huge
local item_c

for i = 0, items - 1 do
    local item = r.GetTrackMediaItem(mouse_tr,i)
    local it_x = r.GetMediaItemInfo_Value(item, 'D_POSITION')
    local it_y = r.GetMediaItemInfo_Value(item, 'D_LENGTH')+it_x

    if it_x < mouse and it_y > mouse then
        item_c = item
        break
    else
        local min = math.min(math.abs(it_x-mouse),math.abs(it_y-mouse))
        if min_d > min then
            min_d = min
            item_c = item
        end
    end
end

Last edited by Meo-Ada Mespotine; 08-14-2018 at 10:59 AM.
Meo-Ada Mespotine is offline   Reply With Quote
Old 08-14-2018, 11:02 AM   #4
JeffreyET
Human being with feelings
 
JeffreyET's Avatar
 
Join Date: Dec 2012
Location: Raleigh, NC, USA
Posts: 405
Default

It is supposed to allow your mouse to select the nearest object. By "doesn't work" I mean I get an error message referring to the first line with the 'MouseCursor' term, to the effect that it is a null quantity. Sorry I'm not a programmer, not familiar with precise terminology. I think perhaps there is a simple substitution edit that could make this script work with a touchpad instead.
__________________
Jeffrey's REAPER tracks Are on Spotify as well as most other streaming services, under the name Karmic Cage.
JeffreyET is offline   Reply With Quote
Old 08-14-2018, 11:06 AM   #5
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,630
Default

Ok, as far as I can see, you use r. before all Reaper-Api-commands, but they must start with reaper. instead.

e.g.

r.BR_GetMouseCursorContext_Position()

must be

reaper.BR_GetMouseCursorContext_Position()


The same goes with all other functions, that start with r. just replace r. with reaper.


VanHaze probably showed you a way to use r. instead, but, especially if you are not programmer, please use the "official" way of doing it, which is shown in the Reascript-API-documentation.

Have you looked into the API-documentation?

Edit: as far as I can see, you don't need bla() in your script at all. What is your intention with bla() ?
Meo-Ada Mespotine is offline   Reply With Quote
Old 08-14-2018, 11:24 AM   #6
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,984
Default

Quote:
Originally Posted by JeffreyET View Post
allow your mouse to select the nearest object.
Here are some questions you should answer youself before asking us:
1) what is object - item, automation item, envelope point, stretch marker, midi note, etc?
2) is there a time limit for selection. Object to select may be placed 6 hours far from your mouse, and it will be selected since it nearest?
3) should it take into account other tracks?
4) deselect other stuff?

Btw what is wrong with your touchpad? I have Asus laptop and I use touchpad with no problems even on pretty complex projects.
mpl is offline   Reply With Quote
Old 08-14-2018, 11:34 AM   #7
JeffreyET
Human being with feelings
 
JeffreyET's Avatar
 
Join Date: Dec 2012
Location: Raleigh, NC, USA
Posts: 405
Default

Quote:
Originally Posted by mpl View Post
Here are some questions you should answer youself before asking us:
1) what is object - item, automation item, envelope point, stretch marker, midi note, etc?
2) is there a time limit for selection. Object to select may be placed 6 hours far from your mouse, and it will be selected since it nearest?
3) should it take into account other tracks?
4) deselect other stuff?

Btw what is wrong with your touchpad? I have Asus laptop and I use touchpad with no problems even on pretty complex projects.
Nothing wrong, just want a way to select notes in the MIDI editor with less micro-precision hovering...
__________________
Jeffrey's REAPER tracks Are on Spotify as well as most other streaming services, under the name Karmic Cage.
JeffreyET is offline   Reply With Quote
Old 08-14-2018, 11:40 AM   #8
JeffreyET
Human being with feelings
 
JeffreyET's Avatar
 
Join Date: Dec 2012
Location: Raleigh, NC, USA
Posts: 405
Default

Quote:
Originally Posted by mespotine View Post
Ok, as far as I can see, you use r. before all Reaper-Api-commands, but they must start with reaper. instead.

e.g.

r.BR_GetMouseCursorContext_Position()

must be

reaper.BR_GetMouseCursorContext_Position()


The same goes with all other functions, that start with r. just replace r. with reaper.


VanHaze probably showed you a way to use r. instead, but, especially if you are not programmer, please use the "official" way of doing it, which is shown in the Reascript-API-documentation.

Have you looked into the API-documentation?

Edit: as far as I can see, you don't need bla() in your script at all. What is your intention with bla() ?
Don't know about bla(), I just took the script whole from someone else. Not interested or skilled in dissecting the code. But I'll try your simple suggestion before quietly leaving the arena
__________________
Jeffrey's REAPER tracks Are on Spotify as well as most other streaming services, under the name Karmic Cage.
JeffreyET is offline   Reply With Quote
Old 08-14-2018, 11:49 AM   #9
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,630
Default

Ah, ok, that explains the difficulties in the script
Meo-Ada Mespotine is offline   Reply With Quote
Old 08-14-2018, 12:02 PM   #10
JeffreyET
Human being with feelings
 
JeffreyET's Avatar
 
Join Date: Dec 2012
Location: Raleigh, NC, USA
Posts: 405
Default

Hey ya know what? There is already an action pre-written for this - I just didn't look for it. So I've been barking up a much bigger tree than I needed to be. Peace & thanks
__________________
Jeffrey's REAPER tracks Are on Spotify as well as most other streaming services, under the name Karmic Cage.
JeffreyET is offline   Reply With Quote
Old 08-14-2018, 12:27 PM   #11
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,630
Default

Which action is it? Might be helpful for others searching the forum.
Meo-Ada Mespotine is offline   Reply With Quote
Old 08-15-2018, 12:02 AM   #12
vanhaze
Human being with feelings
 
vanhaze's Avatar
 
Join Date: Jul 2012
Location: Netherlands
Posts: 5,247
Default

"Script: me2beats_Select only note near mouse.lua"
__________________
Macbook Pro INTEL | Reaper, always latest version | OSX Ventura | Presonus Studio 24c
My Reaper Tips&Tricks YouTube Channel: https://www.youtube.com/user/vanhaze2000/playlists
vanhaze is offline   Reply With Quote
Old 08-20-2018, 06:57 AM   #13
JeffreyET
Human being with feelings
 
JeffreyET's Avatar
 
Join Date: Dec 2012
Location: Raleigh, NC, USA
Posts: 405
Default

Mesopotine - I'm away from my computer, now, I'll look it up & post later...I looked for & found an action for selecting a note in the MIDI editor
__________________
Jeffrey's REAPER tracks Are on Spotify as well as most other streaming services, under the name Karmic Cage.
JeffreyET 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 06:12 AM.


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