Jump to content

CAL Script to select every second MIDI note


J. King

Recommended Posts

Hello everyone!  Wondering if someone can help me out with a CAL script to select every second note in the piano roll when working with MIDI.

When editing drums, kick lets say, it would be awesome if every second midi note could be selected so I could easily drop them in a new spot to trigger a different sample (same kick tuned slightly different for realism).  I've been doing this manually forever, has to be a workaround in this day and age hahaha.  Grok spit this code out but I was getting a CAL error 5 Unknown variable Note.Selected

 

(do
  (int noteCount 0)
  (forEachEvent
    (if (== Event.Kind NOTE)
      (do
        (++ noteCount)
        (if (== (% noteCount 2) 1)
          (= Note.Selected 1)
          (= Note.Selected 0)
        )
      )
    )
  )
)

 

Searched forums, found the "Are CAL scripts doomed?" Please do not rid of these gang, infinite time savers!  Any help would be appreciated if someone can get this working 🍻

(Just realized this becomes faster doing this in the event list but still a Run CAL could make it quicker!)

 

Link to comment
Share on other sites

Two things:

1.  There's no such thing as Note - you probably meant Event
2.  Neither Note.Selected or Event.Selected is a thing.  You can't actually select individual events using CAL, as the selection is the thing forEachEvent is iterating over.  You can select whole tracks using CAL using TrackSelect, but not individual events.

Link to comment
Share on other sites

Thanks for the reply.  Yes, event is the proper term.  So the long and short is you have to do this manually...  It did dawn on me that this is a lot faster in the "Event List" view so I'll take the win there.  I could also tweak filters in the Drum Replacer - Copy MIDI events and when pasting it'll give me 3 different MIDI events.  Appreciate the help

Link to comment
Share on other sites

Try this CAL script.  (one I wrote for this very purpose)  

It prompt you for nth note to select, defaults to 2

(do
    (int note_number 1)
    (int even 0)
    (int nth 2)
    (getInt nth "Please enter nth note" 2 50)
    (forEachEvent
        (if (== Event.Kind NOTE)
            (do
                (= even (% note_number nth))
                (if (== even 1)
                    (do
                    );exit do
                    (do
                        (delete)
                        (insert Event.Time Event.Chan NOTE Note.Key Note.Vel Note.Dur)
                    )
                );exit if
                (++ note_number)    
            );exit do
        );exit if
    );exit for 
);exit do

  • Like 1
  • Thanks 2
  • Great Idea 1
Link to comment
Share on other sites

20 minutes ago, Promidi said:

Try this CAL script.  (one I wrote for this very purpose)  

It prompt you for nth note to select, defaults to 2

(do
    (int note_number 1)
    (int even 0)
    (int nth 2)
    (getInt nth "Please enter nth note" 2 50)
    (forEachEvent
        (if (== Event.Kind NOTE)
            (do
                (= even (% note_number nth))
                (if (== even 1)
                    (do
                    );exit do
                    (do
                        (delete)
                        (insert Event.Time Event.Chan NOTE Note.Key Note.Vel Note.Dur)
                    )
                );exit if
                (++ note_number)    
            );exit do
        );exit if
    );exit for 
);exit do

Aha - a clever solution... delete the note then add it again so the new one isn't selected.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...