Old 03-08-2019, 11:38 AM   #281
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,175
Default

Quote:
Originally Posted by juliansader View Post
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.
Thanks - will try that.

I'm only using the GDI stuff to display progress bars at the moment - as it seems to handle better than default graphics options when a lot of stuff is going on in the background.

Unfortunately - it still freezes up completely in the worst cases (until the processing is finished) - but definitely seems slightly better (as in - at least displays the progress bar when sometimes using the default graphics options it doesn't show up at all even though I'm writing directly to gfx.dest -1 and calling gfx.update() ).

It used to work better - but something changed in an update and I find using the native gfx functions for instant graphics updates (ie. out of the standard graphics drawing routine) problematic).
__________________
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, 01:21 PM   #282
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
Default

Quote:
Originally Posted by Edgemeal View Post
I reverted back to 0.963 for now, opened and saved 7 preset files in a row no problem.
Can you post the final code for this? I tried running what you posted earlier, and didn't get anything... I am running .971, and just updated reaper (win64) today...
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote
Old 03-08-2019, 01:37 PM   #283
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
Default

Quote:
Originally Posted by Edgemeal View Post
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)
Oops, I guess I copied an older version, this one does run fine. In the first dialog I selected the ini associated with guitar rig, but the reabank that got created only has 2 presets in it. Well, my ini only has 2 presets, but I thought you were reading the VST presets exposed in the dropdown menu (87 in this case). Is this still not possible? I already have means to parse the .ini for preset names, I was hoping you'd figured out how to get the vst presets from the combobox in the vst window... is that not possible with this API?
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote
Old 03-08-2019, 02:23 PM   #284
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

Quote:
Originally Posted by woodslanding View Post
, but I thought you were reading the VST presets exposed in the dropdown menu (87 in this case). Is this still not possible?
See if this works, it first searches the list for where 'User Presets', starts and ends, so if same English text it should work,...

EDIT When I use midi PC message to select say 3rd user preset from this reabank file and FX also has 'VST built-in' presets then the FX uses the 3rd built-in preset. But ReaControlMIDI works fine.

Code:
-- Testing: Windows 7(US English) / js_ReaScriptAPI v0.971 / REAPER 5.972+dev0308a

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

function pad_zeros(str, places)
  if string.len(str) < places then
    return string.rep('0', places - string.len(str))..str
  else
    return str
  end
end

function Main()
  -- Find VST floating FX window
  local title = reaper.JS_Localize("VST: ".. fx_name, "common") 
  local hwnd = reaper.JS_Window_Find(title, false)
  
  -- check if window found
  if not hwnd then 
    reaper.MB("Please open FX in a floating plugin window!", "Window not found", 0)
    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)

  -- get indexes for start/end of user preset names --
  local list_start = -1
  local list_end = itemCount
  for i = 0, itemCount-1 do
    reaper.JS_WindowMessage_Send(presets, "CB_SETCURSEL", i, 0,0,0)
    local name = reaper.JS_Window_GetTitle(presets,"")
    if name == '----  User Presets (.rpl)  ----' then
      list_start = i+1
    elseif name == '----  VST built-in programs  ----' then
      list_end = i
      break
    end
  end

  -- check if user presets found
  if list_start == -1 then
    reaper.MB("No user presets found!", "No User Data", 0)
    return
  end
 
  -- 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-'..pad_zeros(tostring(list_end-list_start),3)..'\n'

  -- add user preset names -- 
  for i = list_start, list_end-1 do
    reaper.JS_WindowMessage_Send(presets, "CB_SETCURSEL", i, 0,0,0)
    str = str..'\n' .. tostring(i-list_start) ..' '..reaper.JS_Window_GetTitle(presets,"")
  end

 -- restore preset 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)
  -- write data to file
  if ret == 1 then
    local f = io.open(filename, "w")
    f:write(str)
    f:close()
  end
