Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 01-28-2021, 07:24 PM   #1
nielsbohr3141
Human being with feelings
 
Join Date: Dec 2014
Posts: 25
Default MFZ9000 - a set of scripts for consistent zooming and focusing in the MIDI editor

Midi Focus and Zoom 9000

The scripts do two basic things currently:

1) Allows the user to set a default vertical and horizontal zoom for when you open the MIDI editor that will never-ever change except for when the user wants it.

2) When the MIDI editor is opened, the viewport will focus on the first N measures as defined by the user. Measures are counted from the right of the edit cursor. Furthermore, it will also focus vertically to the vertical center of the notes in the viewed measures.


Basically, any time you open any MIDI item on the track, it will always show the same vertical zoom, the same horizontal zoom (measure-based), and you'll always be focused on the notes in your viewport.






Release info:
=========================
MIDI FOCUS AND ZOOM 9000 v0.3.1

Opens the MIDI editor with consistent, user-defined measure-based horizontal zoom values,
and vertical zoom values. The horizontal zoom values can be changed per track (persistent).

The measures shown are calculated from the right of the current edit cursor location.

Usage:
Bind this script to a keyboard key or a mouse action of your choosing
for opening the MIDI items. The default action is (in Mouse Modifiers settings):
Media Item -> Double Click -> Default Action. Check the user settings below. Use
the provided "MFZ9000 - Set zoom settings in MIDI editor.lua" script for user-based
changes in the MIDI editor (NOT IN THE MAIN WINDOW).

=========================


Sorry for making a new thread (https://forum.cockos.com/showthread.php?t=248676), but I've decided to make it into more of a real thing rather than a one-off short script. Reaper's default treatment of the zoom and focus of the MIDI editor is... not very good. The lack of consistency in zooming and focusing has been bugging me for a good while now - all that fiddling with horizontal and vertical zooms and scrolling to fit the notes on the screen. Hopefully, if you're in the same boat, this script will alleviate some of these problems.

v0.2:
Massive internal rewrite, on the user side of things added an option (inside the opener script) to open the MIDI item at mouse cursor location.

Download v0.2:
https://github.com/nick-jn/nick-jn-r...Z9000.v0.2.zip

v0.3:
Changes:
-------------
-- Now activates the appropriate action for MIDI items, subprojects in the arrange view, and any other item (in theory...), upon opening.
-- Previous implementation of zooming based on the measures was dumb. I forgot about time signature changes and weird time signatures. The new one uses 4/4 as a reference, and applies the same zooming factor disregarding the time signature (i.e. the amount of stuff you see horizontally should be the same regardless of the time signature). It's less hacky too.
-- Horizontal zooming is consdireably more sophisticated now - it will try to center the item on the screen if its length is small enough, and it will also show the entirety of the item if its smaller than the desired horizontal zoom. It also has some extra options to control all of that. Check the user settings section.
-- Doesn't create any undo states.
-- Changed vertical zoom values to real values of the MIDI editor.
-- Vertical position won't get off bounds for focusing vertically at low notes (this is a Reaper's bug actually - move the pitch cursor to the lowest, and zoom in/out vertically).
-- Minor optimization for the vertical zooming and refocusing - it now does so with the help of CFGEDITVIEW values.
-- Optimized the pitch cursor shifting algorithm - it now shifts by octave and goes straight to the correct note (when possible) when the correct octave is reached. It's hacky as hell, but faster (not that there's a need really).

Known issues (so far):
-- The user settings utility doesn't refocus quite as well as it should after clicking ok.


Download v0.3:
https://github.com/nick-jn/nick-jn-r...lease.v0.3.zip

------------------------

v0.3.1:
Changes:
-- Slight changes in the order of the user settings in the opener file.

Fixed:
-- Better handling of media item types upon opening.
-- Simplified the pitch cursor shifting algorithm further


Download v0.3.1:
https://github.com/nick-jn/nick-jn-r...000.v0.3.1.zip

Last edited by nielsbohr3141; 02-02-2021 at 04:13 PM. Reason: update
nielsbohr3141 is offline   Reply With Quote
Old 01-29-2021, 06:09 AM   #2
cool
Human being with feelings
 
Join Date: Dec 2017
Location: Sunny Siberian Islands
Posts: 414
Default

Very cool!
One thing: for some reason, when I open the midi editor, I have a large number (several tens) of bars displayed for any measure settings.
cool is offline   Reply With Quote
Old 01-29-2021, 07:53 AM   #3
nielsbohr3141
Human being with feelings
 
Join Date: Dec 2014
Posts: 25
Default

