[PYTHON] Script that changes the length of the sound with REAPER

Introduction

About 20 years ago, I was stepping in Logic There is a function to extend the length of the sound with the TAB key, A memo that I thought that a REAPER script could do something similar. output.gif

script

tatAddLength.py


RPR_ClearConsole()

midieditor = RPR_MIDIEditor_GetActive()
take = RPR_MIDIEditor_GetTake( midieditor )

notecntOut = 0
ccevtcntOut = 0
textsyxevtcntOut = 0

( retval, take, notecntOut, ccevtcntOut, textsyxevtcntOut ) = RPR_MIDI_CountEvts(take, notecntOut, ccevtcntOut, textsyxevtcntOut )

noteidx = notecntOut-1  #last note
selectedOut = True
mutedOut = True
startppqposOut = 0
endppqposOut = 0
chanOut = 0
pitchOut = 0
velOut = 0

( retval, take, noteidx, selectedOut, mutedOut, startppqposOut, endppqposOut, chanOut, pitchOut, velOut ) = RPR_MIDI_GetNote(take, noteidx, selectedOut, mutedOut, startppqposOut, endppqposOut, chanOut, pitchOut, velOut )

retval = RPR_MIDI_SetNote( take, noteidx, True, mutedOut, startppqposOut, endppqposOut+240, chanOut, pitchOut, velOut, False )

adjust = 0.125 * 120/RPR_TimeMap2_GetDividedBpmAtTime(0,0.125) # Tempo
RPR_MoveEditCursor(adjust, False)

Points that do not go well

Is the unit for extending the sound different from the unit for moving the cursor?

--Change the length of the sound

retval = RPR_MIDI_SetNote( take, noteidx, True, mutedOut, startppqposOut, endppqposOut+240, chanOut, pitchOut, velOut, False )

The value specified by SetNote is a MIDI resolution value called QN. Since the 16th note is the main note, 240 is added in a fixed manner.

** * QN can be handled musically and musically without depending on the tempo. On the other hand, it is necessary to refer to the global tempo to convert it to real time. ** **

960 = quarter note 480 = eighth note 240 = 16th note

--Move the cursor

adjust = 0.125 * 120/RPR_TimeMap2_GetDividedBpmAtTime(0,0.125) # Tempo
RPR_MoveEditCursor(adjust, False)

MoveEditCursor ... I don't really understand this.

By trial and error, I feel that if I put 1 at BPM120, it advances by 1 beat. I thought it was time, and even if I tried QNTotTime or something like that, it was different ...

RPR_TimeMap2_GetDividedBpmAtTime(0,0.125) Returns the same value as the tempo, so start from 120 and Now that I have the length of one beat, I multiply it by 1/4 to make it 16th note length. ** * I'm not sure if it fits here **

Key setting

Perhaps the TAB key systematically switches views, so assigning shortcuts doesn't feel good. (It doesn't work well even if assigned) So, this time I decided to use the X of the lower left key. I often use Ctr-Z when I make a mistake.

image.png

Also, I tried to advance only 16th notes with the C key. Image with rests.

image.png

** * The X key is also batting such as closing the window, and sometimes it does not work well ... a mystery. ** **

It ’s a little different, but I ’m generally satisfied.

At the time of Logic, it was to stretch the sound (the length is uncertain) before the note-off came, so it was also a chord. In REAPER, only the last note recorded is extended.

Grid compatible

――I fixed the 16th note, but I wonder if it can be changed here. To fit the grid.

( grid, take,  swingOutOptional,  noteLenOutOptional) = RPR_MIDI_GetGrid(take, 0, 0)

retval = RPR_MIDI_SetNote( take, noteidx, True, mutedOut, startppqposOut, endppqposOut+960*grid, chanOut, pitchOut, velOut, False )

adjust = grid * 60/RPR_TimeMap2_GetDividedBpmAtTime(0,0.25) # Tempo

Is it like this?

tatAddLengthGrid.py


RPR_ClearConsole()

midieditor = RPR_MIDIEditor_GetActive()
take = RPR_MIDIEditor_GetTake( midieditor )

notecntOut = 0
ccevtcntOut = 0
textsyxevtcntOut = 0

( retval, take, notecntOut, ccevtcntOut, textsyxevtcntOut ) = RPR_MIDI_CountEvts(take, notecntOut, ccevtcntOut, textsyxevtcntOut )

