Old 12-02-2014, 11:31 AM   #1
Lawrence
Human being with feelings
 
Join Date: Mar 2007
Posts: 21,502
Default Javascript

I ask here because you guys are talented. Here's what I need to do...

1. Javascript files A, B, and C are external to my Win application.
2. I need to fire a function in file B from my external application.

Possible? To make an entry point into an external JS file and fire a JS function as if it was called from the script collection?

Thanks for any advice.
Lawrence is offline   Reply With Quote
Old 12-02-2014, 12:32 PM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,929
Default

It's "probably" possible but it would depend on how your main application has been written. With what language, what frameworks you have at your disposal etc...(By the way, can there really be some so awesome function you are prepared to involve Javascript to execute it...? Or is the function going to be something user written or so...?)
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
http://xenakios.wordpress.com/
Xenakios is offline   Reply With Quote
Old 12-02-2014, 12:45 PM   #3
Lawrence
Human being with feelings
 
Join Date: Mar 2007
Posts: 21,502
Default

The commands I'm trying to get to already fire directly from a JS function so if I could inject into that, call that function directly, externally, it would remove a large layer of coding to do the same thing, that would then be unnecessary. I'm using this code below to send formatted keyboard messages to an app, and it works fine, as long as the keycode is properly formatted...

Code:
 
 ' Convert qwerty letters to their keycodes
        Dim o As Object = kc.ConvertFromString(Key) 'last arry item  
        keyCode = CType(o, Keys)


' If modifier is required, use these.  May have 3 modifiers total
        If KeyMods(0) = True Then keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYDOWN, 0)
        If KeyMods(1) = True Then keybd_event(VK_ALT, MapVirtualKey(VK_ALT, 0), KEYEVENTF_KEYDOWN, 0)
        If KeyMods(2) = True Then keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT, 0), KEYEVENTF_KEYDOWN, 0)

        'Main Key Char To press ===============================
        SendMessage(CurHwnd, WM_KEYDOWN, keyCode, 0)
        SendMessage(CurHwnd, WM_KEYUP, keyCode, 0)
        '======================================================

        'if modifiers are used, release 
        If KeyMods(0) = True Then keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0)
        If KeyMods(1) = True Then keybd_event(VK_ALT, MapVirtualKey(VK_ALT, 0), KEYEVENTF_KEYUP, 0)
        If KeyMods(2) = True Then keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT, 0), KEYEVENTF_KEYUP, 0)
.. but if I could hit the JS function directly, which is already attached to the main class, I could send the actual commands directly to the app without being concerned with parsing and formatting key combos. The JS function takes a codeline something like this below...

Code:
Host.GUI.Commands.interpretCommand (element.category, element.name, false, args);
... so if I could call that function I could get rid of all the API code doing keyboard and sendmessage and send the command directly to the app UI. It works fine as is, just wondering if there's a better way. Instead of taking a key combo from a command and formatting it and then passing it to the API, I could send the literal category | element (action) | args directly to the JS function.

I wonder if it might be better to not do this in VS altogether and just add a new include file to the JS collection and use an XML UI so I could have a direct connection to the JS files, the mini API already there in JS.

Last edited by Lawrence; 12-02-2014 at 01:03 PM.
Lawrence is offline   Reply With Quote
Old 12-02-2014, 01:19 PM   #4
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

Quote:
Originally Posted by Lawrence View Post
I ask here because you guys are talented.
Definitely - but for generic programming questions (i.e. not EEL/JesuSonic, not related specifically to anything REAPER/audio/dsp), Stack Overflow may get you much better answers.
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned is offline   Reply With Quote
Old 12-02-2014, 02:35 PM   #5
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,929
Default

Quote:
Originally Posted by Banned View Post
Definitely - but for generic programming questions (i.e. not EEL/JesuSonic, not related specifically to anything REAPER/audio/dsp), Stack Overflow may get you much better answers.
+1 to that! (I am not telling Lawrence to go away from these Reaper forums, but I think the programmers spending time here on these Cockos forums mainly know more about VST and Reaper extension plugins, C/C++, Eel/Jesusonic and such topics...)
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
http://xenakios.wordpress.com/
Xenakios is offline   Reply With Quote
Old 01-15-2015, 09:13 PM   #6
kaklaudioparlour
Human being with feelings
 
kaklaudioparlour's Avatar
 
Join Date: Jan 2015
Location: Vancouver
Posts: 3
Default

You could check out javascript.net, which itself is based on Google's V8 engine. It should let you marshal objects in and out of javascript code.

You could use this sort of thing to let a user control bits of your plugin's internals with user created javascript.
kaklaudioparlour 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 02:17 AM.


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