• SONAR
  • How to remove duplicate midi notes with Undupe CAL? (p.2)
2015/08/24 03:13:51
icontakt
I just did some more testing and it seems that Undupe ignores the first set of overlapped notes in the selection when no other events exist before them.
In other words, it's better to merge all MIDI clips in the track before using this script.
2015/08/24 03:15:00
scook
As I said, the script can be simplified. The time window setting is not particularly intuitive either.
2015/08/24 03:20:53
scook
icontakt
In other words, it's better to merge all MIDI clips in the track before using this script.

Keep in mind CAL predates lanes and layers. Only MIDI tracks existed when CAL was developed.
2015/08/24 03:31:11
icontakt
scook
Did you try changing the time window?

 
Just did it, and got the same results.
 
scook
As I said, the script can be simplified. The time window setting is not particularly intuitive either.

 
I haven't looked into the script, but if it's not easy for me to fix I'll just merge all clips before unduping.
 
scook
icontakt
In other words, it's better to merge all MIDI clips in the track before using this script.

Keep in mind CAL predates lanes and layers. Only MIDI tracks existed when CAL was developed.


 
Yes, but I only used one lane in the test above.
 
 
Anyway, I thought Undupe got broken sometime this year (because I only tried it on one set of duplicated notes when I posted #5). I'm glad it didn't. I'm OK with the workaround.
2015/08/24 07:17:58
twelvetone
I am working through the Cakewalk Application Language Programming Guide.pdf
I made some test scripts which successfully change Now, track titles, get the event kind, etc.
So fundamentally, CAL is there and still works.
 
The scripts seem to be divided into 2 types:
1) Ones with author details inside. These have filenames that conform to the DOS 8.3 all-caps format and appear to to originate from a competition held in 1991. Each author has an ID and seems keen to publish personal details. All of these have a 3-part structure comprising 3 do-blocks which, in some file comments, are identified as Prolog, Body and Epilog. UNDUPE.CAL is one of these, the attribution is however a bit vague. It only states "Maybe Miguel Ratton".
 
2) Ones with no author in the comments. These have mixed-case long names. None have originator or  author info.
These are also structurally different in that they have a single do block and most have looping statements such as while and, significantly, forEachEvent.
 
There is one from this group that stands out: Split Note to Tracks.cal in that it has in the comments:
Courtesy Red Nile Productions 1993
Modified Greg Hendershott at user's request 12/10/93
 
There is also a script called need20.cal which is called up by many other scripts. All it does is check whether the CAL engine is version 2.0 or higher. (X3 is 100 = v10.0)
 
I am not deep enough into CAL yet but my guess is that the older scripts conform to this 3-block Prolog-Body-Epilog idiom which carries with it an implied looping and that this is now superseded by explicit looping statements, which may explain why icontakt finds only one note is being deleted from a selected range in UNDUPE.CAL. (Although I am not getting it to delete ANY yet...)
 
Having said that, I am finding that I can play with the 3-block idiom and it does seem to work to some degree.
 
I have found no mention of the 3-block idiom in the document so far, so this is all speculation at this point.
 
2015/08/24 07:26:20
twelvetone
It would be useful to know whether track lanes and layers have been assigned identifiers. Tricky, because scripts could exist using these names already.
 
CAL is pretty powerful, just as UNDUPE.CAL demonstrates.
 
It would be nice to have a documentation. It needn't be a LISP programming course, just document the reserved and key words, and give some sample code.
2015/08/24 12:16:29
scook
I downloaded the CAL Editor years ago not for editor but for the "CAL Reference.chm"
No worked examples but a nice concise reference.
2015/08/24 13:06:21
twelvetone
Curious. The help files open, but if you click on anything in the left tree control, the right side text window remains blank.
 
OK, I now tried on Windows XP. They work. But not on Windows 8.1, evidently.
 
scook, as ever, thanks so much for the support. Got something to do this weekend now.
2015/08/24 13:08:30
scook
I am still on Win7
2015/08/24 13:24:39
scook
Here is a different take on removing duplicate notes. Did not test it much. Functionally similar to UNDUPE.CAL
; rmdupes.cal
; scook 2015

; set up variables and get user input
(do
 (dword lastTime 0)
 (int lastKey 0)
 (int nDeleted 0)
 (int timeWindow 0)

; If a note starts this number of ticks before or after the current note
; and is the same pitch, it is considered a duplicate.
 (getInt timeWindow "Time (in ticks) to determine dupes:" 0 32767))

; Loop through the selected events. NOTE: the current implementation
; of SONAR (2015) does not reset the start if the script is aborted. IOW,
; if the script is aborted, reselect the values to start over.
(do
 ; Only process notes
 (if (== Event.Kind NOTE)
     (do
      ; Check if the note is the same key as the previous note and
      ; fall within the time range provided. If it meets these criteria
      ; delete the note otherwise remember the note time and key
      ; for the next comparison.
      (if (&& (== Note.Key lastKey)
          (&& (>= Event.Time (- lastTime timeWindow))
          (<= Event.Time (+ lastTime timeWindow))))
      (do
       (delete)
       (++ nDeleted))
    (do
     (= lastTime Event.Time)
     (= lastKey Note.Key))))))
; report
(do
 (pause "Deleted " nDeleted " duplicate notes."))
© 2026 APG vNext Commercial Version 5.1

Use My Existing Forum Account

Use My Social Media Account