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.
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)
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 **
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.
Also, I tried to advance only 16th notes with the C key. Image with rests.
** * The X key is also batting such as closing the window, and sometimes it does not work well ... a mystery. ** **
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.
――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