Old 02-18-2019, 08:40 AM   #241
nappies
Human being with feelings
 
nappies's Avatar
 
Join Date: Dec 2017
Posts: 302
Default Strange thing

Guys what am i doing wrong? JS_Window_ListAllChild return empty string.

Last version JS API installed and Reaper also last version.




Code:
function msg(m)
  reaper.ShowConsoleMsg(tostring(m) .. "\n")
end


main_wnd = reaper.GetMainHwnd()
local retval, list = reaper.JS_Window_ListAllChild(main_wnd)
msg(list)
nappies is offline   Reply With Quote
Old 02-18-2019, 12:14 PM   #242
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

@nappies
I don't have much help to offer but can only say your code is working here.
No idea what could be going wrong, sorry.

nofish is offline   Reply With Quote
Old 02-18-2019, 02:56 PM   #243
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by Edgemeal View Post
@ juliansader
Any plans to add support for ComboBox list like you did for ListView?
Communication with ComboBoxes are through standard window messages, using JS_WindowMessage_Send. The ComboBox message names, such as "CB_GETCOUNT" aren't automatically recognized by the current version of the extension, but I can easily add these to the next update.

In the meantime, you can use message numbers such as "0x0146" instead of "CB_GETCOUNT", for example, when accessing ComboBoxes.
juliansader is offline   Reply With Quote
Old 02-18-2019, 03:03 PM   #244
nappies
Human being with feelings
 
nappies's Avatar
 
Join Date: Dec 2017
Posts: 302
Default

nofish, thank you man! I thought I was going crazy) On the new reinstalled reaper everything is ok.
nappies is offline   Reply With Quote
Old 02-18-2019, 04:18 PM   #245
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by juliansader View Post
Communication with ComboBoxes are through standard window messages, using JS_WindowMessage_Send. The ComboBox message names, such as "CB_GETCOUNT" aren't automatically recognized by the current version of the extension, but I can easily add these to the next update.

In the meantime, you can use message numbers such as "0x0146" instead of "CB_GETCOUNT", for example, when accessing ComboBoxes.
I tried but not sure how to get the text, the last API call says param #4 should be a number but pretty sure Win32 API expects a string buffer. What am I doing wrong?

Code:
function msg(str)
  reaper.ShowConsoleMsg(tostring(str) .. '\n')
end

CB_GETCOUNT = "0x0146"
CB_GETLBTEXT = "0x0148"
CB_GETLBTEXTLEN = "0x0149"

reaper.ClearConsole()

local title = reaper.JS_Localize("VST: ReaEQ", "common") --< Floating FX window
local hwnd = reaper.JS_Window_Find(title, false)
if not hwnd then return end

 -- get presets combobox
local container = reaper.JS_Window_FindChildByID(hwnd, 0)
local presets = reaper.JS_Window_FindChildByID(container, 1000)

local itemCount = reaper.JS_WindowMessage_Send(presets, CB_GETCOUNT, 0,0,0,0)
msg(itemCount)

for i = 0, itemCount-1 do
  local itemLength = reaper.JS_WindowMessage_Send(presets, CB_GETLBTEXTLEN, i, 0,0,0) 
  local buffer = string.rep(" ", itemLength) 
  reaper.JS_WindowMessage_Send(presets, CB_GETLBTEXT, i, buffer, 0,0) 
  msg(buffer)
end

Last edited by Edgemeal; 02-18-2019 at 04:28 PM.
Edgemeal is offline   Reply With Quote
Old 02-19-2019, 11:30 PM   #246
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by Edgemeal View Post
I tried but not sure how to get the text, the last API call says param #4 should be a number but pretty sure Win32 API expects a string buffer. What am I doing wrong?
That window message requires the address of a buffer into which it can write a string, and it should be passed to the API function as a Lua number. Pointers can be converted to address numbers by JS_Window_AddressFromHandle (or a simple tostring on the handle).

Lua strings are fixed, so aren't editable buffers into which functions can write new strings. I am not aware of any Lua function in REAPER that allocates such memory, except new_array(). Perhaps I should add some functions for allocating memory buffers to the extension?

I haven't been able to get CB_GETLBTEXT and CB_GETLBTEXTLEN to work either, even with properly allocated buffers. CB_GETLBTEXTLEN returns wildly exaggerated values, and CB_GETLBTEXT just returns an error code.

