Using Reaper Under MacOs and Js programming: Difference between pages

From Reaper Accessibility Wiki
(Difference between pages)
Jump to navigation Jump to search
(initial page migration)
 
 
Line 1: Line 1:
= introduction =
=js Programming=


OSARA is a plug-in which aims to work under Windows and Mac using the screen readers available for each platform. As has been [[Getting_Started#Mac_Osara_Installation|probably explained elsewhere]] and [[Chapter_1_Setting_Up_and_Getting_Started#1.9_REAPER_Selections.2C_Controls_and_Commands|in the reaper manual]], there are some [[Enabling_Midi_Devices#Mac_Instructions|differences]] for achieving [[Sidechaining_with_ReaComp#Some_Tips_for_Windows_and_Mac_users|some procedures]] (like setting up track sends for instance). This article will attempt to bring them all in one place. it also will most likely be helpful for users of both platforms. note that due to the development of reaper and osara advancing simultaneously for some time now, possibilities are growing for accomplishing tasks so the information present on this article, while still relevant and applicable, is subject to change from time to time.
== Introduction ==
js plugins are Reaper's own plugin format similar in many ways to VST plugins.  A js plugin can process and generate audio and midi data and expose parameters to the user which can be automated.


== voiceover tips and tricks ==
js plugins have a number of advantages such as easy to start writing, all parameters are exposed and these parameters are easy to interact with via a keyboard either directly in the user interface or by the OSARA parameter dialogue.  They also support graphics making them good for sighted users and it is also possible to add keyboard support though this is almost vanishingly rare.  Disadvantages are around limited to non-existent file handling.


=== voiceover talks too much/makes too much noise! ===
== View and existing js plugin ==
js plugins are written in plain text files and there are plenty to take a look at.  From the Reaper Help Options menu select Resource path.  In here is a folder called "Effects" in which are all the js plugins that come with Reaper.


One of the first things (and most frequently described problems) users notice, is the excess speech and feedback being given by voiceover. For example, since macOS High Sierra, VO beeps every time OSARA provides feedback. This not only makes working in reaper tedious, it can also potentially become distracting and slow down the workflow. There are some things you can do to reduce these issues.
Typically a js plugin either has no file extension or an extension of jsfx.  Use your favourite plain text editor to open up any of the files to see what they look like.


==== Reducing Voice Over Sounds With VO Activities ====
It is useful to turn the vebosity of your screen reader so it speaks all characters.  It is important to capture all the code when programming.  For example, a semicolon is required at the end of each command and most people dont set their screen reader to announce these.
To stop VO beeping each time OSARA provides feedback, setup a Voice-Over Activity for Reaper as described below:


#Press VO-F8 to open Voice-Over Utility.
In NVDA, the verbosity can be cycled with NVDA+P.
#Press command-0 to go to activities.
#Now, find the "Add" button at the bottom of the window and press it.
#You are prompted to make a name for the activity. making the name application specific is recommended but this is a personal preference.
#Now press VO+right-arrow until you hear: Additional settings (or how it is shown for your language). And here press vo-spacebar.
#Now continue to press VO+right arrow until you hear: Audio checkbox unchecked. Check it using Vo-spacebar.
#Continue once more to the right, and you'll find the options button, which you press by using vo-spacebar on it.
#Now you have to locate and check the box: Mute sound effects and go to the end of the window and close it by pressing either close or OK.
#Now you are back to the activities window. We now need to tell Voiceover when to use this activity.
#Press VO+right until it says: Webpages and programs menu button, and press VO+spacebar.
#Select Reaper from the list of applications. That's it, no more sound effects from Voiceover.


Note, many other options around verbosity can also be customized for the Reaper Activity you have created, including any Keyboard Commander assignments you have made. Below is another recommended Activity customization. Also, the above Muting of VO sound effects can also be added to a Keyboard Commander, key in the VO Utility.
== Structure of a plugin ==
A js plugin is made up of a header and then a series of sections which have a predefined named and purpose.


==== Reducing Speech Verbosity ====
While setting up the activity as above, you can include verbosity settings. 
Press the "Set… Verbosity" button. and then expand the additional speech verbosity options. at the very bottom of the table of options which you can customize, there is an option called "Window". Customize the verbosity for this setting and uncheck the “Name” field. You will still need to have either status or type checked but this will stop Voice Over from telling you about your particular version of reaper and who it is licensed to, whenever you return to the main Reaper window. This reduces some of the extraneous speech
==== Muting Voice Over ====
Another option is to assign a Keyboard Commander shortcut key that will mute Voiceover completely. This is especially helpful when you don't want to be distracted while doing some precise edits.
You can do this from within the Voice Over Utility accessed by pressing VO+F8, and then pressing Command+8 to access the commander options. Pick the Keyboard tab, and then Add an additional key and assign it to the Mute Voice Over toggle command. 


The header can be as short as a declaration of the name of the plugin but can also hold much more information such as the author, date, version, release notes, instructions on usage and other information that helps with reaPack integration.


note: VO is a short form for the Voiceover word. Remember you can use either caps lock or control-option keys as Voiceover mmodifier keys depending on how you have set Voiceover on your Mac.


== other specific mac related concerns ==
The header is followed by definition of the plugin parameters which is done by defining a slider for each parameter.  A slider has a min value, a max value, an increment value and a default value.  These are seen by the user in the plugin user interface as a slider and edit box for each parameter.


=== How to Allow OSARA, SWS and Other Reaper Extensions to run in Mac OS Catalina. ===


When Mac OS Catalina was released in October 2019, users found that OSARA, SWS and other extensions were not allowed to run. Catalina users receive an error message complaining that the extensions they're attempting to run aren't confirmed to be from a known source/developer. But fear not, you can manually allow OSARA and other extensions to run by following these steps:
The @init block is run when the plugin first starts which is typically when it is first loaded onto an FX chain and when play starts. It is used to initialise variables to default values.  Note that the js plugin language does not require variables to be declared before they are used so this section does not need to include initialisation of all variables if this is done elsewhere.  Also, the default initialisation of a variable is to set it to zero.


# Press cancel the first time you see the error message. If you get a second warning where the extension name is different. Do not press cancel a second time.
# Open System Preferences, then choose Security.
# Navigate to the bottom of the screen by pressing VoiceOver+End.
# Navigate using VoiceOver+LeftArrow until you hear VoiceOver say "Click the lock to make changes", press VoiceOver+Space on that lock button and enter your password if prompted.
# To the left of the lock button, you'll find a button labeled "Allow". You can confirm which extension you're allowing by hitting VoiceOver+LeftArrow once more, so be sure to verify that, then when you're ready, move back to the "Allow" button and click it using VoiceOver+Space.
# Here's where you'll need to use a little screen reader trickery. You now need to press VoiceOver+F1 twice quickly to bring up the application chooser menu. The first item in that menu should be "System dialogs", and VoiceOver will likely say "1 item". Press VoiceOver+Space twice there (the first press will open the system dialogs submenu, the second press will move VoiceOver focus into the system dialog itself).
# You should now find yourself re-focused back in the same warning described in step 1. Repeat steps 5 and 6 again until there are no more system dialogs to attend to.
After allowing each of your extensions this way, they should work as expected when you next launch Reaper.


==== Alternative Method (for advanced users only). ====
The @slider block is run whenever a parameter is changed either through automation or by the user.  For example, a parameter might be presented to the user as a percentage from 0 to 100 but the code needs this rescaling from -1 to 1.


The method described below may result in your system being easier to attack because it involves disabling Apple's system integrity protection (a setting which is turned on by default). There are multiple articles online outlining this method in detail, such as [https://www.imore.com/how-turn-system-integrity-protection-macos this guide from iMore]


Please research the ramifications of disabling system integrity protection and make certain that you're comfortable before attempting this alternative method. It may seem easier than the steps above at a glance, but remember that security is paramount nowadays. OK, you've made it through the warning so you're clearly a determined sort. Here are the steps:
The @block code is run as a new block of samples arrives.  The block size as defined in Reaper preferences in the devices section dictates how many sampless.  This is an area of code commonly used to process MIDI as all the MIDI notes and events coming up in the next block of samples can be processed and action taken accordingly.  Also, MIDI notes and events can be inserted so they are played once the block enters Reaper's play buffer.
# Reboot your Mac into recovery mode by holding CMD+R as you press the power button.
# Wait for about 30 seconds, then launch VoiceOver either by pressing CMD+F5 or pressing three times on the Touch ID button if your Mac has one of those.
# Select your language if prompted.
# On the screen that offers such options as "Install Mac OS" and "Restore from Time Machine backup", move to the menu bar by pressing VoiceOver+M, open the Utilities menu and choose Terminal.
# Type in the following command and press Enter when you are done: csrutil disable
# Type reboot and hit Enter again. Once done, your Mac will restart with system integrity protection disabled, and - though your system may now be a perilous void of vulnerability - your extensions should work as expected.  


===  there is no application key on mac ===


There are some situations in which you are advised to use the applications key, (for example, when setting inputs for recording).
The@sample block is run every sample.  So yes, many thousands of times a second.  Commonly used to process audio as there is easy access to the value of the audio in each channel.


The good news is that you don’t need an application-key on the mac. Recent  changes in osara development and reaper allow users to access the menus reliably, regardless of system. This is because Rather than using various hacks to access context menus, osara now uses a new REAPER API function explicitly designed for this purpose.
This basically means that On Mac, you can now press control+1, control+2 and control+3 to open the first, second and third context menus, respectively. More detailed information is available in the [[OSARA_readme#Context_Menus|osara readme]]


As for setting track inputs, the info that follows is out of date, but might be of use for some people.
The @gfx block is used to draw graphics and process keyboard input.  I'm not sure when it is run.
there is a simple trick to open the track-input-menu:


For example, lets say,  you have an interface with 8 inputs and want to assign  the first  microphone-input to track 3, because track 1 and 2 contain virtual instruments. Then you could do the following:
== First Audio Plugin ==
# Press Voice-over+I to open the item-chooser.
Let's dive in with a very simple js plugin that includes a volume control for audio.  Open up a plain text editor and copy and paste the following code into it.
# Type in 3 for track-number 3 and press enter.
# Make sure that quick-navigation-mode is off by pressing left and right arrow-keys simultaneously.
# Press voice-over+left once. That should bring you to an entry called „Track-input-record, followed by a number, which will depend on how many channels your interface has.
# Pressing voice-over+space will open the track-inputs-menu. Here you can assign the appropriate input.
You can also assign inputs on the Mac or Windows with [http://audio.pizza/tag/reaconsole/ ReaConsole] (follow the link for an audio tutorial by Garth Humphreys) or see its [[Reaper_plus!_the_power_of_sws_extensions#SWS_ReaConsole|corresponding documentation]].




=== adjusting effect parameters ===
Desc: My first audio plugin


Thanks to a recent osara update, there is the possibility, just  as is done in windows to open a  [[OSARA_readme#FX_Parameters|dialog which exposes all of the parameters that relate to a plug-in]]


A couple of notes regarding Mac though
slider:100<0,100,1>Volume
# The actions to open Parameters dialogs aren't bound to keys on the Mac yet. You'll need to bind yourself or execute from the Actions dialog.
# The slider should support keyboard interaction (arrow keys, page up/down, home/end). However, it won't work if you try to use VO commands to interact with it. For now there isn't either a possibility, nor plans to try to fix this.


In the case of other effects that do not expose very helpful values from this dialog, you can try and access the native or generic effects UI, depending on the particular effect you are using. the accessibility of the native dialogs vary between manufacturers; however, if you are using the default settings, then when you add an effect you will be in the native UI. First check this out and see if you can access the parameters, most of the included Reaper effects are accessible. For third party effects, it varies. If the native UI is not accessible, then press VO + space on the UI button and you will have some access to the parameters.
 
@slider
 
scaler = slider1/100;
 
 
@sample
 
spl0 *= scaler;
 
spl1 *= scaler;
 
 
Save this in the Reaper resources Effects folder, ideally in a new subfolder to contain all your plugins.  Start up Reaper and it should do a rescan and make your new js plugin available to use.
 
 
Create a track and add some audio to it for example recording yourself speaking, by inserting an audio file or selecting something from media explorer.  Hit F on the track to bring up the FX chain dialogue and use the Add button to add your plugin.  Type in "first" as this is text included in the first line of the code copied into the plugin and is the name given to the plugin.  Arrow down and you should find the plugin.  Hit enter and it will get loaded onto the FX chain for the track.  Press tab to work your way through the plugin and you will come to the slider and edit controls for the volume parameter.
 
 
Press space to play the audio and then adjust the volume with either the slider or entering a new value in the edit field.  The volume changes.  Your first plugin.
 
== First MIDI Plugin ==
Here is a simple plugin that has a slider to change the pitch of any incoming MIDI notes.  The minimum code for MIDI is a little more than for audio.
 
 
Desc: My first MIDI js plugin
 
 
slider:0<-24,24,1>Semitone shift
 
 
@slider
 
shift = slider1;
 
 
@block
 
while( midirecv( offset, msg1, msg2, msg3 ) )
 
(
 
  msg1 & 0xF0 = 0x90 ?
 
  (
 
   midisend( offset, msg1, msg2 + shift, msg3 );
 
  )
 
  :
 
  (
 
   midisend( offset, msg1, msg2, msg3 );
 
  );
 
);
 
 
In the same way as with the audio plugin, copy this code into a plain text file and save it in the Effects subfolder in the Reaper resource path ideally in your own subfolder holding all your plugins. Start up Reaper so it does a rescan and then insert reaSynth onto a track as as a VSTi.  Test you can play notes.  Now add your first MIDI plugin onto this track as well.  Before it has any effect thugh yu need to move reaSynth so it is below your first MIDI plugin since the plugin needs to update the MIDI data between it being played and it arriving at reaSynth.  Do this by either cutting and pasting reaSynth so it is second in the chain, or using the action bound to control-shift alt page down (Windows).
 
 
Tab to the Semitone shift slider in your new plugin. Play a note and then change the slider.  The pitch of notes is shifted.
 
== Tools to help write plugins ==
The most basic tool is your plain text editor of choice.  Reaper does have an inbult editor but it is not easily accessible.  So writing code in a plain text editor is the next best thing.  If you make a change to your code and save it though, you will need to return to Reaper and the FX chain , press contrl R on your plugin and replace the plugin with a new instance of itself to for the changes take effect.
 
 
It is possible to view all the variables used in a plugin along with their values.  This can be done with NVDA object navigation by tabbing to the edit button in the FX dialogue, hitting enter , and uing object navigation to move right until a list control is reached.  Gone down and you can then review each variable.
 
 
Debugging is difficult though in js plugins.  There is no option to display a message box or output diagnostic info to a file. And some variables will change their value with every sample or every block making them impossible to track.  You cannot step through the code one line at a time reviewing variable values like you can in more complex IDE's.
 
==Resources ==
 
There are not a whole bunch of great resources for writing js plugins.  Probably the most comprehensive source of information are all the plugins that come with Reaper and found in the Effects folder.  But these can be complex and difficult to work out how they work.
 
There is a good tutorial made by [https://www.admiralbumblebee.com/music/2018/02/08/Write-a-Reaper-MIDI-JSFX-from-scratch.html Admiral Bumblebeee] which goes through a modestly complex project to write a MIDI plugin.  There is also other useful content on this web site.
 
[https://www.reaper.fm/sdk/js/basiccode.php#js_basic The JSFX Programming Reference - Language Essentials] is on Reaper's web site.  It is a reference manual though and not a tutorial but if you get into JSFX programming you will come to appreciate this resource.
 
The Reaper community are a helpful bunch.  [https://forum.cockos.com/forumdisplay.php?f=3 The JSFX forum]. Use the search feature or search with something like Google putting reaper jsfx forum in as part of your search.  Sign up to post a question. 

Revision as of 19:45, 7 November 2023

js Programming

Introduction

js plugins are Reaper's own plugin format similar in many ways to VST plugins.  A js plugin can process and generate audio and midi data and expose parameters to the user which can be automated.

js plugins have a number of advantages such as easy to start writing, all parameters are exposed and these parameters are easy to interact with via a keyboard either directly in the user interface or by the OSARA parameter dialogue.  They also support graphics making them good for sighted users and it is also possible to add keyboard support though this is almost vanishingly rare.  Disadvantages are around limited to non-existent file handling.

View and existing js plugin

js plugins are written in plain text files and there are plenty to take a look at.  From the Reaper Help Options menu select Resource path.  In here is a folder called "Effects" in which are all the js plugins that come with Reaper.

Typically a js plugin either has no file extension or an extension of jsfx.  Use your favourite plain text editor to open up any of the files to see what they look like.

It is useful to turn the vebosity of your screen reader so it speaks all characters.  It is important to capture all the code when programming.  For example, a semicolon is required at the end of each command and most people dont set their screen reader to announce these.

In NVDA, the verbosity can be cycled with NVDA+P.

Structure of a plugin

A js plugin is made up of a header and then a series of sections which have a predefined named and purpose.


The header can be as short as a declaration of the name of the plugin but can also hold much more information such as the author, date, version, release notes, instructions on usage and other information that helps with reaPack integration.


The header is followed by definition of the plugin parameters which is done by defining a slider for each parameter.  A slider has a min value, a max value, an increment value and a default value.  These are seen by the user in the plugin user interface as a slider and edit box for each parameter.


The @init block is run when the plugin first starts which is typically when it is first loaded onto an FX chain and when play starts. It is used to initialise variables to default values.  Note that the js plugin language does not require variables to be declared before they are used so this section does not need to include initialisation of all variables if this is done elsewhere.  Also, the default initialisation of a variable is to set it to zero.


The @slider block is run whenever a parameter is changed either through automation or by the user.  For example, a parameter might be presented to the user as a percentage from 0 to 100 but the code needs this rescaling from -1 to 1.


The @block code is run as a new block of samples arrives.  The block size as defined in Reaper preferences in the devices section dictates how many sampless.  This is an area of code commonly used to process MIDI as all the MIDI notes and events coming up in the next block of samples can be processed and action taken accordingly.  Also, MIDI notes and events can be inserted so they are played once the block enters Reaper's play buffer.


The@sample block is run every sample.  So yes, many thousands of times a second.  Commonly used to process audio as there is easy access to the value of the audio in each channel.


The @gfx block is used to draw graphics and process keyboard input.  I'm not sure when it is run.

First Audio Plugin

Let's dive in with a very simple js plugin that includes a volume control for audio.  Open up a plain text editor and copy and paste the following code into it.


Desc: My first audio plugin


slider:100<0,100,1>Volume


@slider

scaler = slider1/100;


@sample

spl0 *= scaler;

spl1 *= scaler;


Save this in the Reaper resources Effects folder, ideally in a new subfolder to contain all your plugins.  Start up Reaper and it should do a rescan and make your new js plugin available to use.


Create a track and add some audio to it for example recording yourself speaking, by inserting an audio file or selecting something from media explorer.  Hit F on the track to bring up the FX chain dialogue and use the Add button to add your plugin.  Type in "first" as this is text included in the first line of the code copied into the plugin and is the name given to the plugin.  Arrow down and you should find the plugin.  Hit enter and it will get loaded onto the FX chain for the track.  Press tab to work your way through the plugin and you will come to the slider and edit controls for the volume parameter.


Press space to play the audio and then adjust the volume with either the slider or entering a new value in the edit field.  The volume changes.  Your first plugin.

First MIDI Plugin

Here is a simple plugin that has a slider to change the pitch of any incoming MIDI notes.  The minimum code for MIDI is a little more than for audio.


Desc: My first MIDI js plugin


slider:0<-24,24,1>Semitone shift


@slider

shift = slider1;


@block

while( midirecv( offset, msg1, msg2, msg3 ) )

(

  msg1 & 0xF0 = 0x90 ?

  (

   midisend( offset, msg1, msg2 + shift, msg3 );

  )

  :

  (

   midisend( offset, msg1, msg2, msg3 );

  );

);


In the same way as with the audio plugin, copy this code into a plain text file and save it in the Effects subfolder in the Reaper resource path ideally in your own subfolder holding all your plugins. Start up Reaper so it does a rescan and then insert reaSynth onto a track as as a VSTi.  Test you can play notes.  Now add your first MIDI plugin onto this track as well.  Before it has any effect thugh yu need to move reaSynth so it is below your first MIDI plugin since the plugin needs to update the MIDI data between it being played and it arriving at reaSynth.  Do this by either cutting and pasting reaSynth so it is second in the chain, or using the action bound to control-shift alt page down (Windows).


Tab to the Semitone shift slider in your new plugin. Play a note and then change the slider.  The pitch of notes is shifted.

Tools to help write plugins

The most basic tool is your plain text editor of choice.  Reaper does have an inbult editor but it is not easily accessible.  So writing code in a plain text editor is the next best thing.  If you make a change to your code and save it though, you will need to return to Reaper and the FX chain , press contrl R on your plugin and replace the plugin with a new instance of itself to for the changes take effect.


It is possible to view all the variables used in a plugin along with their values.  This can be done with NVDA object navigation by tabbing to the edit button in the FX dialogue, hitting enter , and uing object navigation to move right until a list control is reached.  Gone down and you can then review each variable.


Debugging is difficult though in js plugins.  There is no option to display a message box or output diagnostic info to a file. And some variables will change their value with every sample or every block making them impossible to track.  You cannot step through the code one line at a time reviewing variable values like you can in more complex IDE's.

Resources

There are not a whole bunch of great resources for writing js plugins.  Probably the most comprehensive source of information are all the plugins that come with Reaper and found in the Effects folder.  But these can be complex and difficult to work out how they work.

There is a good tutorial made by Admiral Bumblebeee which goes through a modestly complex project to write a MIDI plugin.  There is also other useful content on this web site.

The JSFX Programming Reference - Language Essentials is on Reaper's web site.  It is a reference manual though and not a tutorial but if you get into JSFX programming you will come to appreciate this resource.

The Reaper community are a helpful bunch.  The JSFX forum. Use the search feature or search with something like Google putting reaper jsfx forum in as part of your search. Sign up to post a question.