Old 11-08-2018, 06:15 PM   #1
Steviebone
Human being with feelings
 
Join Date: Jul 2018
Posts: 809
Default Tiled MIDI clip thumbnails

I have a question regarding reapers scripting capability. I am a programmer with some experience over many years albeit probably a bit outdated at this point in some regards. While I've written literally millions of lines of code and am quite familiar with programming principles I have not tried to write any scripts for reaper yet. But I'm hoping to dust off my skill set and jump in. I have one particular process I would like to address first. Before I do I have a couple of questions.

I'm not a drummer. I've had fairly good success manipulating MIDI items that have been recorded by drummers. In a project I'm currently involved in I have a set of musically related MIDI performances usually 1 to 4 measures, most of them a single measure. They are stacked into one item as a set of takes. There are hundreds of takes that are grouped together in segments/number ranges. I have revised a few existing scripts to enable me to navigate them for auditioning. This works but can be somewhat tedious when I'm trying to find something specific. Even though I can jump around to specific groups, stepping through the range one at a time is slow and inefficient.

I would like to be able to audition clips visually. What I mean by that is that I would like to be able to see a group of short MIDI drum clips in a tiled thumbnail type of display. The thumbnails don't have to be large as I can generally see the kick drum and snare in general beat pattern at a glance. So if I'm looking for something that needs to have the kick on certain beats I can weed out a lot of clips I won't need to audibly audition.

So would the reaper internals support display of the clips like this? For example, I would like to be able to pop up a window that display rows of 1 measure clips like thumbnails and then select one for audition while reaper is looping. This would greatly speed up my process.

Thanks in advance for any suggestions/feedback.
Steviebone is offline   Reply With Quote
Old 11-09-2018, 09:56 AM   #2
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default

Yes, that's possible.

Have a look at the "gfx." commands to see what's available for graphics. You could make the thumbnails with just a bunch of rects and lines. You'd need to parse the MIDI takes to get note positions for drawing and then set active MIDI take with mouse clicks.
snooks is offline   Reply With Quote
Old 11-09-2018, 10:37 AM   #3
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default

Here's something to give you some context. It let's you select an active take from a MIDI item using a crappy thumbnail view that doesn't have any info or content, but which does have some lovely lines to show where the beats are if there was MIDI drawn in there.

Code:
gfx.init("MIDI Picker", 500, 500)

local MARGIN = 20
local THUMB_WIDTH = 130
local THUMB_HEIGHT = 100

-- guards to return if no MIDI items selected
if reaper.CountSelectedMediaItems(0) == 0 then return end
local item = reaper.GetSelectedMediaItem(0, 0)
local take = reaper.GetActiveTake(item)
-- need SWS for this next line
if not reaper.BR_IsTakeMidi(take) then return end

--
local function createThumbnail(x, y, midi_take)
  local thumbnail = {}
  thumbnail.x = x
  thumbnail.y = y
  thumbnail.midi_take = midi_take
  gfx.r, gfx.g, gfx.b, gfx.a = 0, 1, 1, .5
  gfx.roundrect(x, y, THUMB_WIDTH, THUMB_HEIGHT, 10, 255)
  local barline_spacing = THUMB_WIDTH * .25 -- assumes 4 beats
  for i = 1, 3 do
    gfx.x, gfx.y, gfx.a = x + barline_spacing * i, y, .25
    gfx.lineto(gfx.x, gfx.y + THUMB_HEIGHT)
  end
  return thumbnail
end


thumbnails = {}
for i = 1, reaper.GetMediaItemNumTakes(item) do
  local take = reaper.GetMediaItemTake(item, i - 1)
  local t = createThumbnail(MARGIN + (THUMB_WIDTH + 20) * (i - 1), 20, take)
  thumbnails[#thumbnails + 1] = t
end

--
local function main()
  if prev_mouse_cap & 1 == 0 and gfx.mouse_cap & 1 == 1 then 
    for i = 1, #thumbnails do
      local t = thumbnails[i]
      if gfx.mouse_x >= t.x and gfx.mouse_x < t.x + THUMB_WIDTH and
         gfx.mouse_y >= t.y and gfx.mouse_y < t.y + THUMB_HEIGHT then
        reaper.SetActiveTake(t.midi_take)
        reaper.UpdateArrange()
      end
    end
  end
  prev_mouse_cap = gfx.mouse_cap
  reaper.defer(main)
end

prev_mouse_cap = gfx.mouse_cap

main()
snooks is offline   Reply With Quote
Old 11-09-2018, 11:58 AM   #4
Arthur McArthur
Human being with feelings
 
Arthur McArthur's Avatar
 
Join Date: Sep 2016
Location: Toronto
Posts: 749
Default

This sounds interesting, I could probably use this too!
Arthur McArthur is offline   Reply With Quote
Old 11-09-2018, 12:06 PM   #5
Steviebone
Human being with feelings
 
Join Date: Jul 2018
Posts: 809
Default

Thank you for the replies. Sounds complex for my first attempt at Reaper programming but what the heck! Now that I know it's possible I will endeavor to better educate myself. It may take a minute, I only have an hour or so a day to devote to programming unfortunately. I'm sure I'll have some more questions soon.
Steviebone is offline   Reply With Quote
Old 11-09-2018, 12:09 PM   #6
Steviebone
Human being with feelings
 
Join Date: Jul 2018
Posts: 809
Default

Quote:
Originally Posted by snooks View Post
Yes, that's possible.

Have a look at the "gfx." commands to see what's available for graphics. You could make the thumbnails with just a bunch of rects and lines. You'd need to parse the MIDI takes to get note positions for drawing and then set active MIDI take with mouse clicks.
So there is no internal command to simply display a midi take, I would need to parse each midi item and draw the notes myself? Sorry I guess that's redundant given your reply...
Steviebone is offline   Reply With Quote
Old 11-09-2018, 03:34 PM   #7
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default

Yeah, there's no realistic other way that I can think of. Maybe somebody has done something along these lines who could share code?
snooks is offline   Reply With Quote
Old 11-10-2018, 07:10 AM   #8
TonE
Human being with feelings
 
Join Date: Feb 2009
Location: Reaper HAS send control via midi !!!
Posts: 4,032
Default

Can svg be used for visuals? As it is only text, generation might be easier, who knows?
TonE 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 05:24 AM.


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