Old 08-12-2017, 10:43 AM   #1
Tod
Human being with feelings
 
Tod's Avatar
 
Join Date: Jan 2010
Location: Kalispell
Posts: 14,745
Default Saving & Restoring Grid & Type (Midi Editor)

Hello scripters, I would like to be able save and restore the grid and type (straight, triplet, dotted, ect..) settings . This is so that I can change them with actions to perform a task, and then restore them.

I can find no actions for this, I also looked in ReaPack.

Is there any way this can be done?
Tod is offline   Reply With Quote
Old 08-12-2017, 08:06 PM   #2
Tod
Human being with feelings
 
Tod's Avatar
 
Join Date: Jan 2010
Location: Kalispell
Posts: 14,745
Default

Humm, it looks like maybe no, possibly no variables of commands to deal with it?
Tod is offline   Reply With Quote
Old 08-12-2017, 08:19 PM   #3
foxAsteria
Human being with feelings
 
foxAsteria's Avatar
 
Join Date: Dec 2009
Location: Oblivion
Posts: 10,254
Default

Well of course if they are specific grid types you can just make custom actions out of the various grid actions, but I imagine you just want to be able to quickly change back to the grid you were at before changing it. Idk, hit up mpl, maybe you'll get lucky. He seems to be on a roll lately and even made me a custom script the other day when everyone else had been ignoring me for quite a while.
__________________
foxyyymusic
foxAsteria is online now   Reply With Quote
Old 08-12-2017, 09:07 PM   #4
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

We got something going in the Script Request Sticky (post 718) for main section. It was before grid API came out for both Main and MIDI Editor. It used ExtState to store the grid, There's ExtState, which is a kind of global data storage thingy, and ProjExtState, which is project specific. ExtState has a parameter called "persist" which determines if things will be usable across sessions. I think ProjExtState goes in the project file right away so persist parameter is not needed.

So, not too bad, but maybe give more specific method you want to use. You could have "slots" or just one, etc. Global seems cleaner/simpler than per-project to me, but whatever.

Code:
C: double MIDI_GetGrid(MediaItem_Take* take, double* swingOutOptional, double* noteLenOutOptional)

EEL: double MIDI_GetGrid(MediaItem_Take take, optional &swing, optional &noteLen)

Lua: number retval, optional number swing, optional number noteLen = reaper.MIDI_GetGrid(MediaItem_Take take)

Python: (Float retval, MediaItem_Take take, Float swingOutOptional, Float noteLenOutOptional) = RPR_MIDI_GetGrid(take, swingOutOptional, noteLenOutOptional)

Returns the most recent MIDI editor grid size for this MIDI take, in QN. Swing is between 0 and 1. Note length is 0 if it follows the grid size.

Last edited by FnA; 08-12-2017 at 09:15 PM.
FnA is offline   Reply With Quote
Old 08-13-2017, 08:51 AM   #5
Tod
Human being with feelings
 
Tod's Avatar
 
Join Date: Jan 2010
Location: Kalispell
Posts: 14,745
Default

Quote:
Originally Posted by FnA View Post
We got something going in the Script Request Sticky (post 718) for main section. It was before grid API came out for both Main and MIDI Editor. It used ExtState to store the grid, There's ExtState, which is a kind of global data storage thingy, and ProjExtState, which is project specific. ExtState has a parameter called "persist" which determines if things will be usable across sessions. I think ProjExtState goes in the project file right away so persist parameter is not needed.

So, not too bad, but maybe give more specific method you want to use. You could have "slots" or just one, etc. Global seems cleaner/simpler than per-project to me, but whatever.

Code:
C: double MIDI_GetGrid(MediaItem_Take* take, double* swingOutOptional, double* noteLenOutOptional)

EEL: double MIDI_GetGrid(MediaItem_Take take, optional &swing, optional &noteLen)

Lua: number retval, optional number swing, optional number noteLen = reaper.MIDI_GetGrid(MediaItem_Take take)

Python: (Float retval, MediaItem_Take take, Float swingOutOptional, Float noteLenOutOptional) = RPR_MIDI_GetGrid(take, swingOutOptional, noteLenOutOptional)

Returns the most recent MIDI editor grid size for this MIDI take, in QN. Swing is between 0 and 1. Note length is 0 if it follows the grid size.
Thanks FnA, I tried your scripts from post 718, but they don't seem to work. I saved them as Python scripts, would that be right?

I'm using the "Save" and "Restore" in a custom action so they are used right away.

