Old 10-28-2021, 01:15 PM   #41
paaltio
Human being with feelings
 
Join Date: Aug 2011
Location: Los Angeles, CA
Posts: 308
Default

By the way has the situation changed regarding the playback start issue, or is it still a problem to determine where the latest playthrough starts?

The Cubase behavior seems the most correct when using retrospective record during playback, i.e. the buffer gets cleared every time you start playing after hitting play.
paaltio is online now   Reply With Quote
Old 10-28-2021, 01:39 PM   #42
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
Default

Quote:
Originally Posted by paaltio View Post
By the way has the situation changed regarding the playback start issue, or is it still a problem to determine where the latest playthrough starts?

The Cubase behavior seems the most correct when using retrospective record during playback, i.e. the buffer gets cleared every time you start playing after hitting play.
Yes, internal buffer clearing is also planned (though it will not be actually cleared, only filtered for adding).
mpl is offline   Reply With Quote
Old 10-28-2021, 02:04 PM   #43
paaltio
Human being with feelings
 
Join Date: Aug 2011
Location: Los Angeles, CA
Posts: 308
Default

Quote:
Originally Posted by mpl View Post
Yes, internal buffer clearing is also planned (though it will not be actually cleared, only filtered for adding).
Sounds great, thanks!
paaltio is online now   Reply With Quote
Old 11-01-2021, 07:53 AM   #44
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

There's a function missing for flushing the buffer. Will make a FR for that later.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 12-04-2022, 07:52 AM   #45
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 565
Default

I came across this issue about MIDI_GetRecentInputEvent
Code:
local retval, buf, ts, devIdx, projPos, projLoopCnt = reaper.MIDI_GetRecentInputEvent(0)
local stateCur, keyCur=string.byte(buf,1), string.byte(buf,2)
At first it worked, but after a while, suddenly the stateCur value was always 128, even I was keep pressing the midi key(built in virtual midi keyboard). Then I restart Reaper, and it became normal again. I'm not sure if it happend after I woke up the system from sleep(Win10).
dsyrock is offline   Reply With Quote
Old 01-18-2024, 11:25 AM   #46
cool
Human being with feelings
 
Join Date: Dec 2017
Location: Sunny Siberian Islands
Posts: 957
Default

Guys, hello! I apologize for the necroposting, I found this topic in Google.

Is there a way inside the Defer function to get NoteOff data “in real time”? I see that the data for each subsequent note arrives sequentially, but I have absolutely no idea how to separate the notes in the stream and assign NoteOff (releasing the key of one note while another is playing, for example) to the notes individually.
cool is offline   Reply With Quote
Old 01-18-2024, 01:49 PM   #47
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Quote:
Originally Posted by cool View Post
Guys, hello! I apologize for the necroposting, I found this topic in Google.

Is there a way inside the Defer function to get NoteOff data “in real time”? I see that the data for each subsequent note arrives sequentially, but I have absolutely no idea how to separate the notes in the stream and assign NoteOff (releasing the key of one note while another is playing, for example) to the notes individually.
Something like this:
Code:

---Get MIDI input. Use for get MIDI between defer loops.
---@param midi_last_retval number need to store the last MIDI retval from MIDI_GetRecentInputEvent. Start the script with `MIDILastRetval = reaper.MIDI_GetRecentInputEvent(0)` and feed it here. Optionally pass nill here and it will create a global variable called "MIDILastRetval_Hidden" and manage that alone. 
---@return table midi_table midi table with all the midi values. each index have another table = {msg = midi message, ts = time, device = midi device idx}
---@return number midi_last_retval updated reval number.
function GetMIDIInput(last_retval)
    local idx = 0
    local first_retval
    local midi_table = {}
    local is_save_hidden_retval -- if not last_retval then it will save it in a global variable MIDILastRetval_Hidden and use it later

    -- if last_retval == true then it will manage the retval alone.
    if not last_retval then
        if not MIDILastRetval_Hidden then
            MIDILastRetval_Hidden = reaper.MIDI_GetRecentInputEvent(0)
            last_retval = MIDILastRetval_Hidden
        else 
            last_retval = MIDILastRetval_Hidden
        end
        is_save_hidden_retval = true
    end
    -- Get all recent inputs
    while true do
        local retval, msg, ts, device_idx = reaper.MIDI_GetRecentInputEvent(idx)
        if idx == 0 then
            first_retval = retval
        end

        if retval == 0 or retval == last_retval then
            last_retval = first_retval
            if is_save_hidden_retval then 
                MIDILastRetval_Hidden = first_retval
            end
            return midi_table, last_retval
        end
        midi_table[#midi_table+1] = {msg = msg, ts = ts, device = device_idx}
        
        idx = idx + 1
    end
end

---Unpack a packed string MIDI message in different values
---@param msg string midi as packed string
---@return number msg_type midi message type: Note Off = 8; Note On = 9; Aftertouch = 10; CC = 11; Program Change = 12; Channel Pressure = 13; Pitch Vend = 14; text = 15. 
---@return number msg_ch midi message channel 1 based (1-16)
---@return number data2 databyte1 -- like note pitch, cc num
---@return number data3 databyte2 -- like note velocity, cc val. Some midi messages dont have databyte2 and this will return nill. For getting the value of the pitchbend do databyte1 + databyte2
---@return string text if message is a text return the text
---@return table allbytes all bytes in a table in order, starting with statusbyte. usefull for longer midi messages like text
function UnpackMIDIMessage(msg)
    local msg_type = msg:byte(1)>>4
    local msg_ch = (msg:byte(1)&0x0F)+1 --msg:byte(1)&0x0F -- 0x0F = 0000 1111 in binary. this is a bitmask. +1 to be 1 based

    local text
    if msg_type == 15 then
        text = msg:sub(3)
    end

    local val1 = msg:byte(2)
    local val2 = (msg_type ~= 15) and msg:byte(3) -- return nil if is text
    return msg_type,msg_ch,val1,val2,text,msg
end

function loop()
    local midi_in = GetMIDIInput()
    for k, midi_table in ipairs(midi_in) do
        --midi_table:
            --msg: string midi message
            --ts: n time
            --device: n midi device idx
        local type, ch, data1, data2 = UnpackMIDIMessage(midi_table.msg)
        if type == 9 and data2 ~= 0 then -- filter note ON
            print('note:', data1)
        elseif type == 8 or type == 9 and data2 == 0 then -- filter note OFF
            print('noteoff:', data1)
        end
    end
    reaper.defer(loop)
end
reaper.defer(loop)
daniellumertz is offline   Reply With Quote
Old 01-18-2024, 11:40 PM   #48
cool
Human being with feelings
 
Join Date: Dec 2017
Location: Sunny Siberian Islands
Posts: 957
Default

Quote:
Originally Posted by daniellumertz View Post
Something like this:
code
Thank you! Looks quite complicated, I'll try to figure it out.
At least I see that the script allows to get independent NoteOffs, this is good news for me.
cool 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:22 AM.


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