Old 02-08-2020, 11:49 AM   #1
lightnb
Human being with feelings
 
Join Date: Dec 2019
Posts: 24
Default Help with first script: Cycle MIDI Note Display

I've built a lot of stuff with PHP and Javascript, but this is my first time with EEL and Reaper.

So I decided to do a simple test project, which will create a script to cycle the display of MIDI notes between triangle, square, and diamond. (instead of having separate buttons for each).

This is the rough script:

Code:
// Simple script that can be attached to a single button or hotkey
// that cycles through the diamond/triangle/rectangle midi note displays.

// See if we have initialized this variable yet
// DisplayState will be null (?) when this script is first run,
// Otherwise, it will have a numeric value

if(!DisplayState){ // First Run
// Create a variable to store the display state of the note.
// 1 = Rectangle, 2 = triangle, 3=diamond
var DisplayState = GetNoteDisplayState();
DisplayState =  convert to 1,2,3 from whatever the API returns....

} // Variable initialized, cycle:


if(DisplayState == 1){
  DisplayState=2;
  SetDisplayState('triangle');
}elseif(DisplayState == 2){
  DisplayState=3;
  SetDisplayState('diamond');
}else{ // 3 or other value, return to rectangles.
  DisplayState=1;
  SetDisplayState('rectangle');
}

I've looked through the function list that comes from the local file in the Reaper help menu, but I'm not seeing the functions that I need.

Things I need:

1.) An echo(); or alert(); function for debugging.
2.) An API call that checks which state the note display is in (rectangle, triangle, or diamond);
3.) An API call that sets the display to one of those types.

I found MIDIEditor_GetMode(),MIDIEditor_GetSetting_int(), MIDIEditor_SetSetting_int(), which seem close, but I'm not sure if that's the right function or how exactly to specify note display if GetSetting() can return it.
lightnb is offline   Reply With Quote
Old 02-08-2020, 02:32 PM   #2
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,588
Default

I have no idea about PHP and Javascript, so I can't help with making parallelisms of those with eel or lua..

Btw, the action that you want to make already exists: 40407 -- View: Cycle events view rectangles/triangles/diamonds...

But just for practicing how things work in ReaScript...

You have fisrt to get the active take of the open Midi Editor..
so look at these: MIDIEditor_GetActive, MIDIEditor_GetTake.

Then you have to query the toggle state of the command that interests you:
GetToggleCommandState
and the relative commands are:
40450 -- View: Show events as diamonds (drum mode)
40449 -- View: Show events as rectangles (normal mode)
40448 -- View: Show events as triangles (drum mode)

Then set the mode by running the appropriate action using MIDIEditor_OnCommand

Hope this helps

PS. For debugging you can send messages to the console with ShowConsoleMsg
amagalma is offline   Reply With Quote
Old 02-11-2020, 08:06 PM   #3
lightnb
Human being with feelings
 
Join Date: Dec 2019
Posts: 24
Default

Quote:
Originally Posted by amagalma View Post
40407 -- View: Cycle events view rectangles/triangles/diamonds...
40450 -- View: Show events as diamonds (drum mode)
40449 -- View: Show events as rectangles (normal mode)
40448 -- View: Show events as triangles (drum mode)
So I found these numbers by right clicking and choosing "show action IDs" in the Actions list.

Quote:
Originally Posted by amagalma View Post

You have fisrt to get the active take of the open Midi Editor..
so look at these: MIDIEditor_GetActive, MIDIEditor_GetTake.
OK, so I got a take by getting a reference to the midi editor and passing that in.

Code:
oActiveMIDIEditor = reaper.MIDIEditor_GetActive();
oActiveTake = reaper.MIDIEditor_GetTake(oActiveMIDIEditor);
Quote:
Originally Posted by amagalma View Post
Then you have to query the toggle state of the command that interests you:
GetToggleCommandState
GetToggleCommandState doesn't take a MidiEditor (or Take) as an argument though, so I guess I don't need the reference to the MIDIEditor for this?

Also, running:
Code:
reaper.ShowConsoleMsg(reaper.GetToggleCommandState(40450));
reaper.ShowConsoleMsg(reaper.GetToggleCommandState(40449));
reaper.ShowConsoleMsg(reaper.GetToggleCommandState(40448));
reaper.ShowConsoleMsg(reaper.GetToggleCommandState(40407));
Shows
Code:
 -1-1-1-1
So it looks like none of the actions have a toggle state. Is there another command that does this?

Also, it would be useful if you could dump an object and see what's inside it. For example:

Code:
reaper.vardump(oActiveMIDIEditor);
Code:
oActiveMIDIEditor[
HasFocus:1,
TakeID:0,
MIDIItemName:"Drum Beat 1",
....
]
lightnb 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 09:46 AM.


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