Old 01-05-2017, 04:18 AM   #1
TonE
Human being with feelings
 
Join Date: Feb 2009
Location: Reaper HAS send control via midi !!!
Posts: 4,031
Default _____

_____

Last edited by TonE; 02-28-2017 at 01:46 PM.
TonE is offline   Reply With Quote
Old 01-05-2017, 04:55 AM   #2
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

Might be just me, but I don't understand the post. I do get that you'd like to have some tutorials, but what does eg "from item to pitch" mean? And what's a superfolder? (Edit, ahh, you probably mean parent, right?)

Maybe a few explanations about what it is you want to know could help here.
gofer is offline   Reply With Quote
Old 01-05-2017, 06:21 AM   #3
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

I think he just wants explanations of how to get certain information and work with it.

First, all the MIDI functions need to know what item (called "take" here) you're working in:
Code:
cur_wnd = reaper.MIDIEditor_GetActive()
cur_take = reaper.MIDIEditor_GetTake(cur_wnd)
Then you need some notes to work with:
Code:
-- Get all of the selected notes
local sel_notes = {}
	
local cur_note = -2
local note_val
while cur_note ~= -1 do
		
	cur_note = reaper.MIDI_EnumSelNotes(cur_take, cur_note)
	if cur_note == -1 then break end
	cur_arr = {reaper.MIDI_GetNote(cur_take, cur_note)}
	table.remove(cur_arr, 1)
	table.insert(sel_notes, cur_arr)
	
end
reaper.MIDI_EnumSelNotes gives you every selected note, one at a time, in a bit of a strange way - you tell it "I've got the fourth note already" and it says "okay, here's the fifth note", and so on until it runs out of notes to give you.

We've now got a table, cur_arr, that contains a subtable for each selected note with these values:
Code:
retval, selectedOut, mutedOut, startppqposOut, endppqposOut, chanOut, pitchOut, velOut reaper.MIDI_GetNote(current_take, selected_note)
retval isn't super useful once you've got the note, so you can see in the code above that I used table.remove to just clear that value from all of the subtables.

Now we can get information about each note simply by accessing the appropriate field of the subtable:
Code:
[1] - Is the note selected, true/false
[2] - Is the note muted, true/false
[3] - Note start position, measured in PPQ
[4] - Note end position, measured in PPQ
[5] - MIDI channel
[6] - MIDI note number
[7] - MIDI velocity
Code:
local pitch_of_note_20 = cur_arr[20][6]
Converting from a MIDI note number to the actual pitch class just takes some division. The % operator is the same as mod, that is, a math operation called modulo. a % b takes a / b and gives you the remainder:
Code:
pitch_class = cur_note % 12
Changing a MIDI note's values is just a matter of changing the appropriate value in our table, and then using reaper.MIDI_SetNote to copy/paste our new values onto the original note.
Code:
reaper.MIDI_SetNote( take, noteidx, selectedInOptional, mutedInOptional, startppqposInOptional, endppqposInOptional, chanInOptional, pitchInOptional, velInOptional, noSortInOptional )
You don't actually need to copy all of the values - just the ones you're changing. Any of the above values that you set as nil in the function arguments, or omit, will remain as they were.

Code:
cur_arr[20][6] = cur_arr[20][6] + 7

reaper.MIDI_SetNote( cur_take, 20, nil, nil, nil, nil, nil, cur_arr[20][6])
If you're changing multiple notes' parameters in one go, it's more efficient to use the noSort option on each one, and then tell Reaper to sort them afterward:
Code:
 for i = 1, #cur_arr do
    reaper.MIDI_SetNote( cur_take, i, nil, nil, nil, nil, nil, cur_arr[i][6], nil, true)
end

reaper.MIDI_Sort(cur_take)
As for your other questions, I'd recommend using the search box on X-Raym's API documentation page: http://www.extremraym.com/cloud/reascript-doc/

Between that and Ctrl+F, it's usually not too hard to find what you need.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 01-05-2017, 10:38 AM   #4
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Quote:
I'd recommend using the search box on X-Raym's API documentation page: http://www.extremraym.com/cloud/reascript-doc/

Between that and Ctrl+F, it's usually not too hard to find what you need.
Anyway, all I'm seeing is this:
reaper.BR_SetMediaItemImageResource( item, imageIn, imageFlags )
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 01-05-2017, 12:10 PM   #5
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Another helpful thing to do when figuring out how to make something work with the API is open an .rpp in your text editor and see exactly what's going on. Here are two items with the same image resource, but one has it in Notes and the other one has it as the item background.
Code:
    <ITEM
      POSITION 4.5
      SNAPOFFS 0
      LENGTH 13.5
      LOOP 1
      ALLTAKES 0
      FADEIN 4 0 0 4 0 1
      FADEOUT 4 0 0 4 0 -1
      MUTE 0
      SEL 0
      IGUID {368F4B18-6699-4C1F-B371-4AC94797D43E}
      IID 2
      RESOURCEFN "F:\Adam\Pictures\reaper midi name bug.png"
      IMGRESOURCEFLAGS 0
    >
    <ITEM
      POSITION 20
      SNAPOFFS 0
      LENGTH 13.5
      LOOP 1
      ALLTAKES 0
      FADEIN 4 0 0 4 0 1
      FADEOUT 4 0 0 4 0 -1
      MUTE 0
      SEL 1
      IGUID {014DB2EB-2DB4-4840-BE56-85C96EBAD315}
      IID 2
      RESOURCEFN "F:\Adam\Pictures\reaper midi name bug.png"
      IMGRESOURCEFLAGS 1
    >
The only difference is the resource flag. 0 puts it in Notes, 1 sets it as the background.

retval, imageOut, imageFlagsOut reaper.BR_GetMediaItemImageResource( item ) tells you the flag, and the Set function lets you change it. Easy peasy, I would think.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 01-05-2017, 03:48 PM   #6
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

In the thread title and the OP you asked for tutorials and examples, but now you seem to just be asking for scripts. I don't mind doing it, but now it feels like I wasted twenty minutes this morning writing that post above.

Anyway, these should be available on ReaPack in a few minutes:
Lokasenna_Toggle item under mouse cursor's image between notes and background.lua
Lokasenna_Toggle selected item's image between notes and background.lua

One small bug that I can't solve - they won't Undo correctly.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate

Last edited by Lokasenna; 01-05-2017 at 07:25 PM.
Lokasenna is offline   Reply With Quote
Old 01-05-2017, 06:22 PM   #7
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

Nope, no waste, Lokasenna. Much appreciated little lecture

If I knew about % modulo, I've got the feeling my pitch class script could be about 80% (percent, not modulo) shorter. Should have slept less back in the math lessons . I also learned some additional bits and pieces about tables and didn't know about the nil thing. Let's see if I can apply these ideas to eel as well... or decide to rather switch over to lua.
gofer 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 06:11 AM.


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