end -- end main 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)
Updated (again)
If no user presets found, notify and exit.
If fx floating window not found, notify and exit.
Fix, if 'VST built-in programs' not found list was empty.
Pad list count with zeros for reabank file.

Last edited by Edgemeal; 03-09-2019 at 11:57 PM.
Edgemeal is offline   Reply With Quote
Old 03-08-2019, 04:35 PM   #285
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

v0.972 uploaded:
* WindowsOS: Enable confirmation dialogs for file functions.
* macOS: Fix GetClientRect screen coordinates.
* GDI: macOS and Linux use same color format as WindowsOS.
* New: Window_GetLong, MonitorFromRect, GetClientSize.

WARNING!

I recently realized that all functions that return screen coordinates -- js_ReaScriptAPI functions as well as native functions such as GetMousePosition -- work differently on macOS than on Linux and Windows:

* On macOS, screen coordinates are calculated relative to the *bottom* left corner of the screen, and the positive Y-axis points upwards

* On Linux and Windows, screen coordinates are calculated relative to the *upper* left corner, and the positive Y-axis points downwards.

On all platforms, client coordinates are calculated relative to the upper left corner of the client area.

It is therefore prudent to convert screen coordinates to client coordinates, using ScreenToClient, immediately after getting the screen coordinates.
juliansader is offline   Reply With Quote
Old 03-08-2019, 04:59 PM   #286
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

Quote:
Originally Posted by juliansader View Post
v0.972 uploaded:
* WindowsOS: Enable confirmation dialogs for file functions.
It works!
Thanks!
Edgemeal is offline   Reply With Quote
Old 03-08-2019, 05:49 PM   #287
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,175
Default

Quote:
Originally Posted by juliansader View Post
v0.972 uploaded:
* WindowsOS: Enable confirmation dialogs for file functions.
Could I just ask - is this like when saving a file - if it exists it asks for confirmation - and the result returned from the function reflects this? (Sorry - not got time to check this just now).

If so - is it always active? Only I've added my own confirmations in my script - so want to know if I need to remove my own dialog?

Do Mac and Linux have the same dialogs?

If it's nothing to do with this - just ignore me
__________________
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, 06:12 PM   #288
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by lb0 View Post
Could I just ask - is this like when saving a file - if it exists it asks for confirmation - and the result returned from the function reflects this? (Sorry - not got time to check this just now).
Save file: asks for overwrite confirmation if the file already exists.
Open file: asks for create confirmation if the file doesn't already exist.


Quote:
If so - is it always active?
Yes. I tried to find a way to add a boolean parameter that is optional, so that existing scripts won't be broken, but couldn't find a way.


Quote:
Do Mac and Linux have the same dialogs?
For saving and overwriting, yes. It seems that Linux and Mac don't give the option to type in a name and create a new file via the open file dialog. (I'm no Linux and Mac expert though, so I may be overlooking some option somewhere.)

Last edited by juliansader; 03-08-2019 at 06:22 PM.
juliansader is offline   Reply With Quote
Old 03-08-2019, 06:24 PM   #289
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Come to think of it... would it actually be better in Windows if Save has an overwrite confirmation popup, but Open simply prevents creating a new file?
juliansader is offline   Reply With Quote
Old 03-08-2019, 08:13 PM   #290
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