For most of REAPER's comboboxes, this shouldn't be a problem, since their contents are known and fixed: as long as CB_GETCURSEL (or even JS_Window_GetTitle) and CB_SETCURSEL work, you can get and set combobox selection.

For comboboxes with variable contents, such as the ReaEQ presets, I don't have a good solution yet, unfortunately. Perhaps you can activate each preset one-by-one and use GetTitle to get the name?

Last edited by juliansader; 02-19-2019 at 11:55 PM.
juliansader is offline   Reply With Quote
Old 02-20-2019, 01:37 AM   #247
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by juliansader View Post
Perhaps you can activate each preset one-by-one and use GetTitle to get the name?
I didn't expect CB_SETCURSEL to work better then REAPER's API.
If I try doing this same thing with REAPER API (example, see MPL's reabank script) on say 'Guitar Rig 5' I don't get any preset text and REAPER gets really slow and will crash if I don't stop the script right away.
Some plugins don't like when the presets are changed really fast and crash, But this works!

Testing: Windows 7 / js_ReaScriptAPI v0.963 / REAPER v5.965

Code:
-- TEST: Create Reabank file for 'Guitar Rig 5' --

fx_name = 'Guitar Rig 5' -- floating FX window

function Main()
  local CB_GETCOUNT = "0x0146"
  local CB_GETCURSEL = "0x0147"
  local CB_SETCURSEL = "0x014E"
  -- Find VST floating FX window
  local title = reaper.JS_Localize("VST: ".. fx_name, "common")
  local hwnd = reaper.JS_Window_Find(title, false)
  if not hwnd then return end
   -- get presets combobox
  local container = reaper.JS_Window_FindChildByID(hwnd, 0)
  local presets = reaper.JS_Window_FindChildByID(container, 1000)
  local itemCount = reaper.JS_WindowMessage_Send(presets, CB_GETCOUNT, 0,0,0,0)
  -- save current index
  local cur_index = reaper.JS_WindowMessage_Send(presets, CB_GETCURSEL, 0,0,0,0)
  local listStart = 3
  -- build reabank
   local str = 
  [[
  // .reabank bank/program (patch) information
  // A bank entry lists the MSB, LSB, and bank name
  // for all the patches that follow, until the next bank entry.
  ]]..'\n'..'Bank 0 0 '.. fx_name ..' 001-'..tostring(itemCount-listStart)..'\n'
  -- get preset names
  for i = listStart, itemCount-1 do
    reaper.JS_WindowMessage_Send(presets, CB_SETCURSEL, i, 0,0,0)
    str = str..'\n'..(i-listStart)..' '..reaper.JS_Window_GetTitle(presets,"")
  end
  -- restore index
  reaper.JS_WindowMessage_Send(presets, CB_SETCURSEL, cur_index, 0,0,0)
  -- get file path from user for reabank file
  local initialFolder = reaper.GetResourcePath()..[[\Data]] 
  local initialFile = fx_name .. ".reabank" 
  local extensionList = "ReaBank files (*.reabank)\0*.reabank\0\0" 
  local ret, filename = reaper.JS_Dialog_BrowseForSaveFile("Save As Reabank", initialFolder, initialFile, extensionList)
  if ret == 0 then return end
  -- write data to file
  file = io.open(filename, "w")
  file:write(str)
  file:close()
end
-- begin
if not reaper.APIExists("JS_Localize") then
  reaper.MB("js_ReaScriptAPI extension is required for this script.", "Missing API", 0)
else
  Main()
end
-- end
reaper.defer(function () end)

Last edited by Edgemeal; 02-22-2019 at 01:28 PM. Reason: Add OS and API ver.
Edgemeal is offline   Reply With Quote
Old 02-21-2019, 04:52 PM   #248
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Basically I'm trying to append a folder name to reaper.GetResourcePath(), I've read on the forum to use a forward-slash ("/") because it works on MAC and Windows, but (here on Win7) when I use "/" for the initialFolder param the JS_API open and save dialogs don't open to the expected folder, but do work as expected if I use a backslash '/'. What am I doing wrong this time? Confused as usual.

Testing: Windows 7 / js_ReaScriptAPI v0.963 / REAPER v5.965

Code:
-- Make Reabank file from FX preset file

function GetFileNameOnly(path) 
   local p = path:reverse():find('[%/%\\]') -- file path end
   local e = path:reverse():find('[%.]') -- ext length
   return path:sub(-p + 1, string.len(path)-e)
end

function Main()
 -- select one preset file
  local initialFolder = reaper.GetResourcePath()..[[\presets]] -- ..'/presets' doesn't work!
  local initialFile = '*.ini'
  local extensionList = "Preset files (*.ini)\0*.ini\0\0"   
  local ret, filename = reaper.JS_Dialog_BrowseForOpenFiles("Select Preset File", initialFolder, initialFile, extensionList, false)
  if ret == 0 then return end
  -- get fx name from file name
  local fx_name = GetFileNameOnly(filename) 
  -- read selected preset file
  local index = 0
  local t = {}  
  local file = io.open(filename, "r")
  local data = file:read("*all") -- read the whole file.
  for line in data:gmatch('[^\r\n]+') do
    if string.find(line,'Name=') then
      line = tostring(index) ..' ' .. string.gsub(line,'Name=','')  
      index = index +1
      t[index]= line 
    end
  end
  file:close() 
  -- build reabank data
  local str = 
  [[
  // .reabank bank/program (patch) information
  // A bank entry lists the MSB, LSB, and bank name
  // for all the patches that follow, until the next bank entry.
  ]]..'\n'..'Bank 0 0 ' .. fx_name .. ' 001-' .. tostring(#t) .. '\n'  
  for i=1, #t do -- add preset names 
    str = str..'\n'..(t[i])
  end 
   -- get file path from user for reabank file
  initialFolder = reaper.GetResourcePath()..[[\Data]] -- ..'/Data' doesn't work!
  initialFile = fx_name .. ".reabank"
  extensionList = "ReaBank files (*.reabank)\0*.reabank\0\0"
  ret, filename = reaper.JS_Dialog_BrowseForSaveFile("Save As Reabank", initialFolder, initialFile, extensionList)
  if ret == 0 then return end
  -- write data to file
  file = io.open(filename, "w")
  file:write(str)
  file:close()
end -- function

-- begin
if not reaper.APIExists("JS_Localize") then
  reaper.MB("js_ReaScriptAPI extension is required for this script.", "Missing API", 0)
else
  Main()
end
-- end
reaper.defer(function () end)

Last edited by Edgemeal; 02-22-2019 at 01:28 PM. Reason: Add OS and API ver.
Edgemeal is offline   Reply With Quote
Old 02-22-2019, 12:31 PM   #249
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

I Googled the problem, and found that it is a known bug in Windows' file dialogs: unlike most other Windows functions, the file open and save dialogs do not understand forward slashes.

I will add a patch to the next update.

Another idiosyncrasy that bothers me when multiple files are selected, is that Windows doesn't include the backslash at the end of the folder string, whereas Linux does, and macOS just leaves the folder substring blank -- even though, according to documentation, all three are supposed to format their return strings exactly the same.

I will try to make these more consistent.
juliansader is offline   Reply With Quote
Old 02-22-2019, 01:14 PM   #250
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Thanks, thought I was going crazy.
Edgemeal is offline   Reply With Quote
Old 02-24-2019, 06:31 AM   #251
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,593
Default

Need a little help, what is equivalent for OSX?

Code:
track_window = reaper.JS_Window_Find("trackview", true) -- GET TRACK VIEW
OSX users are experiencing error when calling
Code:
track_window_dc = reaper.JS_GDI_GetWindowDC(track_window)
Sexan is online now   Reply With Quote
Old 02-24-2019, 08:10 AM   #252
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Child window titles are not valid cross-platform (nor are class names), but window IDs seem to be reliable.

You can use JS_Window_GetLongPtr(hwnd, "ID") to get the child window's ID on Windows, if you already have its hwnd.

Thereafter, in your public scripts, use that ID (converted to a number) and JS_Window_FindChildByID to get the window on any platform.

In the case of trackview, its ID seems to be 0x3E8, so the equivalent would be:
Code:
track_view = reaper.JS_Window_FindChildByID(reaper.GetMainHwnd(), 0x3E8)
juliansader is offline   Reply With Quote
Old 02-25-2019, 10:58 AM   #253
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

I'm just working on that function myself. If I can make this working, it will be part of the next iteration of the Ultraschall-API.

Tha lack of a title and classname on MacOS(and probably Linux) makes that stuff quite hard to code...
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-25-2019, 10:56 PM   #254
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

v0.970 uploaded:
* BrowseForOpenFiles: On Windows, returns folder with terminal backslash.
* All file dialogs: On Windows, accept forward slashes in initial folder.
* IsWindow function: Improved on Linux and macOS.
* New functions: Memory allocation and access.
* Deprecated function: StrToPtr.
* WindowMessage functions: Recognize ComboBox message names such as "CB_GETCURSEL".
juliansader is offline   Reply With Quote
Old 02-26-2019, 12:40 AM   #255
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by juliansader View Post
v0.970 uploaded:
REAPER 5.97 (on Win7_x64) is closing on me without any error now when running the script in post #252, it might run on first try then fail, or gets to where the save dialog should open but REAPER closes, changing backslash to forward slash made no difference, the open/save file dialogs seem to have a problem. I reverted back to 0.963 for now, opened and saved 7 preset files in a row no problem.

Last edited by Edgemeal; 02-26-2019 at 02:23 AM.
Edgemeal is offline   Reply With Quote
Old 02-26-2019, 02:09 AM   #256
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Drat, there was indeed a memory access bug. v0.971 uploaded, which should fix it. Thanks for testing so quickly!
juliansader is offline   Reply With Quote
Old 02-26-2019, 02:39 AM   #257
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

0.971 looking good!
Edgemeal is offline   Reply With Quote
Old 02-26-2019, 10:03 AM   #258
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Quote:
Originally Posted by Sexan View Post
Need a little help, what is equivalent for OSX?

Code:
track_window = reaper.JS_Window_Find("trackview", true) -- GET TRACK VIEW
OSX users are experiencing error when calling
Code:
track_window_dc = reaper.JS_GDI_GetWindowDC(track_window)
This is, what I came up with and will be part of the next Ultraschall-API-version. It is cross-platform.
It returns the HWND for the arrangeview(trackview) and the hwnd for the timeline.

You need to replace the line
local Count, Individual_values = ultraschall.CSV2IndividualLinesAsArray(list)
with something, that splits the returned list into an array with the individual adresses and a count of the number of adresses in list

The rest should work right away.

Code:
function GetHWND_ArrangeViewAndTimeLine()

  -- fantastic arrangeview- and timeline-hwnds and where to find them...
  -- by "J.K."Mespotine ;)

  -- preparation of variables
  local ARHWND, TLHWND, temphwnd
  
  -- if we haven't stored the adress of the arrangeviewhwnd yet, let's go find them.
  if reaper.GetExtState("ultraschall", "arrangehwnd")=="" then
    -- prepare some values we need
    local Start,Stop = reaper.BR_GetArrangeView(0)
    local Projectlength=reaper.GetProjectLength()

    -- get mainhwnd of Reaper and all of it's childhwnds
    local HWND=reaper.GetMainHwnd()    
    local retval, list = reaper.JS_Window_ListAllChild(HWND)    
    
    --Now, the magic happens
    
    
    -- [ Getting Arrangeview HWND] --
    
    -- split the hwnd-adresses into individual adresses
    local Count, Individual_values = ultraschall.CSV2IndividualLinesAsArray(list)
    
    
    -- get current scroll-state of all hwnds
    local ScrollState={}
    for i=1, Count do
      ScrollState[i]={}
      local temphwnd=reaper.JS_Window_HandleFromAddress(Individual_values[i])
    
      ScrollState[i]["retval"], ScrollState[i]["position"], ScrollState[i]["pageSize"], ScrollState[i]["min"], ScrollState[i]["max"], ScrollState[i]["trackPos"] = reaper.JS_Window_GetScrollInfo(temphwnd,"h")
      retval, ScrollState[i]["left"], ScrollState[i]["top"], ScrollState[i]["right"], ScrollState[i]["bottom"] = reaper.JS_Window_GetRect(temphwnd)
    end
    
    -- alter scrollstate
    reaper.BR_SetArrangeView(0,Start+100000,Stop+100000)
    
    -- check scrollstate of all hwnds for the one, whose scrollstate changed, as this is the arrange-view-hwnd
    for i=1, Count do
      temphwnd=reaper.JS_Window_HandleFromAddress(Individual_values[i])
      local retval, position, pageSize, min, max, trackPos = reaper.JS_Window_GetScrollInfo(temphwnd,"h")
      if position~=ScrollState[i]["position"] or 
         pageSize~=ScrollState[i]["pageSize"] or
         min~=ScrollState[i]["min"] or
         max~=ScrollState[i]["max"] or
         trackPos~=ScrollState[i]["trackPos"] then
        ARHWND=temphwnd 
        --[[print2(reaper.JS_Window_GetTitle(temphwnd), position, ScrollState[i]["position"], 
                                                    pageSize, ScrollState[i]["pageSize"],
                                                    min, ScrollState[i]["min"],
                                                    max, ScrollState[i]["max"],
                                                    trackPos, ScrollState[i]["trackPos"]
                                                    )--]]
        break
      end
    end

    -- in the unlikely case that I can't find a hwnd, return this error-message    
    if ARHWND==nil then ultraschall.AddErrorMessage("GetHWND_ArrangeViewAndTimeLine", "", 
          [[Couldn't find Arrangeview for some reason. Please report this to me as a bug and what you did to make this error happen!
  
  Please include in the bugreport your OS, the Reaper-version and the following information:
  ]]..Projectlength..", "..Start..", "..Stop..", "..reaper.GetHZoomLevel(), -1) return nil end
    
    -- reset arrangeview-scrolling to it's original state
    reaper.BR_SetArrangeView(0,Start,Stop)
    

    -- [ Getting Timeline HWND] --
    
    -- let's get the dimensions of the arrangeview-hwnd, as top, left and right-positions can be used
    -- to determine bottom, left, right of the timeline-hwnd
    local retval, left, top, right, bottom = reaper.JS_Window_GetRect(ARHWND)
    
    -- check all hwnds to find the one, that has right=right, left=left, bottom_timeline=top_arrangeview
    for i=1, Count do
      local temphwnd=reaper.JS_Window_HandleFromAddress(Individual_values[i])
      if ScrollState[i]["left"]==left and ScrollState[i]["right"]==right and ScrollState[i]["bottom"]==top then
        TLHWND=temphwnd 
        break
      end
    end
    
    -- store the adresses of the found HWNDs of Arrangeview and Timeline into an extstate for further use, to prevent useless
    -- scroll-state-altering of the Arrangeview(which could cause stuck Arrangeviews, when done permanently)
    reaper.SetExtState("ultraschall", "arrangehwnd", reaper.JS_Window_AddressFromHandle(ARHWND), false)
    reaper.SetExtState("ultraschall", "timelinehwnd", reaper.JS_Window_AddressFromHandle(TLHWND), false)
    ultraschall.ARHWND=ARHWND
    ultraschall.TLHWND=TLHWND
  else
    -- if the extstate already has stored the arrangeview-hwnd-address, just convert the one for arrangeview and timeline
    -- it into their handles and return them
    ARHWND=reaper.JS_Window_HandleFromAddress(reaper.GetExtState("ultraschall", "arrangehwnd"))
    TLHWND=reaper.JS_Window_HandleFromAddress(reaper.GetExtState("ultraschall", "timelinehwnd"))
  end  
  return ARHWND, TLHWND
end
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-28-2019, 04:12 AM   #259
Moy
Human being with feelings
 
Moy's Avatar
 
Join Date: Oct 2017
Location: China
Posts: 60
Default

These scripts are soooooooo creative and useful, thanks a lot!

@Edgemeal wrote a script to locate "Search" box in Media Explorer and said I should thank(donate) you, haha

So I'm wondering how can I donate your - since I didn't found a donation link yet.
Could you please post your Paypal, maybe?

-

Oh by the way, I'm curious about the way how you made the gifs in https://forum.cockos.com/showthread.php?t=176878

The keystroke display is interesting
__________________
Nice to meet REAPER.
My Chinese tutorials of RAEPER: https://zhuanlan.zhihu.com/reaper
Moy is offline   Reply With Quote
Old 02-28-2019, 06:23 AM   #260
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by Moy View Post
So I'm wondering how can I donate your - since I didn't found a donation link yet. Could you please post your Paypal, maybe?
Thanks a lot! It's http://www.paypal.me/juliansader.


Quote:
Originally Posted by Moy View Post
Oh by the way, I'm curious about the way how you made the gifs in https://forum.cockos.com/showthread.php?t=176878

The keystroke display is interesting
This was recorded on Linux with the Key-mon status monitor. (I've not been able to find any Windows app that is as good as Key-mon.)
juliansader is offline   Reply With Quote
Old 03-01-2019, 01:39 AM   #261
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by mespotine View Post
This is, what I came up with and will be part of the next Ultraschall-API-version. It is cross-platform.
It returns the HWND for the arrangeview(trackview) and the hwnd for the timeline.
Fortunately, I don't think such intricate code will be necessary. HWNDs of child windows such as trackview can be found with FindChildByID, and Justin recently confirmed that IDs are cross-platform reliable.
juliansader is offline   Reply With Quote
Old 03-02-2019, 07:43 PM   #262
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Shouldn't the File dialogs check the entered or selected filenames?
For example, If user enters a filename that doesn't exist for Open file the return should be zero.
And if entered filename already exists for Save dialog it should pop up an Overwrite Yes/No dialog, so that if user selects 'No' then return is zero.

Or maybe thats just the default in VS vb.net and I'm spoiled?
Edgemeal is offline   Reply With Quote
Old 03-04-2019, 03:54 AM   #263
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Quote:
Originally Posted by juliansader View Post
Fortunately, I don't think such intricate code will be necessary. HWNDs of child windows such as trackview can be found with FindChildByID, and Justin recently confirmed that IDs are cross-platform reliable.
Hmm..the question is now, how do you store the ID crossplatform.

Because, currently, I would need to get the ID using JS_Window_GetLongPtr which needs a HWND to work.
The ID is a userdata-object in Lua, so I can't store it in a string-variable or something like that, afaik.
But this would be needed to use JS_Window_FindChildByID...
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 03-04-2019, 05:11 AM   #264
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@Edgemeal
There is reaper.file_exists function to file path checking :P


How would you get media file section in media explorer peaks ? (MEPeaks is the ID but I don't know how to get the section ?) I would be interested in a new script for Inserting media file section in last touch track at mouse (or edit cursor if mouse is outside) position :P
X-Raym is offline   Reply With Quote
Old 03-04-2019, 05:45 AM   #265
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by Edgemeal View Post
Shouldn't the File dialogs check the entered or selected filenames?
For example, If user enters a filename that doesn't exist for Open file the return should be zero.
And if entered filename already exists for Save dialog it should pop up an Overwrite Yes/No dialog, so that if user selects 'No' then return is zero.
I will add this in the next update. (It will also make the Windows dialog more consistent with the Linux one.)
juliansader is offline   Reply With Quote
Old 03-04-2019, 05:58 AM   #266
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Quote:
Originally Posted by juliansader View Post
I will add this in the next update. (It will also make the Windows dialog more consistent with the Linux one.)
I would prefer this to be optional. I want to be able to do the checks in the background, if necessary for things in my API.
A simple boolean with default setting of check_for_existing_file=true would be sufficient, I guess.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 03-04-2019, 06:01 AM   #267
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by mespotine View Post
Because, currently, I would need to get the ID using JS_Window_GetLongPtr which needs a HWND to work.
The ID is actually a number, even though the function returns pointers. The pointer can be converted to a number using JS_Window_AddressFromHandle, or tonumber(tostring(ptr):match("%S+$"), 16).

I realize that it is awkward to return the ID as a pointer, but since the function can also return pointers (when asked for "WNDPROC" or "DLGPROC"), I'm not sure which return format would be better.

EDIT: Hmmm... perhaps the function should return *two* values, one a pointer, and the other the integer version. And I should also update the API help to make clear that the function can return pointers as well as integers.

Last edited by juliansader; 03-04-2019 at 06:12 AM.
juliansader is offline   Reply With Quote
Old 03-04-2019, 06:45 AM   #268
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Quote:
Originally Posted by juliansader View Post
The ID is actually a number, even though the function returns pointers. The pointer can be converted to a number using JS_Window_AddressFromHandle, or tonumber(tostring(ptr):match("%S+$"), 16).

I realize that it is awkward to return the ID as a pointer, but since the function can also return pointers (when asked for "WNDPROC" or "DLGPROC"), I'm not sure which return format would be better.

EDIT: Hmmm... perhaps the function should return *two* values, one a pointer, and the other the integer version. And I should also update the API help to make clear that the function can return pointers as well as integers.
Nice, that would solve all such issues with HWNDs
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 03-04-2019, 07:04 AM   #269
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by juliansader View Post
I will add this in the next update. (It will also make the Windows dialog more consistent with the Linux one.)
Awesome!
Was just looking at file dialogs in vb.net I see flags are set to true by default, .CheckFileExists, .CheckPathExists, .OverwritePrompt.
Like I said, I'm just spoiled!
Thanks!

EDIT
A couple more flags that wold come in handy.
.FilterIndex, get/set which file extension is used from the extension list.
.AddExtension, automatically add file extension if user omits it.

Last edited by Edgemeal; 03-04-2019 at 07:15 AM.
Edgemeal is offline   Reply With Quote
Old 03-04-2019, 09:21 AM   #270
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by X-Raym View Post
@Edgemeal
There is reaper.file_exists function to file path checking :P
Yes, but its more elegant when file dialog does it for you.
Quote:
How would you get media file section in media explorer peaks ? (MEPeaks is the ID but I don't know how to get the section ?) I would be interested in a new script for Inserting media file section in last touch track at mouse (or edit cursor if mouse is outside) position :P
Can't we already do that?, You make an area selection over the item in the MEpeaks area, right click and select Insert selected portion into project. Only drawback I see is it adds it to first selected track at edit cursor.
Edgemeal is offline   Reply With Quote
Old 03-04-2019, 09:27 AM   #271
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

Quote:
Only drawback I see is it adds it to first selected track at edit cursor.
And it requires Right click and navigating into menu :P Weird that this is avaible as keyboard shortcut.


Maybe it would be better to open a Feature request.
X-Raym is offline   Reply With Quote
Old 03-04-2019, 09:33 AM   #272
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@Edgemeal
You make me close deeper and thx to reapaccessibility.com I found that if I set Options: Default action inserts media in Media Explorer Action context, then pressing enter WILL import the item section at edit cur pos on first selected track...


I can go with it for now (but I wonder if there was a simpler way to do that).
X-Raym is offline   Reply With Quote
Old 03-04-2019, 11:13 AM   #273
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by X-Raym View Post
How would you get media file section in media explorer peaks ? (MEPeaks is the ID but I don't know how to get the section ?)
I do not quite understand what you mean by "media file section" and "media explorer peaks" -- could perhaps upload a screenshot?
juliansader is offline   Reply With Quote
Old 03-04-2019, 03:53 PM   #274
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@julian


The problem is mostly solved with the Enter key, I can go with that :P But the idea was:

X-Raym is offline   Reply With Quote
Old 03-06-2019, 02:08 PM   #275
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,171
Default

Hi Julian,

I'm trying to use the JS_Dialog_BrowseForSaveFile function - and it has been working fine on my 2 laptops.

But when I transferred my script over to my studio PC - it returns -1 without opening the dialog.

I've checked and double-checked the default folder path being passed - and that's fine (I have even tried substituting any / with \ (am on Win10 on all my machines)).

Really odd - do you have any idea what may be causing this. Save as dialogs work elsewhere on my system.

Do you know what dll the call you are using resides in so I can check that? EDIT - sorry - you're probably using the lib file not the dll.

the code I'm using is :
Code:
local retval, fileName = reaper.JS_Dialog_BrowseForSaveFile('Save Strip Set As...', path, '', "stripset files (.stripset)\0*.stripset\0\0")
Like I said - this works fine on my 2 laptops - just not my main studio computer.

Thanks for any help.
Leon.


EDIT:

Ok - I got it working for 5 seconds before it crashed and took out Reaper by adding parameters 5 and 6 - 5 I passed as empty string (not big pointer - probably the reason of the crash) - and 6 I set as 33000

So - does that shed any light on why it's not working properly on my system.

Is there a way to set up a big pointer to pass in (off to research now)...?

EDIT2:

Think I got it sorted - used 32000 doesn't seem to crash reaper - (not 33000)

Any ideas why it doesn't work without me adding these 2 extra parameters?

EDIT3:

Spoke too soon - still freezing/crashing reaper. :/

So adding parameters 5+6 (as "", 32000) does get the dialog open - but it kills reaper once I close the dialog.

Any ideas at all what to do?
__________________
Projects - Reascripts - Lua:
Smart Knobs 2 | LBX Stripper | LBX Floating FX Positioner
Donate via Paypal | LBX Tools Website

Last edited by lb0; 03-06-2019 at 02:45 PM.
lb0 is offline   Reply With Quote
Old 03-06-2019, 03:26 PM   #276
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by lb0 View Post
Like I said - this works fine on my 2 laptops - just not my main studio computer.
Strange... Are you using different versions of REAPER on the three computers?


Quote:
Think I got it sorted - used 32000 doesn't seem to crash reaper - (not 33000)...Spoke too soon - still freezing/crashing reaper. :/
By default in Lua, NeedBig strings are supposed to provide 32768 bytes of memory, so the line "if (fileNameOutNeedBig_sz < 32000) return -1;" is intended to check that a script didn't decrease this memory space, if the optional parameters 5 and 6 are explicitly provided.

I wonder if something changed in a recent version of REAPER, causing NeedBig strings to provide smaller strings by default, and also to limit parameter 6?

But no worries -- if anything changed under the hood in REAPER, it will be easy to fix the function.

Last edited by juliansader; 03-06-2019 at 03:31 PM.
juliansader is offline   Reply With Quote
Old 03-06-2019, 03:57 PM   #277
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,171
Default

Quote:
Originally Posted by juliansader View Post
Strange... Are you using different versions of REAPER on the three computers?



By default in Lua, NeedBig strings are supposed to provide 32768 bytes of memory, so the line "if (fileNameOutNeedBig_sz < 32000) return -1;" is intended to check that a script didn't decrease this memory space, if the optional parameters 5 and 6 are explicitly provided.

I wonder if something changed in a recent version of REAPER, causing NeedBig strings to provide smaller strings by default, and also to limit parameter 6?

But no worries -- if anything changed under the hood in REAPER, it will be easy to fix the function.
Thanks for the quick reply

It's entirely possible I'm running slightly different versions of Reaper.

I'm running 5.962dev1117 on this laptop.

I'll check soon on the studio machine and try maybe updating/downgrading the studio machine to see if it makes a difference.

I tried out your Load dialog and that one works fine on the studio pc.

I guess I'm just puzzled why I'm needing to pass (the hidden) parameters 5 & 6 from Lua - when this is not needed on the laptops.

Will check my versions and report back.

Thanks again,

EDIT:

Ok - sorry - my fault. Seems I was running an older dev release (5.961dev1103 or similar) on my studio PC.

Updated to dev1117 and it all works fine Mas well update and try the latest now...

Thanks again for your help - didn't cross my mind to look at Reaper version!! Noted for the future!
__________________
Projects - Reascripts - Lua:
Smart Knobs 2 | LBX Stripper | LBX Floating FX Positioner
Donate via Paypal | LBX Tools Website

Last edited by lb0; 03-06-2019 at 04:06 PM.
lb0 is offline   Reply With Quote
Old 03-08-2019, 06:28 AM   #278
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

@juliansader

Would it be possible for you to expose the following C-only-functions to ReaScript as well?

PlayPreview
PlayPreviewEx
PlayTrackPreview
PlayTrackPreview2
PlayTrackPreview2Ex

StopPreview
StopTrackPreview
StopTrackPreview2

Currently, previewing an audiofile is only possible, if it's part of the current project(using SWS-actions), though the API-supports previewing audiofiles not in the project as well, if I understood it correctly.

And I would love to have a function, that returns the attributes of a file, like creation-time, last change time, size, etc. The stuff, you could get using ls on Linux or dir on Windows, but without having to go through the console, as this is too slow.
I have tons of scripts(mostly reverse-engineering stuff to document Reaper-things), that need to reread a file for display or checks, but I would love to do that only, if the file has changed, without having to read it in full to check for differences. Especially with large-files this would be a performance-saver.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 03-08-2019, 10:00 AM   #279
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,171
Default

Another quick Q from me

I've been playing around with the GDI stuff drawing directly to a window.

This is working great. But using FillRect - I can set the fill colour using JS_GDI_CreateFillBrush and JS_GDI_SelectObject - but can't work out how to change the border colour (which is always black).

Is this possible? Thanks,
__________________
Projects - Reascripts - Lua:
Smart Knobs 2 | LBX Stripper | LBX Floating FX Positioner
Donate via Paypal | LBX Tools Website
lb0 is offline   Reply With Quote
Old 03-08-2019, 10:54 AM   #280
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

IIRC, the selected GDI "pen" is used for the border.

Warning: I haven't been able to get GDI to work properly in Linux, even though it is supposed to have been implemented.
juliansader 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 08:47 AM.


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