Old 01-13-2018, 12:32 AM   #1
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 2,643
Default Notation Text Events to Regions

MusicXML stores the chord names in Notation Events.
Just trying to work out how to get that info to set them as regions.
reaper.MIDI_GetAllEvts

there's some info here js_Notation - Select all notes that have customized display lengths or positions.lua


Last edited by MusoBob; 01-14-2018 at 01:14 PM.
MusoBob is offline   Reply With Quote
Old 01-15-2018, 02:03 PM   #2
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

I scribbled this very quickly, so it might not be perfect, but it would give you ideas of how to proceed.

Code:
reaper.Undo_BeginBlock2(0)
take = reaper.MIDIEditor_GetTake(reaper.MIDIEditor_GetActive())
reaper.MIDI_Sort(take)
MIDIOK, MIDI = reaper.MIDI_GetAllEvts(take, "")
tChords = {}
stringPos, ticks = 1, 0
while stringPos < MIDI:len() do
    offset, flags, msg, stringPos = string.unpack("i4Bs4", MIDI, stringPos)
    ticks = ticks + offset
    if msg:byte(1) == 0xFF then
        chord = msg:match("text (%w+)")
        if chord then
            tChords[#tChords+1] = {chord = chord, ticks = ticks}
        end
    end
end
tChords[#tChords+1] = {ticks = ticks}
for i = 1, #tChords do
    tChords[i].time = reaper.MIDI_GetProjTimeFromPPQPos(take, tChords[i].ticks)
end
for i = 1, #tChords-1 do
    reaper.AddProjectMarker2(0, true, tChords[i].time, tChords[i+1].time, tChords[i].chord, 0, ((tChords[i].chord):match("m") and 0x10000FF) or 0x1FF0000)
end
reaper.Undo_EndBlock2(0, "Convert chords to regions", -1)
juliansader is offline   Reply With Quote
Old 01-15-2018, 04:50 PM   #3
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 2,643
Default

Quote:
Originally Posted by juliansader View Post
I scribbled this very quickly.....
Just scribbled, i wish I could scribble like that !
It works great thanks for that. Just had to change below to match C/G C# etc..
Code:
        chord = msg:match("text (.+)")
MusoBob is offline   Reply With Quote
Old 02-03-2018, 05:19 AM   #4
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 2,643
Default

I need to do the reverse now:
Just trying to work out how to write the chord region_name to notation text events in the midi track so when it's exported from the notation window it will export the MusicXML chords.
I need to get the ppqpos from the start position of the region or current cursor position.

reaper.MIDI_GetPPQPos_StartOfMeasure(MediaItem_Take take, number ppqpos)
reaper.MIDI_InsertTextSysexEvt(MediaItem_Take take, boolean selected, boolean muted, number ppqpos, integer type, string bytestr)

Last edited by MusoBob; 02-03-2018 at 10:55 AM.
MusoBob is offline   Reply With Quote
Old 02-04-2018, 11:47 PM   #5
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 2,643
Default

Thanks to juliansader again https://forum.cockos.com/showthread.php?t=172789
https://forum.cockos.com/showpost.ph...7&postcount=33
Trial and error =
Code:
retval, isrgnOut, posOut, rgnendOut, region_name, markrgnindexnumberOut, colorOut = reaper.EnumProjectMarkers3(0, regionidx)
ppqpos = reaper.MIDI_GetPPQPosFromProjTime(take, cursor_pos)
reaper.MIDI_InsertTextSysexEvt(take, true, false, ppqpos, 0x0F, "TRAC text "..region_name)

Last edited by MusoBob; 02-05-2018 at 12:03 AM.
MusoBob is offline   Reply With Quote
Old 03-08-2020, 04:08 PM   #6
daeavelwyn
Human being with feelings
 
daeavelwyn's Avatar
 
Join Date: Dec 2014
Posts: 597
Default

Hi here !

Could you please post the last version of this script ? I'm struggling with an error "bad argument #1 to 'MIDI_Sort' (MediaItem_Take expected)"

Is there a way to make this script creates item notes on a selected track directly instead of creating regions I have to manually delete afterwards.
daeavelwyn is offline   Reply With Quote
Old 03-08-2020, 04:52 PM   #7
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 2,643
Default

So what are you trying to do ?
Do you have a musicxml file that you want the chord names from as item notes instead of regions ?

Custom Action:
X-Raym_Create text items on first selected track from regions.lua
SWS: Delete all regions
__________________
ReaTrakStudio Chord Track for Reaper forum
www.reatrak.com
STASH Downloads https://stash.reaper.fm/u/ReaTrak
MusoBob is offline   Reply With Quote
Old 03-08-2020, 04:57 PM   #8
daeavelwyn
Human being with feelings
 
daeavelwyn's Avatar
 
Join Date: Dec 2014
Posts: 597
Default

I'd like to get Chords from notation view to be displayed in a track as item notes and an easy way to update this track if I make changes in the notation editor.

Actually I use the following script (you posted on this thread : https://forum.cockos.com/showthread.php?t=197351 )

Code:
-- Notation Events Chords to Regions
-- juliansader https://forum.cockos.com/member.php?u=14710

reaper.Undo_BeginBlock2(0)
reaper.Main_OnCommand(40421,0) --Item: Select all items in track 40421
reaper.Main_OnCommand(40153,0) --Item: Open in built-in MIDI editor (set default behavior in preferences) 40153
take = reaper.MIDIEditor_GetTake(reaper.MIDIEditor_GetActive())
reaper.MIDI_Sort(take)
MIDIOK, MIDI = reaper.MIDI_GetAllEvts(take, "")
tChords = {}
stringPos, ticks = 1, 0
while stringPos < MIDI:len() do
    offset, flags, msg, stringPos = string.unpack("i4Bs4", MIDI, stringPos)
    ticks = ticks + offset
    if msg:byte(1) == 0xFF then
        chord = msg:match("text (.+)")
        if chord then
            tChords[#tChords+1] = {chord = chord, ticks = ticks}
        end
    end
end
tChords[#tChords+1] = {ticks = ticks}
for i = 1, #tChords do
    tChords[i].time = reaper.MIDI_GetProjTimeFromPPQPos(take, tChords[i].ticks)
end
for i = 1, #tChords-1 do
    -- Set Region Color RGB > reaper.ColorToNative(55,118,235)
    reaper.AddProjectMarker2(0, true, tChords[i].time, tChords[i+1].time, tChords[i].chord, 0, reaper.ColorToNative(55,118,235)|0x1000000) 
end
 reaper.Undo_EndBlock2(0, "Convert chords to regions", -1)
Then I use X-Raym script : "Script: X-Raym_Create text items on first selected track from regions.lua" and I get my track with my chords, but I have to manually delete the created regions (I make that with the region manager, select all new regions containing chords name en delete them)

I don"t want to delete all regions, just the last created from the script !!

An easier way to acheive this would be really appreciate !!

Last edited by daeavelwyn; 03-08-2020 at 05:03 PM.
daeavelwyn is offline   Reply With Quote
Old 03-08-2020, 06:32 PM   #9
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 2,643
Default

Select the musicxml item then select the track you want the chord text items on, you could make it insert a new track instead.

Code:
reaper.Undo_BeginBlock2(0)
--reaper.Main_OnCommand(40421,0) --Item: Select all items in track 40421
reaper.Main_OnCommand(40153,0) --Item: Open in built-in MIDI editor (set default behavior in preferences) 40153
take = reaper.MIDIEditor_GetTake(reaper.MIDIEditor_GetActive())
reaper.MIDI_Sort(take)
MIDIOK, MIDI = reaper.MIDI_GetAllEvts(take, "")
tChords = {}
stringPos, ticks = 1, 0
while stringPos < MIDI:len() do
    offset, flags, msg, stringPos = string.unpack("i4Bs4", MIDI, stringPos)
    ticks = ticks + offset
    if msg:byte(1) == 0xFF then
        chord = msg:match("text (.+)")
        if chord then
            tChords[#tChords+1] = {chord = chord, ticks = ticks}
        end
    end
end
tChords[#tChords+1] = {ticks = ticks}
for i = 1, #tChords do
    tChords[i].time = reaper.MIDI_GetProjTimeFromPPQPos(take, tChords[i].ticks)
end

-- CREATE TEXT ITEMS
-- text and color are optional
function CreateTextItem(track, start_pos, length, text, color)
    
  item = reaper.AddMediaItemToTrack(track)
  
  reaper.SetMediaItemInfo_Value(item, "D_POSITION", start_pos)
  reaper.SetMediaItemInfo_Value(item, "D_LENGTH", length)
  
  if text ~= nil then
    reaper.ULT_SetMediaItemNote(item, text)
  end
  
  if color ~= nil then
    reaper.SetMediaItemInfo_Value(item, "I_CUSTOMCOLOR", color)
  end
  
  return item

end

track = reaper.GetSelectedTrack(0, 0) -- Get selected track i
for i = 1, #tChords-1 do
    start_pos = tonumber(tChords[i].time)
    end_pos = tonumber(tChords[i+1].time)
    length = end_pos - start_pos
    text = tChords[i].chord
    color = reaper.ColorToNative(255,255,0)|0x1000000 -- Set Color (r,g,b)
    CreateTextItem(track, start_pos, length, text, color)
end
 reaper.MIDIEditor_OnCommand( reaper.MIDIEditor_GetActive(), 2 )
 reaper.Undo_EndBlock2(0, "Convert chords to text items", -1)
You could maybe modify the MPL Chord Region Editor to read the chord notation events
so as they are changed the should change in the display
__________________
ReaTrakStudio Chord Track for Reaper forum
www.reatrak.com
STASH Downloads https://stash.reaper.fm/u/ReaTrak

Last edited by MusoBob; 03-08-2020 at 06:49 PM.
MusoBob is offline   Reply With Quote
Old 03-09-2020, 06:16 AM   #10
daeavelwyn
Human being with feelings
 
daeavelwyn's Avatar
 
Join Date: Dec 2014
Posts: 597
Default

O_O !!! OMG !! You kill me man !! This script is just amazing !!

I will abuse but could you add a way to make item notes "stretch image/text" by default ?

I'm not sure what I should change in the MPL script, my programming skills are very poor :-s

[EDIT] Well, I got the Heda scripts that let me resize text
[EDIt 2] As I passed a very long time to find such a solution, I create a post dedicated to your work here : https://forum.cockos.com/showthread.php?p=2254593

Last edited by daeavelwyn; 03-09-2020 at 08:36 AM.
daeavelwyn is offline   Reply With Quote
Old 03-09-2020, 03:40 PM   #11
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 2,643
Default

If you're not displaying the Media item take name you can change the Media item label font:

chords.ttf

__________________
ReaTrakStudio Chord Track for Reaper forum
www.reatrak.com
STASH Downloads https://stash.reaper.fm/u/ReaTrak
MusoBob 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 11:23 AM.


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