Old 09-25-2022, 09:26 PM   #1
Tod
Human being with feelings
 
Tod's Avatar
 
Join Date: Jan 2010
Location: Kalispell
Posts: 14,759
Default MIDI insert CC events

If possible I would like a script that will do this at the current edit cursor position:

Insert CC event selectable 01 to 127 (CC_NUM)
With selectable Values 0 to 127 (CC_VALUE)
Channel #s 1 to 16

These values would all be set up for editing in a text editor like notepad++.

It would be great and much appreciated if this could be done, I checked ReaPack and couldn't find anything, and there's currently nothing in the actions list, not that I could find anyway.

And a message to all you Reaper scripters, there's no doubt in my mind, that your efforts are appreciated by all Reaperites, and I also believe that your scripts put Reaper way beyond any other DAW. Thankyou.
Tod is offline   Reply With Quote
Old 09-26-2022, 07:04 PM   #2
Tod
Human being with feelings
 
Tod's Avatar
 
Join Date: Jan 2010
Location: Kalispell
Posts: 14,759
Default

So is this hard to do? Maybe that's why it hasn't been done before?
Tod is offline   Reply With Quote
Old 09-27-2022, 10:42 AM   #3
lunker
Human being with feelings
 
lunker's Avatar
 
Join Date: Nov 2007
Location: Lucas, TX, USA (via Luleå, Sweden)
Posts: 2,008
Default

Hi Tod,

The code to insert a CC event in the active MIDI item at the cursor is pretty straight forward.

I'm confused about what you want to do with the text file.

