/
core_midi_roll.lua
636 lines (494 loc) · 20 KB
/
core_midi_roll.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
-- @noindex
-- @description ReaperTon Midi Step Input
-- @version 1.3
-- @provides [nomain] .
function DBG(str)
--reaper.ShowConsoleMsg(str.."\n")
end
----------------------------------------------------------------------------------
function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
----------------------------------------------------------------------------------
function hasbit(x, p)
return x % (p + p) >= p
end
----------------------------------------------------------------------------------
function setbit(x, p)
return hasbit(x, p) and x or x + p
end
----------------------------------------------------------------------------------
function clearbit(x, p)
return hasbit(x, p) and x - p or x
end
----------------------------------------------------------------------------------
local function IsInMIDIEditor()
-- this is not as straight-forward as it should be.
-- you can have an active MIDI editor, but it's totally hidden & you're focused in the
-- arranger view. the only way I've found to detect this is:
return reaper.GetCursorContext() == -1
end
----------------------------------------------------------------------------------
local function IsMultipleOf(a, b, slop)
local d = a/b
local intPart,fract = math.modf(d + (slop / 2))
local ret = math.abs(fract) < math.abs(slop)
return ret
end
----------------------------------------------------------------------------------
-- mapping of QN durations and command IDs for midi editor and main window
-- GRID (midi editor):
-- 1 = 40204
-- 1/2 = 40203
-- 1/4 = 40201
-- 1/8 = 40197
-- 1/16 = 40192
-- 1/32 = 40190
-- 1/64 = 41020
-- GRID (main):
-- 1 = 40781
-- 1/2 = 40780
-- 1/4 = 40779
-- 1/8 = 40778
-- 1/16 = 40776
-- 1/32 = 40775
-- 1/64 = 40774
local gridDivisions = {
whole = { QN = 4, mecid = 40204, maincid = 40781, desc = "whole" },
half = { QN = 2, mecid = 40203, maincid = 40780, desc = "half" },
quarter = { QN = 1, mecid = 40201, maincid = 40779, desc = "quarter" },
eighth = { QN = 1/2, mecid = 40197, maincid = 40778, desc = "eighth" },
sixteenth = { QN = 1/4, mecid = 40192, maincid = 40776, desc = "sixteenth" },
thirtysecond = { QN = 1/8, mecid = 40190, maincid = 40775, desc = "thirtysecond" },
sixtyfourth = { QN = 1/16, mecid = 41020, maincid = 40774, desc = "sixtyfourth" },
}
-- returns one of the values in gridDivisions
local function findBestGridValueForTime(t, maxDivisionQN)
local beatsSinceMeasure, _, _, _, _ = reaper.TimeMap2_timeToBeats(0, t)
-- just pick a really small value to help rounding
local leewayQN = gridDivisions.sixtyfourth.QN / 8.;
if (gridDivisions.whole.QN <= maxDivisionQN) and IsMultipleOf(beatsSinceMeasure, gridDivisions.whole.QN, leewayQN) then
return gridDivisions.whole
elseif (gridDivisions.half.QN <= maxDivisionQN) and IsMultipleOf(beatsSinceMeasure, gridDivisions.half.QN, leewayQN) then
return gridDivisions.half
elseif (gridDivisions.quarter.QN <= maxDivisionQN) and IsMultipleOf(beatsSinceMeasure, gridDivisions.quarter.QN, leewayQN) then
return gridDivisions.quarter
elseif (gridDivisions.eighth.QN <= maxDivisionQN) and IsMultipleOf(beatsSinceMeasure, gridDivisions.eighth.QN, leewayQN) then
return gridDivisions.eighth
elseif (gridDivisions.sixteenth.QN <= maxDivisionQN) and IsMultipleOf(beatsSinceMeasure, gridDivisions.sixteenth.QN, leewayQN) then
return gridDivisions.sixteenth
elseif (gridDivisions.thirtysecond.QN <= maxDivisionQN) and IsMultipleOf(beatsSinceMeasure, gridDivisions.thirtysecond.QN, leewayQN) then
return gridDivisions.thirtysecond
elseif (gridDivisions.sixtyfourth.QN <= maxDivisionQN) and IsMultipleOf(beatsSinceMeasure, gridDivisions.sixtyfourth.QN, leewayQN) then
return gridDivisions.sixtyfourth
end
return nil
end
----------------------------------------------------------------------------------
-- accepts an item from gridDivisions
local function setGridDivision(divData)
if not divData then
--DBG("won't set grid division without data.")
return
end
if divData.mecid then
local midiEditor = reaper.MIDIEditor_GetActive()
local mode = reaper.MIDIEditor_GetMode(midiEditor)
if IsInMIDIEditor() and (mode ~= -1) then-- -1 if ME not focused
--DBG("running MIDI Editor command "..divData.mecid.." to change grid to "..divData.desc)
reaper.MIDIEditor_OnCommand(midiEditor, divData.mecid)
end
end
if divData.maincid then
--DBG("running Main command "..divData.maincid.." to change grid to "..divData.desc)
reaper.Main_OnCommand(divData.maincid, 0)
end
end
-- considers the length of the note we just entered. never allows
local function adjustGridToCursorAndInsertedNote(noteLengthQN)
local divData = findBestGridValueForTime(reaper.GetCursorPosition(), noteLengthQN)
setGridDivision(divData);
end
----------------------------------------------------------------------------------
function MoveEditCursorByGridSize(gridSteps)
local maincid = 40646-- left
local mecid = 40047
if gridSteps == 1 then
mecid = 40048
maincid = 40647
end
local midiEditor = reaper.MIDIEditor_GetActive()
local mode = reaper.MIDIEditor_GetMode(midiEditor)
if IsInMIDIEditor() and (mode ~= -1) then-- -1 if ME not focused
--DBG("running MIDI editor command "..mecid)
reaper.MIDIEditor_OnCommand(midiEditor, mecid)
return
end
--DBG("running MAIN command "..maincid)
reaper.Main_OnCommand(maincid, 0)
end
----------------------------------------------------------------------------------
local jsfx={} --store details of helper effect
jsfx.name="ReaperTon-MIDIChordState"
jsfx.fn="ReaperTon-MIDIChordState"-- filename
jsfx.paramIndex_Active = 0
jsfx.paramIndex_NotesInBuffer = 1
jsfx.paramIndex_NoteQueryIndex = 2
jsfx.paramIndex_NoteValue = 3
jsfx.paramIndex_Channel = 4
jsfx.paramIndex_Velocity = 5
jsfx.body=[[
desc:ReaperTon-MIDIChordState
slider1:0<0,1,1{On,Off}>Active (eats notes)
slider2:0<0,127,1>Notes in buffer
slider3:0<0,1000,1>Note Query Index
slider4:0<0,127,1>Output Pitch
slider5:0<0,15,1>Output channel
slider6:0<0,127,1>Output velocity
@init
notebuf=0; //start pos of buffer
nb_width=3; //number of entries per note
buflen=0; //notes in buffer
function addRemoveNoteFromBuffer(m1,m2,m3)
(
s = m1&$xF0;
c = m1&$xF; // channel
n = m2;// note
v = m3; // velocity
init_buflen=buflen;
i = -1;
while // look for this note|channel already in the buffer
(
i = i+1;
i < buflen && (notebuf[nb_width*i]|0 != n || notebuf[nb_width*i+1]|0 != c);
);
(s == $x90 && v > 0) ? // note-on, add to buffer
(
notebuf[nb_width*i] = n;
notebuf[nb_width*i+1] = c;
notebuf[nb_width*i+2] = v;
i == buflen ? buflen = buflen+1;
)
: // note-off, remove from buffer
(
i < buflen ?
(
memcpy(notebuf+nb_width*i, notebuf+nb_width*(i+1),
nb_width*(buflen-i-1)); // delete the entry
buflen = buflen-1;
);
);
buflen==init_buflen ? -1; //return value for nothing added/removed
);
@slider
p=slider3*nb_width; //position in buffer
slider4=notebuf[p]; // note
slider5=notebuf[p+1]; // channel
slider6=notebuf[p+2]; // velocity
@block
while (midirecv(offset,msg1,msg2,msg3))
(
(msg1&$xF0==$x90) ?
addRemoveNoteFromBuffer(msg1,msg2,msg3);
(msg1&$xF0==$x80) ?
addRemoveNoteFromBuffer(msg1,msg2,msg3);
slider2=buflen;
midisend(offset,msg1,msg2,msg3);
)
]]
----------------------------------------------------------------------------------
-- file op
local function createJSEffect(fn,str)
local file=io.open(reaper.GetResourcePath().."/Effects/"..fn, "w")
file:write(str)
file:close()
end
-- file op
local function deleteJSEffect(fx)
os.remove(reaper.GetResourcePath().."/Effects/"..fx.fn)
end
-- add the given fx to the given track.
local function getOrAddInputFx(track,fx,create_new)
local idx=reaper.TrackFX_AddByName(track,fx.name,true,1)
if idx==-1 or idx==nil then
idx=reaper.TrackFX_AddByName(track,fx.fn,true,1)
if (idx==nil or idx==-1) and create_new==true then
createJSEffect(fx.fn,fx.body)
idx=getOrAddInputFx(track,fx,false)
return idx
else
tr=nil
return -1
end
end
idx=idx|0x1000000 -- why the OR?
--reaper.TrackFX_SetEnabled(track, idx, true)
return idx
end
----------------------------------------------------------------------------------
-- returns the relevant take for the midi editor, or selected track, at edit cursor.
function findExistingTake()
local take = nil
local midiEditor = reaper.MIDIEditor_GetActive()
local mode = reaper.MIDIEditor_GetMode(midiEditor)
if IsInMIDIEditor() and (mode ~= -1) then-- -1 if ME not focused
--DBG("In MIDI editor; mode "..mode)
take = reaper.MIDIEditor_GetTake(midiEditor)
if reaper.ValidatePtr(take, 'MediaItem_Take*') then--check that it's an actual take (in case of empty MIDI editor)
return take
end
DBG("no valid current take in midi editor.")
end
-- attempt to find take by selected track / cursor pos.
--DBG("attempt to find take by selected track / cursor pos.")
local selectedTrackCount = reaper.CountSelectedTracks(0)
if selectedTrackCount < 1 then
DBG("no selected track anyway...")
return nil
end
local track = reaper.GetSelectedTrack(0, 0)
local cursorPos = reaper.GetCursorPosition()
-- todo: is there a more efficient way to search for a media item
local mediaItemCount = reaper.CountTrackMediaItems(track)
for i = 0, mediaItemCount - 1 do
local mediaItem = reaper.GetTrackMediaItem(track, i)
local pos = reaper.GetMediaItemInfo_Value(mediaItem, "D_POSITION")-- in TIME
local len = reaper.GetMediaItemInfo_Value(mediaItem, "D_LENGTH")
-- fudge it a bit.
local fudge = 0.002
pos = pos - fudge
len = len + fudge + fudge
--DBG("media item "..i.." / pos "..pos.." / len "..len.." / cursorpos "..cursorPos)
if cursorPos >= pos and cursorPos <= (pos + len) then
DBG("found a media item.")
return reaper.GetActiveTake(mediaItem)
else
--DBG("media item not suitable. cursor "..cursorPos.." is not within ("..pos.." , "..pos+len..")")
end
end
return nil
end
local function createTake(takeStart, takeEnd)
local selectedTrackCount = reaper.CountSelectedTracks(0)
if selectedTrackCount < 1 then
DBG("no selected track to create a take...")
return nil
end
local track = reaper.GetSelectedTrack(0, 0)
local newItem = reaper.CreateNewMIDIItemInProj(track, takeStart, takeEnd)
return reaper.GetActiveTake(newItem)
end
-- TECHNICALLY, this has a bug.
-- "media item end time" is different than "midi item extents". midi items can have a longer
-- length than their "extent".
local function ensureTakePosLastsUntil(take, requestedEndTime)
local mediaItem = reaper.GetMediaItemTake_Item(take)
local existingStartTime = reaper.GetMediaItemInfo_Value(mediaItem, "D_POSITION")
local existingLength = reaper.GetMediaItemInfo_Value(mediaItem, "D_LENGTH")
local existingEndTime = existingStartTime + existingLength
if(existingEndTime >= requestedEndTime) then
--DBG("not adjusting take length. "..existingEndTime.." >= "..requestedEndTime)
return
end
local existingStartQN = reaper.TimeMap2_timeToQN(0, existingStartTime)
local newEndQN = reaper.TimeMap2_timeToQN(0, requestedEndTime)
-- DBG("Adjusting take length because "..existingEndTime.." < "..requestedEndTime)
-- DBG(" existingEndTime: "..existingEndTime)
-- DBG(" requestedEndTime: "..requestedEndTime)
-- DBG(" existingStartTime: "..existingStartTime)
-- DBG(" existingStartQN: "..existingStartQN)
-- DBG(" newEndQN: "..newEndQN)
reaper.MIDI_SetItemExtents(mediaItem, existingStartQN, newEndQN)
end
-- returns begin, end time for the measure
local function SnapToMeasure(time)
local beatsSinceMeasure, _, cml, fullbeats, _ = reaper.TimeMap2_timeToBeats(0, time)
local measureStartBeats = fullbeats - beatsSinceMeasure
local measureStart = reaper.TimeMap2_beatsToTime(0, measureStartBeats)
local nextMeasureStart = reaper.TimeMap2_beatsToTime(0, measureStartBeats + cml)
return measureStart, nextMeasureStart
end
-- returns an array of { note, chan, velocity }
function getHeldNotes(track)
local iHelper = getOrAddInputFx(track, jsfx, true)
-- read the notes of the helper fx
local heldNoteCount = reaper.TrackFX_GetParam(track, iHelper, jsfx.paramIndex_NotesInBuffer)
if heldNoteCount < 1 then
return {}
end
local pitches={}
for i = 1, heldNoteCount, 1 do
reaper.TrackFX_SetParam(track, iHelper, jsfx.paramIndex_NoteQueryIndex, i - 1)
-- now the plugin updates its sliders to give us the values for this index.
pitches[#pitches+1] = {}
pitches[#pitches].note, _, _ = reaper.TrackFX_GetParam(track, iHelper, jsfx.paramIndex_NoteValue)
pitches[#pitches].chan = reaper.TrackFX_GetParam(track, iHelper, jsfx.paramIndex_Channel)
pitches[#pitches].velocity = reaper.TrackFX_GetParam(track, iHelper, jsfx.paramIndex_Velocity)
--DBG(" held note "..pitches[#pitches].note.." / vel "..pitches[#pitches].velocity)
end
return pitches
end
----------------------------------------------------------------------------------
-- returns an array of { index, pitch, velocity, channel, startPPQ, endPPQ }, sorted from top to bottom
function getNotesStartingAtCursor(take, track)
-- basically enum notes and find ones that start near the cursor
local cursorTime = reaper.GetCursorPosition();
local cursorPPQ = reaper.MIDI_GetPPQPosFromProjTime(take, cursorTime)
--Lua: integer retval, number notecntOut, number ccevtcntOut, number textsyxevtcntOut
local ret, noteCount, _, _ = reaper.MIDI_CountEvts(take)
-- let's build a list of note indices corresponding to the notes you're holding down
-- at the same time, figure out the duration of those notes. for simplicity, just take the first duration.
local notes = {}
for i = 0, noteCount - 1 do
local _, _, _, startPPQ, endPPQ, channel, pitch, velocity = reaper.MIDI_GetNote(take, i)
--DBG("is note "..i..", ")
if math.abs(startPPQ - cursorPPQ) < 5 then
notes[#notes + 1] = {
index = i,
pitch = pitch,
velocity = velocity,
channel = channel,
startPPQ = startPPQ,
endPPQ = endPPQ
}
end
end
table.sort(notes, function(a, b)
return a.pitch > b.pitch
end);
return notes
end
function getStuffAtCursor()
local take = findExistingTake()
local cursorTime = reaper.GetCursorPosition();
-- create take if needed
if not take then
local noteStartQN = reaper.TimeMap2_timeToQN(0, cursorTime)
local noteEndTime = reaper.TimeMap2_QNToTime(0, noteStartQN + reaper.MIDI_GetGrid(take))
take = createTake(takeStart, takeEnd)
end
local track = reaper.GetMediaItemTake_Track(take)
-- find the notes in the current take corresponding to that.
-- basically enum notes and find ones that end near the cursor AND are being held
local cursorPPQ = reaper.MIDI_GetPPQPosFromProjTime(take, cursorTime)
--Lua: integer retval, number notecntOut, number ccevtcntOut, number textsyxevtcntOut
local ret, noteCount, _, _ = reaper.MIDI_CountEvts(take)
--DBG("count events? ret="..ret..", noteCount="..noteCount)
-- let's build a list of note indices corresponding to the notes you're holding down
-- at the same time, figure out the duration of those notes. for simplicity, just take the first duration.
local noteIndexesBehind = {}
local noteIndexesBeween = {}
local noteIndexesAhead = {}
for i = 0, noteCount - 1 do
local _, selected, muted, startppq, endppq, _, pitch, _ = reaper.MIDI_GetNote(take, i)
--DBG("note "..i.." startppq="..startppq.." endppq="..endppq.." cursorppq="..cursorPPQ.." pitch="..pitch)
if math.abs(endppq - cursorPPQ) < 5 then
-- DBG("Added note "..i.." startppq="..startppq.." endppq="..endppq.." cursorppq="..cursorPPQ.." pitch="..pitch)
noteIndexesBehind[#noteIndexesBehind + 1] = i
elseif startppq < cursorPPQ and cursorPPQ < endppq then
noteIndexesBeween[#noteIndexesBeween + 1] = i
elseif math.abs(cursorPPQ-startppq) < 5 then
noteIndexesAhead[#noteIndexesAhead + 1] = i
end
end
return take, track, noteIndexesBehind, noteIndexesBeween, noteIndexesAhead, cursorTime, cursorPPQ
end
function cleanNotesWithZeroLenght(track, take)
local ret, noteCount, _, _ = reaper.MIDI_CountEvts(take)
for i = noteCount - 1, 0, -1 do
local _, selected, muted, startppq, endppq, _, pitch, _ = reaper.MIDI_GetNote(take, i)
--DBG("Cleanup "..startppq.." end "..endppq.." sum "..endppq-startppq.." pitch "..pitch)
if(endppq-startppq <=1) then
-- DBG("MIDI_DeleteNote "..i)
reaper.MIDI_DeleteNote(take, i)
end
end
end
function insertOrModifyHeldNotesByGrid(gridSteps)
local take, track, noteIndexesBehind, noteIndexesBeween, noteIndexesAhead, cursorTime, cursorPPQ = getStuffAtCursor()
--TODO break this super function into chuncks?
local heldPitches = getHeldNotes(track)
-- this bit fixes undo
local item = reaper.GetMediaItemTake_Item(take)
reaper.MarkTrackItemsDirty(track, item)
local startPPQ = reaper.MIDI_GetPPQPosFromProjTime(take, cursorTime)
MoveEditCursorByGridSize(gridSteps)
if #heldPitches == 0 then
return
end
local newEndTime = reaper.GetCursorPosition()
local newEndPPQ = reaper.MIDI_GetPPQPosFromProjTime(take, newEndTime)
-- ensure the take is big enough to hold the new duration. snap it.
local _, takeEnd = SnapToMeasure(newEndTime)
ensureTakePosLastsUntil(take, takeEnd)
--TODO replace the three gigant loops below with only one that iterates trough the heldPithes
--and instead of removing from heldPithces create unextendedPitches array
-- check if notes ahead are in the way and mark them for deletion
if #noteIndexesAhead >0 then
DBG("Notes ahead")
for i = 1, #noteIndexesAhead do
if #heldPitches > 0 then
local _, noteSelected, noteMuted, noteStartppq, noteEndppq, noteChan, notePitch, noteVel = reaper.MIDI_GetNote(take, noteIndexesAhead[i])
for index,v in pairs(heldPitches) do
if (v.note == notePitch) and (gridSteps>0) then
reaper.MIDI_SetNote(take, noteIndexesAhead[i], false, nil, noteStartppq, noteStartppq, nil, nil, nil, nil)
break
end
end
end
end
end
-- modify existing held notes
if #noteIndexesBehind >0 then
DBG("Notes behind extend")
for i = 1, #noteIndexesBehind do
local _, noteSelected, noteMuted, noteStartppq, noteEndppq, noteChan, notePitch, noteVel = reaper.MIDI_GetNote(take, noteIndexesBehind[i])
if #heldPitches > 0 then
for index,v in pairs(heldPitches) do
if (v.note == notePitch) and (v.chan == noteChan) and (v.velocity == noteVel or gridSteps<0) then
reaper.MIDI_SetNote(take, noteIndexesBehind[i], false, nil, nil, newEndPPQ, nil, nil, nil, nil)
table.remove(heldPitches, index)
break
end
end
end
end
end
-- check if on top of playing notes and split them
if #noteIndexesBeween >0 then
for i = 1, #noteIndexesBeween do
if #heldPitches > 0 then
local _, noteSelected, noteMuted, noteStartppq, noteEndppq, noteChan, notePitch, noteVel = reaper.MIDI_GetNote(take, noteIndexesBeween[i])
for index,v in pairs(heldPitches) do
if (v.note == notePitch) and (gridSteps>0) then
reaper.MIDI_SetNote(take, noteIndexesBeween[i], nil, nil, nil, startPPQ, nil, nil, nil, nil)
break
elseif (v.note == notePitch) and (gridSteps<0) then
reaper.MIDI_SetNote(take, noteIndexesBeween[i], nil, nil, nil, newEndPPQ, nil, nil, nil, nil)
break
end
end
end
end
end
--cleanup aka delete all notes with very small lenght
cleanNotesWithZeroLenght(track, take)
-- insert remaining notes if advancing curosr
local mediaItem = reaper.GetMediaItemTake_Item(take)
reaper.UpdateItemInProject(mediaItem)
if #heldPitches > 0 and gridSteps>0 then
-- you're holding notes on your MIDI keyboard; add them to the take
DBG("New notes insert")
local noteStartPPQ = startPPQ-- convert to PPQ
local noteEndPPQ = newEndPPQ-- convert to PPQ
-- insert them.
for k,v in pairs(heldPitches) do
--DBG(" inserting note "..v.note.." from ["..noteStartPPQ.." -> "..noteEndPPQ.."]")
reaper.MIDI_InsertNote(take, false, false, noteStartPPQ, noteEndPPQ, v.chan, v.note, v.velocity)
end
reaper.UpdateItemInProject(mediaItem)-- make certain the project bounds has been updated to reflect the newly recorded item
end
end
function deleteHeldNotesUnderCursor()
end