Here is the actual macro:
Code:
Custom: Add Major chord, 1 bar long, -6 px 
   Script: Save Grid.py
   Navigate: Move edit cursor to start of selected events
   Grid: Set to 1
   Edit: Set note lengths to grid size
   Step input: Insert note at current +04 semitones
   Step input: Insert note at current +07 semitones
   Custom: Shorten notes 6 pixels
   Script: Restore Grid.py
Is there a different extension I should use with your scripts, or maybe a way to modify them to work?
Tod is offline   Reply With Quote
Old 08-13-2017, 08:57 AM   #6
Tod
Human being with feelings
 
Tod's Avatar
 
Join Date: Jan 2010
Location: Kalispell
Posts: 14,745
Default

Quote:
Originally Posted by foxAsteria View Post
Well of course if they are specific grid types you can just make custom actions out of the various grid actions, but I imagine you just want to be able to quickly change back to the grid you were at before changing it. Idk, hit up mpl, maybe you'll get lucky. He seems to be on a roll lately and even made me a custom script the other day when everyone else had been ignoring me for quite a while.
Thanks fox and yeah, I just want to quickly change the grid to 1, add some notes and shorten them slightly, then set the grid back to what it was. Actually by using set grid to 1, I don't have to worry about the type.
Tod is offline   Reply With Quote
Old 08-13-2017, 11:33 AM   #7
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

Hi Tod. Indeed they are Python. I mainly was pointing out the storage method. Those scripts are only for the Main section, and they are deprecated by the newer API now available.

Your macro would be cleaner with a script to put the notes in at desired length. (In "set note length to grid size," 1 = 1 whole note, not 1 measure length, if other than 4/4.) I hesitate to do any public MIDI note scripts, because I have not learned how to use the newer "SetAllEvents" method. Juliansader is the only person I have seen use that. The other method has issues when overlapping notes are involved. But disregarding that problem, I have seen people get satisfaction from scripts by several other scripters using the older method lately.

Do you want whole notes, or measure length at edit cursor? I will write one of those with the old method, if you are ok with the overlapping note limitation. Otherwise I could do it by changing the grid, but since Amagalma brought the concept to the table, and now has some of his own scripts in ReaPack, maybe he should have the opportunity to add it to his stash. It might have other uses.

For your use here, non-persistent ExtState storage would be ok, I think.

Actually, this seems to do the trick:
Code:
Custom: Add Major chord, 1 bar long, -6 px 
   Navigate: Move edit cursor to start of selected events
   Step input: Insert note at current +04 semitones
   Step input: Insert note at current +07 semitones
   Edit: Move edit cursor right one measure
   Edit: Trim right edge of note to edit cursor
   Custom: Shorten notes 6 pixels (I used 6 "1 pixel" actions)
FnA is offline   Reply With Quote
Old 08-13-2017, 01:13 PM   #8
Tod
Human being with feelings
 
Tod's Avatar
 
Join Date: Jan 2010
Location: Kalispell
Posts: 14,745
Default

Thanks much FnA, that works if I make the route note (1st note) longer than the measure and I'd like to be able to just insert a short note

Actually you got me looking and I finally realized I was concentrating on the grid so hard I completely missed the "Set note length x", x being the number, which in this case is 1. Heh heh I can't believe I did that, but I did.

At any rate, I took your macro and used these actions. Also I wanted to have the edit cursor end up at the front of the notes.
Code:
Custom: Add Major chord, 1 bar long, -6 px
     Navigate: Move edit cursor to start of selected events
     Step input: Insert note at current +04 semitones
     Step input: Insert note at current +07 semitones
     Edit: Set note length to 1
     Edit: Move edit cursor right one measure
     Edit: Trim right edge of note to edit cursor
     Custom: Shorten notes 6 pixels
     Navigate: Move edit cursor to start of selected events
Again thanks guys, between the both of you it got me looking and it works perfectly.
Tod is offline   Reply With Quote
Old 08-13-2017, 02:57 PM   #9
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

The trim action should lengthen notes if they end before the cursor. I tried it with eighth notes.

But sounds like you got a good solution. I'm glad, because it doesn't look like you can set swing amount for a "restore grid" script in the MIDI Editor. You do have a parameter in the main section. I can't find it in the docs with search on "swing" anyway...



edit. also, I think you can probably remove the "move edit cursor right 1 measure" and "trim" actions if you just want to set it to whole notes, not whatever the time signature might be.

Last edited by FnA; 08-13-2017 at 03:20 PM.
FnA 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:50 AM.


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