Quote:
Originally Posted by cool View Post
One thing: for some reason, when I open the midi editor, I have a large number (several tens) of bars displayed for any measure settings.

Yeah, unfortunately one thing that I noticed when writing the script is that how much small configuration tweaks Reaper has with respect to nearly everything. It's likely something I didn't account for, or just a bug due to bad coding.


The horizontal zoom works very simple - it creates a new loop by shifting the edit cursor (by measure, and bringing it back to the starting point, if needed), and then using the "zoom to project loop selection" action in the MIDI editor. That's it. I found two settings that can mess with it - linking time selection and loops, moving time cursor to start of the time selection on its change, but these should be accounted for. Any ideas which other settings can mess with edit cursor movement and loop creation?



Try setting "change_measures_externally" to false in the user settings. This will disable the extra user configuration provided by the settings script and will directly load the "measures_to_show" variable from the user settings section.
nielsbohr3141 is offline   Reply With Quote
Old 01-29-2021, 09:04 AM   #4
nielsbohr3141
Human being with feelings
 
Join Date: Dec 2014
Posts: 25
Default

I messed up with that "link loop points to time selection" option after all, the script didn't check for that at the correct time. Might fix the problem above, but in any case this was definitely a bug.



Download v0.1.1:
https://github.com/nick-jn/nick-jn-r...000_v0.1.1.zip
nielsbohr3141 is offline   Reply With Quote
Old 01-29-2021, 10:32 AM   #5
FeedTheCat
Human being with feelings
 
FeedTheCat's Avatar
 
Join Date: May 2019
Posts: 501
Default

Ah nice, a kindred spirit I went on a similar journey last year, maybe there's something in there you can use.
FeedTheCat is offline   Reply With Quote
Old 01-29-2021, 12:50 PM   #6
nielsbohr3141
Human being with feelings
 
Join Date: Dec 2014
Posts: 25
Default

Quote:
Originally Posted by FeedTheCat View Post
Ah nice, a kindred spirit I went on a similar journey last year, maybe there's something in there you can use.

Haha, I actually did try to tinker with your scripts, but I kinda had a bit of a different idea of the workflow. The mouse-based focus should be optional, there should be a GUI menu for the settings, and I eventually want to make a few small actions for a lot of the zoom features so that users could compose them via the actions editor. Plus I'm not a good programmer, I couldn't really understand the scripts well, so I just cut the losses and decided to write something myself. It's been more way fun than I though, I haven't programmed in almost a year, so I was a bit worried.
nielsbohr3141 is offline   Reply With Quote
Old 01-29-2021, 03:06 PM   #7
FeedTheCat
Human being with feelings
 
FeedTheCat's Avatar
 
Join Date: May 2019
Posts: 501
Default

Yeah, I went a bit overboard trying to put everything into one script and it got pretty complicated in the process. Some functions of it could be useful in isolation though, like the ones in the Multi-edit stuff (scrollToNoteRow, zoomToPitchRange). Anyway, I'll be following your progress
FeedTheCat is offline   Reply With Quote
Old 01-30-2021, 06:30 AM   #8
cool
Human being with feelings
 
Join Date: Dec 2017
Location: Sunny Siberian Islands
Posts: 414
Default

Quote:
Originally Posted by nielsbohr3141 View Post
I messed up with that "link loop points to time selection" option after all, the script didn't check for that at the correct time. Might fix the problem above, but in any case this was definitely a bug.



Download v0.1.1:
https://github.com/nick-jn/nick-jn-r...000_v0.1.1.zip

Thank you! The script works well in the portable version of Reaper. In my config it only works as it should with "change_measures_externally = false" but that's quite enough for me.

But here's the question. Can a script center the playcursor (and/or item)? Now the script shifts the playcursor to the left after opening the ME. Thus, if I now click on the center of an item, after opening the ME, I will see only half of the item.

Last edited by cool; 01-30-2021 at 06:39 AM.
cool is offline   Reply With Quote
Old 01-30-2021, 07:42 AM   #9
nielsbohr3141
Human being with feelings
 
Join Date: Dec 2014
Posts: 25
Default

Version 0.2 is up.


https://github.com/nick-jn/nick-jn-r...Z9000.v0.2.zip


A very significant rewrite of the internals, now at least the code is half decent and can be worked on. Hopefully there are fewer bugs now too. The only new feature is the addition of an option that lets you open the item with respect to mouse cursor's location (it just temporarily shifts the edit cursor there and shifts it to closest measure to the right, and then restores the edit cursor to the original position).
nielsbohr3141 is offline   Reply With Quote
Old 01-30-2021, 07:50 AM   #10
nielsbohr3141
Human being with feelings
 