I was a little surprised when Open File asked me if I wanted to create a file when I typed 'gibberish' (file that didn't exist), It just seems weird to even have an option to create a file when your supposed to be selecting a file to open, but I guess it has its uses.

in vb.net using all defaults I get,..

I like that better.

Last edited by Edgemeal; 03-09-2019 at 01:41 PM. Reason: $0.02
Edgemeal is offline   Reply With Quote
Old 03-09-2019, 03:18 PM   #291
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,175
Default

Quote:
Originally Posted by juliansader View Post
Come to think of it... would it actually be better in Windows if Save has an overwrite confirmation popup, but Open simply prevents creating a new file?
For me personally, I wouldn't require the create new file option - as I'd be requesting some data file that already existed (and a newly created file wouldn't be any use). But I'd usually have code in place that would discard the created file anyway. I too prefer Edgemeal's 'File not found' suggestion.

In windows open file dialog - it's usually possible to create a file anyway using the right-click menu within the dialog if necessary (don't know about other OS's though).

Nice to have the overwrite option built in when saving a file though - saves me coding it into a script. As long as the different OS dialogs have the same overwrite confirmation of course (like you confirmed). If they didn't - it would probably be best to have them react in the same way if poss so I need less OS specific code in the script.
__________________
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-12-2019, 03:20 AM   #292
reapero
Human being with feelings
 
Join Date: Aug 2011
Posts: 522
Default

Hey guys,

I got scripts working on a PC that dont work on a Mac (i tried to make a portable version in the mac if that matters)

Actually the scripts work but i think its more about the functions to open files/folders

I got this:

Code:
retval, fileNames = reaper.JS_Dialog_BrowseForOpenFiles( "Select your wav files", "C:\\", _, _, true )
On the mac the caption doesnt even show up and the button to select the files ("Open") is greyed out, unavailable.

Any clue?
reapero is offline   Reply With Quote
Old 03-13-2019, 12:46 AM   #293
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by reapero View Post
On the mac the caption doesnt even show up and the button to select the files ("Open") is greyed out, unavailable.
Since El Capitan, Apple has removed custom captions from standard File Open dialogs. It is possible to "hack" captions by displaying the custom title as a message on top of the dialog, but Cockos's WDL/swell hasn't implemented this:


* macOS file open dialogs don't provide a dropdown list for the extension filter -- instead, all extensions in the list are enabled

* the "Open" button is only enabled once a file (with an acceptable extension) is selected.

Last edited by juliansader; 03-13-2019 at 01:50 AM.
juliansader is offline   Reply With Quote
Old 03-13-2019, 07:57 AM   #294
reapero
Human being with feelings
 
Join Date: Aug 2011
Posts: 522
Default

Thank you Julian!

Another thing not working on the mac: to separate multiple file names being selected i used this code:

Code:
retval, fileNames = reaper.JS_Dialog_BrowseForOpenFiles( "Select your wav files", "C:\\", _, _, true )

t = {} --add names to table
for file in fileNames:gmatch("[^\0]+") do
    t[#t+1] = file
end

Turns out mac uses "/" instead of "" so now i dont have the filenames in the table anymore. I think i read you guys talking about it, Edgemeal suggested to use "/" so i changed it to

Code:
for file in fileNames:gmatch("[^/0]+") do
but unfortunately it doesnt work on windows.

So is there any workaround for this?
reapero is offline   Reply With Quote
Old 03-13-2019, 09:31 AM   #295
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

The "\0" in gmatch should always use a backslash \, since the backslash is the "escape character" and the "\0" pair is simply a way for humans to type a character byte with value 0.

The first example code that you posted should work, except that you should also concatenate the folder path (if any) to each the file names. Here are two examples that should work on all platforms:
Code:
OK, files = reaper.JS_Dialog_BrowseForOpenFiles("", "", "", "", true)

t = {}
if not files:match("\0") then -- single file selected?
    t[1] = files
else -- multiple files selected
    folder = files:match("^[^\0]*") -- if macOS, may be empty string, so use *
    for file in files:gmatch("\0([^\0]+)") do
        t[#t+1] = folder .. file
    end
end

d = {}
for file in files:gmatch("[^\0]*") do -- * instead of + to capture empty substrings
    d[#d+1] = file
end
if #d > 1 then -- multiple files?
    local folder = table.remove(d, 1) -- may be empty, in case of macOS
    for f = 1, #d do
        d[f] = folder .. d[f]
    end
end

Last edited by juliansader; 03-15-2019 at 04:45 AM.
juliansader is offline   Reply With Quote
Old 03-13-2019, 05:50 PM   #296
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

Any reason this script wouldn't work on Mac?

Mac user says it doesn't work as expected,
https://forum.cockos.com/showpost.ph...14&postcount=5

Thanks.
Edgemeal is offline   Reply With Quote
Old 03-14-2019, 04:28 AM   #297
reapero
Human being with feelings
 
Join Date: Aug 2011
Posts: 522
Default

Quote:
Originally Posted by juliansader View Post

The first example code that you posted should work, except that you should also concatenate the folder path (if any) to each the file names.
It just doesnt work the same on mac and pc. I paste the code here again:

Code:
retval, fileNames = reaper.JS_Dialog_BrowseForOpenFiles( "Select your wav files", "C:\\", _, _, true )

t = {} --add names to table
for file in fileNames:gmatch("[^\0]+") do
    t[#t+1] = file
end
If i select 2 files, this is the output from the table in both platforms:

WINDOWS:
t[1] = C:\ (the path)
t[2] = skull_damage_00.wav (the name of the first file)

MAC:
t[1] = /Users/me/Downloads/skull_damage_00.wav (full path for first file)
t[2] = /Users/me/Downloads/skull_damage_01.wav (full path for second file)

Is there something i am missing?

I am interested in the names without the path, since i did the script on a pc and further string manipulation is done afterwards based on just the file names(table values). So, ideally, i should have the same table on the mac that i get on the pc.

Please dont tell me i have to re write the whole script...
reapero is offline   Reply With Quote
Old 03-14-2019, 06:06 AM   #298
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,629
Default

Quote:
Originally Posted by Edgemeal View Post
Any reason this script wouldn't work on Mac?

Mac user says it doesn't work as expected,
https://forum.cockos.com/showpost.ph...14&postcount=5

Thanks.
Which version of the JS-extension is installed? Earlier versions had an issue with Window_Find().

You should also do some checks, like if there are multiple windows open with the same name, maybe checking, if the HWND has certain childHWNDs to separate it from others with the same name who aren't FXWindows.
If there's a gfx-window open with the same name, you run into trouble.
You can make a debug-version that displays, which window is found so the user can report, what is found and what not.
__________________
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-14-2019, 09:04 AM   #299
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

Quote:
Originally Posted by mespotine View Post
Which version of the JS-extension is installed? Earlier versions had an issue with Window_Find().
Ya very possible.
Quote:
You should also do some checks, like if there are multiple windows open with the same name, maybe checking, if the HWND has certain childHWNDs to separate it from others with the same name who aren't FXWindows.
Came up with this for now,
https://raw.githubusercontent.com/Ed...Monitoring.lua


Thanks
Edgemeal is offline   Reply With Quote
Old 03-14-2019, 10:04 AM   #300
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by Edgemeal View Post
Any reason this script wouldn't work on Mac?

Mac user says it doesn't work as expected,
[url]https://forum.cockos.com/showpost.php?p=2107514&postcount=5[/url
I can't remember any issues with the Find functions, but I think the problem lies with the WM_CLOSE message. Windows are not forced to obey WM_CLOSE, but JS_Window_Destroy should work, even for docked windows.
juliansader is offline   Reply With Quote
Old 03-14-2019, 10:34 AM   #301
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by reapero View Post
If i select 2 files, this is the output from the table in both platforms:

WINDOWS:
t[1] = C:\ (the path)
t[2] = skull_damage_00.wav (the name of the first file)

MAC:
t[1] = /Users/me/Downloads/skull_damage_00.wav (full path for first file)
t[2] = /Users/me/Downloads/skull_damage_01.wav (full path for second file)
Is the second file not returned on WindowsOS?

macOS sometimes doesn't return the folder separately, and the first substring will then be empty. If you use gmatch("[^\0]*"), i.e. with * instead of +, you will capture the first substring, even if it's empty.

In a future version, I can perhaps add some C++ code to check whether the folder is returned separately.

To extract the file name, you can use
Code:
t[#t+1] = file:match("[^/]+$")
juliansader is offline   Reply With Quote
Old 03-14-2019, 02:41 PM   #302
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

Quote:
Originally Posted by juliansader View Post
I can't remember any issues with the Find functions, but I think the problem lies with the WM_CLOSE message. Windows are not forced to obey WM_CLOSE, but JS_Window_Destroy should work, even for docked windows.
Hmmm, I tried "WM_DESTROY" (Win7), its not good, when fx monitor is docked and in view and a destroy msg is sent to then the docker doesn't update correctly and the fx monitor appears as if it is drawn over all the tabs! REAPER don't like it thats for sure!

Edit, And when fx monitor window is not docked sending destroy msg doesn't seem to do anything except make it act weird, REAPER must be looking for WM_CLOSE msgs or something.

Maybe best I just mark the script as Windows Only. ?

Last edited by Edgemeal; 03-14-2019 at 03:08 PM.
Edgemeal is offline   Reply With Quote
Old 03-14-2019, 03:04 PM   #303
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

I suspect docked windows will encounter the same problems in Windows. As discussed by yourself and others in Any idea how to resize dockers through scripts?, nobody seems to know yet how to handle REAPER's dockers and docked windows.

The native API function DockWindowRemove doesn't seem to work properly either.

Perhaps it's time to ask Justin and Schwa directly? (Perhaps via askjf.com.) Or we can try to check which WM_USER messages are sent to the docker or the main window when a docked window is closed via the menu or the x button.
juliansader is offline   Reply With Quote
Old 03-14-2019, 04:56 PM   #304
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

MAC user says the window doesn't close even when not docked, so can only guess WM_CLOSE doesn't work on MAC?

Quote:
When fxm is undocked, it opens the window but does not close in a next script run
I don't have a MAC so no way to test.
Edgemeal is offline   Reply With Quote
Old 03-14-2019, 05:22 PM   #305
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

I tested JS_Window_Destroy on Windows, Linux and OSX High Sierra, and it seems to work fine: the docked window is destroyed, its contents are removed, and it can be re-opened again without problems.

JS_Window_Destroy seems to do a lot more than just send WM_DESTROY:
Quote:
Destroys the specified window. The function sends WM_DESTROY and WM_NCDESTROY messages to the window to deactivate it and remove the keyboard focus from it. The function also destroys the window's menu, flushes the thread message queue, destroys timers, removes clipboard ownership, and breaks the clipboard viewer chain (if the window is at the top of the viewer chain).

If the specified window is a parent or owner window, DestroyWindow automatically destroys the associated child or owned windows when it destroys the parent or owner window. The function first destroys child or owned windows, and then it destroys the parent or owner window.

DestroyWindow also destroys modeless dialog boxes created by the CreateDialog function.

Last edited by juliansader; 03-14-2019 at 05:28 PM.
juliansader is offline   Reply With Quote
Old 03-14-2019, 11:40 PM   #306
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

I tried closing FX monitor window on MAC (virtualbox),
Neither WM_CLOSE or WM_SYSCOMMAND,SC_CLOSE do anything, and sending WM_DESTROY basically had same effect as in Windows, the fx monitor window still there but no longer responds to mouse, keys, etc,. Was fun to play with MAC OS though, ok not really, I hated it!

Have fun!
Edgemeal is offline   Reply With Quote
Old 03-15-2019, 12:02 AM   #307
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Did JS_Window_Destroy work fine?
juliansader is offline   Reply With Quote
Old 03-15-2019, 12:33 AM   #308
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

Quote:
Originally Posted by juliansader View Post
Did JS_Window_Destroy work fine?
I didn't even know about that one!

Yes, JS_Window_Destroy seems to work OK for closing the window, tried on Windows 7 and that virtual MacOS 10.12.

Cheers!
Edgemeal is offline   Reply With Quote
Old 03-15-2019, 02:22 AM   #309
reapero
Human being with feelings
 
Join Date: Aug 2011
Posts: 522
Default

Quote:
Originally Posted by juliansader View Post
Is the second file not returned on WindowsOS?
It is, on t[3], since the first key value corresponds to the path.

Quote:
macOS sometimes doesn't return the folder separately, and the first substring will then be empty. If you use gmatch("[^\0]*"), i.e. with * instead of +, you will capture the first substring, even if it's empty.
That kinda worked. I have now in MAC:

t[1] = (empty value)
t[2] = /Users/me/Downloads/skull_damage_00.wav (first selected file)
t[3] = /Users/me/Downloads/skull_damage_01.wav (second file)

Quote:
To extract the file name, you can use
Code:
t[#t+1] = file:match("[^/]+$")
Now if i do that i lose the first empty value on the table and get

t[1] = skull_damage_00.wav
t[2] = skull_damage_01.wav


So, is there any possible way for me to end up with the same table i did on the PC? This:

t[1] = path
t[2] = skull_damage_00.wav (the name of the first file)
t[3] = skull_damage_01.wav (the name of the second file)


Or should i already consider using conditionals based on OS? Pretty lost here
reapero is offline   Reply With Quote
Old 03-15-2019, 08:42 AM   #310
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by reapero View Post
Or should i already consider using conditionals based on OS? Pretty lost here
There are two conditionals that you should consider:

1) If only one file was selected, the folder is not returned separately, and the entire path with file name is returned as a single string.

2) On macOS, the folder is sometimes (always?) not returned separately. (BTW, I'm not sure why -- is it a bug, or can a user select files from more than one folder?)


Quote:
So, is there any possible way for me to end up with the same table i did on the PC? This:
Sure, simply extract the folder path, store it in t[1] and remove it from all the other entries:

Code:
t = {}
for file in list:gmatch("[^\0]*") do
    t[#t+1] = file
end
if #t > 1 and t[1] == "" then -- macOS multiple files?
    t[1] = t[2]:match("^.*/") or "" -- folder path
    for i = 2, #t do
        local filename = t[i]:match("[^/]+$")
        if t[i] == t[1] .. filename then -- check that each entry consists of folder..filename
            t[i] = filename
        else
            -- Error: not all files from same folder!
        end
    end
end
juliansader is offline   Reply With Quote
Old 03-15-2019, 06:16 PM   #311
Breeder
Human being with feelings
 
Breeder's Avatar
 
Join Date: Nov 2010
Posts: 2,436
Default

I'm seriously too short on time for any code related stuff to try and do this but maybe some kind soul finds it useful and wants to share with the community:

Take a screenshot of a project (or maybe just the arrange and mixer window - alt+prtscreen type...maybe all 3...screenshot of the screen, arrange and mixer...that would enough information for later overview), save it in the project audio folder and import into media bay (so it doesn't get deleted on project cleanup)

Is it even possible using js_ extension?

The more I work, the more projects get heavier and slower to load so this would be a lifesaver. Run it when saving the project (if it exists create a backup like .rpp files get backups on saving) and have an instant overview of what is what.

If a donation could speed this up, pm me with the amount
Breeder is offline   Reply With Quote
Old 03-18-2019, 02:50 PM   #312
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,629
Default

Screenshot should be possible, but saving it as a file could be a thing.
There's only a LoadPNG-Lice-function, but not a SavePNG-one.

This would be awesome to have, for even more things than your usecase.
__________________
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-19-2019, 03:05 AM   #313
reapero
Human being with feelings
 
Join Date: Aug 2011
Posts: 522
Default

Quote:
Originally Posted by juliansader View Post

Sure, simply extract the folder path, store it in t[1] and remove it from all the other entries:
Damn..you make it look easy

But seriously, string manipulation in lua with all of these special characters, patterns and weird expressions..isnt this complicated if you compare it to, lets say, python? I am asking this from the most pure ignorance, so no pun intended.


Now i found another problem: in order to create files in the folder i extracted earlier, i have to manually add a backslash(\) character at the end in Windows -not included in the path. On Mac it seems that this is a slash(/) and its already included in the path.

Any way to deal with this besides using reaper.GetOS() to do some logic and write different code for each platform?

Thanks a lot!
reapero is offline   Reply With Quote
Old 03-19-2019, 10:30 AM   #314
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,629
Default

Quote:
Originally Posted by reapero View Post
Damn..you make it look easy

But seriously, string manipulation in lua with all of these special characters, patterns and weird expressions..isnt this complicated if you compare it to, lets say, python? I am asking this from the most pure ignorance, so no pun intended.


Now i found another problem: in order to create files in the folder i extracted earlier, i have to manually add a backslash(\) character at the end in Windows -not included in the path. On Mac it seems that this is a slash(/) and its already included in the path.

Any way to deal with this besides using reaper.GetOS() to do some logic and write different code for each platform?

Thanks a lot!
If you code in Lua, you can use my Ultraschall-API, which holds the function:

https://mespotin.uber.space/Ultrasch...seForOpenFiles

That does it for you.
__________________
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-19-2019, 10:32 AM   #315
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,629
Default

BTW, is there a chance to get the current check-state of a checkbox-hwnd or radio-buttons?
And is there already some kind of a list of the useable ChildIDs in Reaper? If not, I will create one.
__________________
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-19-2019, 11:04 AM   #316
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

Quote:
Originally Posted by mespotine View Post
BTW, is there a chance to get the current check-state of a checkbox-hwnd or radio-buttons?
BM_GETCHECK works in Windows.

Code:
  ret = reaper.JS_WindowMessage_Send(hwnd, "BM_GETCHECK", 0,0,0,0)
-- 1 = CHECKED, 0 = NOT CHECKED

Last edited by Edgemeal; 08-21-2023 at 11:04 AM. Reason: remove dead link
Edgemeal is offline   Reply With Quote
Old 03-19-2019, 03:05 PM   #317
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by reapero View Post
Now i found another problem: in order to create files in the folder i extracted earlier, i have to manually add a backslash(\) character at the end in Windows -not included in the path. On Mac it seems that this is a slash(/) and its already included in the path.
Since v0.970, BrowseForOpenFiles on Windows should return a folder path with backslash at the end, if multiple files were selected (similar to macOS and Linux, which return paths ending with forward slash). If it doesn't work, please let me know.
juliansader is offline   Reply With Quote
Old 03-19-2019, 03:14 PM   #318
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Screenshot should be possible, but saving it as a file could be a thing.
There's only a LoadPNG-Lice-function, but not a SavePNG-one.
I will see if I can add functions to save image files in the next version.


Quote:
Originally Posted by Breeder View Post
Take a screenshot of a project (or maybe just the arrange and mixer window - alt+prtscreen type...maybe all 3...screenshot of the screen, arrange and mixer...that would enough information for later overview), save it in the project audio folder and import into media bay (so it doesn't get deleted on project cleanup)
Is it currently possible to import image files into the media bay?
juliansader is offline   Reply With Quote
Old 03-20-2019, 05:50 AM   #319
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,175
Default

Quote:
Originally Posted by juliansader View Post
I will see if I can add functions to save image files in the next version.
This would be amazing!! Something I've wanted for some time.
__________________
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-20-2019, 10:15 AM   #320
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,629
Default

Quote:
Originally Posted by Edgemeal View Post
BM_GETCHECK works in Windows.

Basically what I use for checkbox and radiobuttion in my MIDI Quantize & Dynamic Split presets savers,
Code:
  ret = reaper.JS_WindowMessage_Send(hwnd, "BM_GETCHECK", 0,0,0,0)
-- 1 = CHECKED, 0 = NOT CHECKED
Big big thanks


@juliansader
I missed, that you answered me on my MouseState-problem. Thanks, will look into that
__________________
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
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 01:36 PM.


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