Old 09-11-2019, 08:18 PM   #1
wwcdgm
Human being with feelings
 
Join Date: Oct 2018
Posts: 17
Default How to split notes in the length of ticks

Hello everyone, I am learning to write a lua script. The function of the script is to select the note and split the note according to the set tick length.

Here is the script:

Code:
function Msg(param)
	reaper.ShowConsoleMsg(tostring(param) .. "\n")
end

reaper.ShowConsoleMsg("")

local editor = reaper.MIDIEditor_GetActive()
local take = reaper.MIDIEditor_GetTake(editor)
retval, notes, ccs, sysex = reaper.MIDI_CountEvts(take)

local j = 240 -- tick

function Notes()

	for i = 0,  notes-1 do
		
		retval, sel, muted, ppq_start, ppq_end, chan, pitch, vel = reaper.MIDI_GetNote( take, i )
		if sel == true then

			note_len = ppq_end - ppq_start -- Get the length of the note
			num_cuts = math.floor(note_len/j) -- Number of split obtained
			
			
			for k=1,num_cuts do
				Msg("k = "..k)
				
				
				reaper.MIDI_InsertCC(take, false, false, ppq_start + j, 224, 0, 0, 64) -- Here is a test. Insert CC, it works fine.
				xxx -- How to split notes in every 240 ticks position
				
				ppq_start = math.floor(ppq_start + j) -- From the beginning of the note, add a tick of 240(j = 240) each time, and cut when added.
				
				
				reaper.SetEditCurPos( ppq_start, 0, 0 )
				Msg("split position = "..ppq_start)
			end

		end
		i=i+1
	end

end

Notes()


reaper.UpdateArrange()
reaper.SN_FocusMIDIEditor()

Last edited by wwcdgm; 10-31-2019 at 11:59 AM.
wwcdgm 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 02:30 PM.


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