Join Date: Dec 2014
Posts: 25
Default

Quote:
Originally Posted by cool View Post
Thus, if I now click on the center of an item, after opening the ME, I will see only half of the item.

Not sure if I understand it 100%. The current behavior is this: a loop is created from the edit cursor's position to the right of it, N measures long. Then the MIDI editor engages the "zoom to project loop selection", which zooms horizontally to that loop.


Do you mean that if you open the script towards the end of the item, you don't want to see the empty space, that instead of showing you empty measures, the viewport should only show up to the very last measure of the item?



With regards to the external settings tool issue, try the newest version.
nielsbohr3141 is offline   Reply With Quote
Old 01-30-2021, 09:17 AM   #11
cool
Human being with feelings
 
Join Date: Dec 2017
Location: Sunny Siberian Islands
Posts: 414
Default

Quote:
Originally Posted by nielsbohr3141 View Post
Not sure if I understand it 100%. The current behavior is this: a loop is created from the edit cursor's position to the right of it, N measures long. Then the MIDI editor engages the "zoom to project loop selection", which zooms horizontally to that loop.


Do you mean that if you open the script towards the end of the item, you don't want to see the empty space, that instead of showing you empty measures, the viewport should only show up to the very last measure of the item?



With regards to the external settings tool issue, try the newest version.
Version 0.2 works for me in exactly the same way as the previous ones.



I took screenshots. When opening a short item (length <= the number of measures specified in the settings), I expect it to be fully visible.



What i expect:




What I get:


Also

Bug: when trying to use on a wave item, i get the error: helpers.lua:53: bad argument #1 to 'GetMediaItemTake_Item' (MediaItem_Take expected)
cool is offline   Reply With Quote
Old 01-30-2021, 10:00 AM   #12
nielsbohr3141
Human being with feelings
 
Join Date: Dec 2014
Posts: 25
Default

Quote:
Originally Posted by cool View Post
When opening a short item (length <= the number of measures specified in the settings), I expect it to be fully visible.
Oh yeah, this will definitely be implemented. But at this moment this is the expected behaviour.


I might also try to fiddle with centering small items (whose lengths are less than the amount of measures set in the settings) in the viewport when possible.



Quote:
Originally Posted by cool View Post
Bug: when trying to use on a wave item, i get the error: helpers.lua:53: bad argument #1 to 'GetMediaItemTake_Item' (MediaItem_Take expected)

Somehow I completely forgot about the existence of audio items Thanks! Apparently subprojects in arrange view are also a thing, so the script needs to treat all three options accordingly.
nielsbohr3141 is offline   Reply With Quote
Old 02-01-2021, 05:28 PM   #13
nielsbohr3141
Human being with feelings
 
Join Date: Dec 2014
Posts: 25
Default

MFZ9000 v0.3:


https://github.com/nick-jn/nick-jn-r...lease.v0.3.zip

Big update. Lots of improvements, lots more code, filesize has almost doubled. This is getting a bit above my pay grade, so bug reports are very welcome.

Overall, the project has blown up a bit too much, the whole thing turned out to be a can of worms, but that's just how it is with these thing. But it's getting close now to the functionality that I want. If none of the extra additions (and there were lots of those) have caused any major problems, then most of the functionality is implemented. What's left is to add a few bits and pieces (some extra actions like refocusing vertically to be used in the MIDI editor), and maybe a better GUI to change the settings. And to iron out the kinks, of course. I also need to figure out how to use git on Windows properly.



See the changes in the first post of the thread.
nielsbohr3141 is offline   Reply With Quote
Old 02-01-2021, 06:49 PM   #14
cool
Human being with feelings
 
Join Date: Dec 2017
Location: Sunny Siberian Islands
Posts: 414
Default

Thank you! Working fine for me. Good work.
One thing: script changes the arrange view zoom.


Also, maybe it will be more handy to publish the script through ReaPack? Now I have to rename files every time a new version appears.
And, little nitpick: now a simple (in terms of functionality) script contains five files and a folder. It is not quiet handy to place it in the scripts folder. I think if the script only contained one or two files, it would be easier to install and organize the files in the Scripts folder.


Bug: helpers.lua:119: bad argument #1 to 'GetMediaItemTake_Source' (MediaItem_Take expected) on the Empty Item.

Bug: pooled midi items opens as wave (Properties only).