Your initial sentence says you want to insert a single CC at the cursor. If I were doing that, I would pop up a dialog box with blanks for the user to fill in the three parameters (CC#, value, channel). That seems a lot easier than having to create a text file, and then browse to it when you run the function. Unless you want the name of the file hard-coded into the function, and you plan edit the file every time you want to insert a new CC event -- that seems like a hassle.

Is your eventual goal to insert several CC events in one go, which is why you want them in the text file?
__________________
Best Regards, Ernie "lunker" Lundqvist
BDSM (Bad Dog Studio Musicians)
Windows 10 running on Z390 + i7-8700

Last edited by lunker; 09-27-2022 at 10:52 AM.
lunker is offline   Reply With Quote
Old 09-27-2022, 05:00 PM   #4
Tod
Human being with feelings
 
Tod's Avatar
 
Join Date: Jan 2010
Location: Kalispell
Posts: 14,759
Default

Quote:
Originally Posted by lunker View Post
Hi Tod,

The code to insert a CC event in the active MIDI item at the cursor is pretty straight forward.

I'm confused about what you want to do with the text file.

Your initial sentence says you want to insert a single CC at the cursor. If I were doing that, I would pop up a dialog box with blanks for the user to fill in the three parameters (CC#, value, channel). That seems a lot easier than having to create a text file, and then browse to it when you run the function. Unless you want the name of the file hard-coded into the function, and you plan edit the file every time you want to insert a new CC event -- that seems like a hassle.

Is your eventual goal to insert several CC events in one go, which is why you want them in the text file?
Hi Ernie, and thanks for your reply.

Yeah, its a bit more complicated then just putting CC events where the Edit cursor is.

Right now I have Custom macros for sending the cursor to the front of the selected main note, adding a CC event, then moving left 3 ticks and adding a keyswitch, plus placing 2 different CC events in that position. This is already working.

However, due to a bug in Reaper, or maybe Kontakt, I need to add CC events 1 tick apart starting from the front of the keyswitch to 2 tics beyond the main note.

I do have a script for placing CC events, but it only works in conjunction with a selected note.

I have discussed this with Justin and after a few back and forths, we decided I might be able to fix this in the script I've written for Kontakt. However, after trying many things in my Kontakt script, I was unsuccessful.

I only mentioned text files to indicate I want to input the CC values I need in notepad++.

Once again Ernie, thankyou.
Tod is offline   Reply With Quote
Old 09-27-2022, 05:31 PM   #5
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 2,008
Default

Code:
 
-- Settings 
local channel = 1 -- 1 based
local cc = 1 
local value = 127
local offset = 0 -- offset from current cursor position in ticks

---Iterate this function it will return the takes open in midi_editor window. editable_only == get only the editables 
---@param midi_editor midi_editor midi_editor window
---@param editable_only boolean If true get only takes that are editable in midi_editor 
---@return function iterate takes
function enumMIDITakes(midi_editor, editable_only)
    local i = -1
    return function()
        i = i + 1
        return reaper.MIDIEditor_EnumTakes(midi_editor, i, editable_only)
    end
end

local midi_editor = reaper.MIDIEditor_GetActive()
local position = reaper.GetCursorPosition()

for take in enumMIDITakes(midi_editor, true) do
    local ppq = reaper.MIDI_GetPPQPosFromProjTime(take, position)
    local bol = reaper.MIDI_InsertCC( take, false, false, ppq+offset, 176, channel-1, cc, value)
    reaper.MIDI_Sort(take)
end
daniellumertz is offline   Reply With Quote
Old 09-27-2022, 05:38 PM   #6
Tod
Human being with feelings
 
Tod's Avatar
 
Join Date: Jan 2010
Location: Kalispell
Posts: 14,759
Default

Quote:
Originally Posted by daniellumertz View Post
Code:
 
-- Settings 
local channel = 1 -- 1 based
local cc = 1 
local value = 127
local offset = 0 -- offset from current cursor position in ticks

---Iterate this function it will return the takes open in midi_editor window. editable_only == get only the editables 
---@param midi_editor midi_editor midi_editor window
---@param editable_only boolean If true get only takes that are editable in midi_editor 
---@return function iterate takes
function enumMIDITakes(midi_editor, editable_only)
    local i = -1
    return function()
        i = i + 1
        return reaper.MIDIEditor_EnumTakes(midi_editor, i, editable_only)
    end
end

local midi_editor = reaper.MIDIEditor_GetActive()
local position = reaper.GetCursorPosition()

for take in enumMIDITakes(midi_editor, true) do
    local ppq = reaper.MIDI_GetPPQPosFromProjTime(take, position)
    local bol = reaper.MIDI_InsertCC( take, false, false, ppq+offset, 176, channel-1, cc, value)
    reaper.MIDI_Sort(take)
end
Wow Daniel, could this be it? It looks good and I'll be trying it right away.

It also has an "offset", very interesting.

What kind of extension should I use for this?
Tod is offline   Reply With Quote
Old 09-27-2022, 06:03 PM   #7
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 2,008
Default

no extensions need! hope I could match what you needed, but if it don't, just write back
daniellumertz is offline   Reply With Quote
Old 09-27-2022, 07:06 PM   #8
Tod
Human being with feelings
 
Tod's Avatar
 
Join Date: Jan 2010
Location: Kalispell
Posts: 14,759
Default

Quote:
Originally Posted by daniellumertz View Post
no extensions need! hope I could match what you needed, but if it don't, just write back
I had a chance to check it out and it's working great Daniel. I ended up saving it as LUA script and that works just fine. I didn't expect the offset and that's a very big part of it.

Thank you so much Daniel.
Tod is offline   Reply With Quote
Old 09-27-2022, 10:46 PM   #9
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 2,008
Default

if you want I can also prompt the user for the configs each time you run the script with an window where you can specify all configs
daniellumertz is offline   Reply With Quote
Old 09-28-2022, 03:39 PM   #10
Tod
Human being with feelings
 
Tod's Avatar
 
Join Date: Jan 2010
Location: Kalispell
Posts: 14,759
Default

Quote:
Originally Posted by daniellumertz View Post
if you want I can also prompt the user for the configs each time you run the script with an window where you can specify all configs
That's a wonderful offer Daniel, I don't need it for what I'm using it for now, but it is a great script that has many, if not all of the variables needed for working with CC events.

If it's not a big deal, it might be useful for others too.
Tod 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 07:35 AM.


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