noteidx = notecntOut-1  #last note
selectedOut = True
mutedOut = True
startppqposOut = 0
endppqposOut = 0
chanOut = 0
pitchOut = 0
velOut = 0

( retval, take, noteidx, selectedOut, mutedOut, startppqposOut, endppqposOut, chanOut, pitchOut, velOut ) = RPR_MIDI_GetNote(take, noteidx, selectedOut, mutedOut, startppqposOut, endppqposOut, chanOut, pitchOut, velOut )


( grid, take,  swingOutOptional,  noteLenOutOptional) = RPR_MIDI_GetGrid(take, 0, 0)

retval = RPR_MIDI_SetNote( take, noteidx, True, mutedOut, startppqposOut, endppqposOut+960*grid, chanOut, pitchOut, velOut, False )

adjust = grid * 60/RPR_TimeMap2_GetDividedBpmAtTime(0,0.25) # Tempo
RPR_MoveEditCursor(adjust, False)

ToDo: -Allow it to be extended with the pedal (This is MIDI, but what should I do if it accidentally explodes when the mode is different? I want it to work only when stepping in) --Something like erasing while returning --Chord support (this seems to be possible if applied to the same start note as the last note)

Recommended Posts

Script that changes the length of the sound with REAPER
A Python script that compares the contents of two directories
Shell script (Linux, macOS) that outputs the date of the last week
Debug the script with Sakura Editor
The story of making a module that skips mail with python
A story that visualizes the present of Qiita with Qiita API + Elasticsearch + Kibana
Phenomenon that the numerical value changes slightly with Pandas and its response
The story of making a sound camera with Touch Designer and ReSpeaker
The result of making the first thing that works with Python (image recognition)
Get the return value of an external shell script (ls) with python3
Change the length of Python csv strings
This and that of the inclusion notation.
Align the size of the colorbar with matplotlib
Script to change the description of fasta
Execute Python script with cron of TS-220
Check the existence of the file with python
The third night of the loop with for
The second night of the loop with for
Count the number of characters with echo
The advantages and disadvantages of Django that people with one year of experience think
Around the authentication of PyDrive2, a package that operates Google Drive with Python
With LINEBot, I made an app that informs me of the "bus time"
The story of the learning method that acquired LinuC Level 1 with only ping -t
Python script that makes UTF-8 files with all BOMs under the folder without BOMs
Note that the calculation of average pairwise correlation was very easy with pandas
A model that identifies the guitar with fast.ai
The story of doing deep learning with TPU
Note: Prepare the environment of CmdStanPy with docker
Prepare the execution environment of Python3 with Docker
Shortening the analysis time of Openpose using sound
[Note] Export the html of the site with python.
See the behavior of drunkenness with reinforcement learning
zsh settings that facilitate the use of virtualenv
Increase the font size of the graph with matplotlib
Calculate the total number of combinations with python
Check the date of the flag duty with Python
Eliminate the inconveniences of QDock Widget with PySide
Challenge the Tower of Hanoi with recursion + stack
Script to tweet with multiples of 3 and numbers with 3 !!
Fill the browser with the width of Jupyter Notebook
Predict the second round of summer 2016 with scikit-learn
Dump the contents of redis db with lua
Tucker decomposition of the hay process with HOOI
Find out the day of the week with datetime
The basis of graph theory with matplotlib animation
Visualize the behavior of the sorting algorithm with matplotlib
Convert the character code of the file with Python3
One-liner that outputs 10000 digits of pi with Python
[Python] Determine the type of iris with SVM
The story that fits in with pip installation
Python script to get note information with REAPER
A python script that generates a sample dataset for checking the operation of a classification tree
A python script that gets the number of jobs for a specified condition from indeed.com
A script that combines margins when pasting a number of graphs on tiles with gnuplot
A script that can perform stress tests according to the number of CPU cores
The theory that the key to controlling infection with the new coronavirus is hyperdispersion of susceptibility
Here is one of the apps with "artificial intelligence" that I was interested in.
Try to create a waveform (audio spectrum) that moves according to the sound with python
It seems that the module of train_test_split changes from 0.20, and Deprecation Warning appears at 0.18.
A script that keeps looking up until the URL is bookmarked with Hatena Bookmark
A script that pings the registered server and sends an email with Gmail a certain number of times when it fails