Last edited by cool; 02-01-2021 at 07:01 PM.
cool is offline   Reply With Quote
Old 02-02-2021, 04:34 PM   #15
nielsbohr3141
Human being with feelings
 
Join Date: Dec 2014
Posts: 25
Default

Alright, v0.3.1 is up. Minor fixes, and I got Git working now, so no more messing with filenames with each release, now it's consistent. Hopefully I'll add a ReaPack repo soon so that the install/update can be as painless as it can be.

Quote:
Originally Posted by cool View Post
One thing: script changes the arrange view zoom.
Under what conditions does this happen? It shouldn't be possible since horizontal zooming is done via a MIDI editor command no. 40726 (zoom to project loop selection). It's scope should be confined to the MIDI editor.

Do you have synced timebases between MIDI editor and arrange view maybe? This will cause this behaviour.

Quote:
Originally Posted by cool View Post
Also, maybe it will be more handy to publish the script through ReaPack? Now I have to rename files every time a new version appears.
I've finally got Git running, so the releases will now have the same filenames. I just did a ghetto git thing before via copy pasting, but no more of that. The changes are pushed to the online repo as well.

As far as ReaPack... the experience has been beyond aggravating. Took me a good while to set it up (it's Windows' fault really, it's crap at the whole dev toolkit thing, and I had a bunch of stuff installed before that), then it took me a good while to figure out the documentation (which I didn't). I'm stuck, I've no idea how the tags work and how to organize and prep the whole thing properly. I'll try again later, but I'm done for now.

Quote:
Originally Posted by cool View Post
And, little nitpick: now a simple (in terms of functionality) script contains five files and a folder. It is not quiet handy to place it in the scripts folder
I'm not sure where the problem is. The files is _data are libraries, they're in a separate folder deliberately. Why aren't you putting it in a separate folder of its own like /Scripts/MFZ9000/the_contents_of_the_archive ?

Quote:
Originally Posted by cool View Post
Bug: ...
Fixed both, thanks!
nielsbohr3141 is offline   Reply With Quote
Old 02-02-2021, 08:51 PM   #16
cool
Human being with feelings
 
Join Date: Dec 2017
Location: Sunny Siberian Islands
Posts: 414
Default

Quote:
Originally Posted by nielsbohr3141 View Post
Do you have synced timebases between MIDI editor and arrange view maybe? This will cause this behaviour.
Ah. This.

Quote:
Originally Posted by nielsbohr3141 View Post
As far as ReaPack... the experience has been beyond aggravating. Took me a good while to set it up (it's Windows' fault really, it's crap at the whole dev toolkit thing, and I had a bunch of stuff installed before that), then it took me a good while to figure out the documentation (which I didn't). I'm stuck, I've no idea how the tags work and how to organize and prep the whole thing properly. I'll try again later, but I'm done for now.
Hmm. It's very simple. You just need to go to the page https://reapack.com/upload/reascript , log in via GitHub and that's it.

Quote:
Originally Posted by nielsbohr3141 View Post
I'm not sure where the problem is. The files is _data are libraries, they're in a separate folder deliberately. Why aren't you putting it in a separate folder of its own like /Scripts/MFZ9000/the_contents_of_the_archive ?
This is not a problem, of course. Just aesthetics and my personal convenience. As with a real desktop, one item is better than five.
cool is offline   Reply With Quote
Old 02-03-2021, 05:15 AM   #17
Vagelis
Human being with feelings
 
Join Date: Oct 2017
Location: Larisa, Greece
Posts: 1,081
Default

Thanks for the script, I'd like to ask, does it also work also for inline editor?
There's a problem with it that doesn't remember the previous zoom level when you open/close it.
Vagelis is online now   Reply With Quote
Old 02-03-2021, 02:57 PM   #18
nielsbohr3141
Human being with feelings
 
Join Date: Dec 2014
Posts: 25
Default

Quote:
Originally Posted by Vagelis View Post
Thanks for the script, I'd like to ask, does it also work also for inline editor?
There's a problem with it that doesn't remember the previous zoom level when you open/close it.
Nope, the inline editor is its own thing, it's separate from the MIDI editor.

Unfortunately, I've never used it, so I'm not at all familiar with the expected workflow. After toying around with it with for a little bit though, I'm not sure why keeping the vertical zoom constant is a desired behaviour.

Fwiw, if this is the only thing that you need, you can write a quick script of your own. The trick for keeping consistent zoom in the normal MIDI editor is simply zooming all the way out until you can't anymore, and then zooming in the desired amount of times. Hacky, but Reaper doesn't provide you with any other option at the moment.
nielsbohr3141 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 03:53 PM.


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