MIDI Technique: Contrary Motion

Author
jsg
Max Output Level: -69 dBFS
  • Total Posts : 1079
  • Joined: 2003/11/20 04:54:18
  • Location: San Francisco, California
  • Status: offline
2016/11/14 15:55:50 (permalink)

MIDI Technique: Contrary Motion

For a long time I wanted a MIDI routine that would take a melodic line and invert it (contrary motion) so that each interval would be a mirror of its original form.  A very common technique used in all styles of music.   Sonar developers have never gotten around to it, so I hired a programmer to create a CAL routine for this. 
 
I'd like to share it with Sonar users, some of you may find it very useful when composing, I know I do....
 
Best,
Jerry
www.jerrygerber.com
 
Here it is:  copy and paste the complete text into a text file and rename the file "Contrary Motion.cal"
****************************************************
;; ContraryMotion.cal - (c)2010 Dallas Hodgson. (MINI version)
;;
;; This CAL script inverts the melodic contour of a monophonic MIDI note
;; sequence beginning from the 2nd note on, for example:
;;
;; F4 (note 53), Bb4 (note 58), C5 (note 60), D5 (note 62) will become
;; F4 (note 53), C4 (note 48), Bb (note 47), Ab (note 45)
;;;
;; Note that running this chromatic script an even number of times over a MIDI
;; sequence is guaranteed to leave it untouched.
;;
;; Dallas Hodgson
;; rockisland@iname.com
;; www.dallashodgson.info

(do
    (include "need20.cal")    ; Require version 2.0 or higher of CAL

    (int lastKey -1)
    (int lastContraryKey -1)
    (int keyDelta -1)
    
    (forEachEvent
        (if (== Event.Kind NOTE)
           (do     
               ;; special case setup for the very first note
               (if (== lastKey -1)
                   (do
                       (= lastKey Note.Key)               
                       (= lastContraryKey Note.Key)
                       (= keyDelta 0)
                   )
               )
 
               ;; Compute rise or fall in pitch of current unshifted note over previous unshifted note (ex: if current note is C62 and last note was C60, keyDelta = 2)
               (= keyDelta (- Note.Key lastKey))
                   
            ;; debug msg            
               ;; (pause Note.Key keyDelta lastKey lastContraryKey isDiatonic fixDir)

            (= lastKey Note.Key)
                    
               ;; Apply contrary motion to current note relative to previous contrary note. (ex: If it went up by 2 semitones, make it go down 2 semitones etc.)
               (= Note.Key (- lastContraryKey keyDelta))
               
               (= lastContraryKey Note.Key)
           );; enddo
        );; endif
    );; endfor
);; enddo


********************************************************************88
post edited by jsg - 2016/11/14 16:19:51
#1

3 Replies Related Threads

    Zargg
    Max Output Level: 0 dBFS
    • Total Posts : 10666
    • Joined: 2014/09/28 04:20:14
    • Location: Norway
    • Status: offline
    Re: MIDI Technique: Contrary Motion 2016/11/14 16:06:54 (permalink)
    Thanks, Jerry!
    Will give it a try.
    All the best.

    Ken Nilsen
    Zargg
    BBZ
    Win 10 Pro X64, Cakewalk by Bandlab, SPlat X64, AMD AM3+ fx-8320, 16Gb RAM, RME Ucx (+ ARC), Tascam FW 1884, M-Audio Keystation 61es, *AKAI MPK Pro 25, *Softube Console1, Alesis DM6 USB, Maschine MkII
    Laptop setup: Win 10 X64, i5 2.4ghz, 8gb RAM, 320gb 7200 RPM HD, Focusrite Solo, + *
     
    #2
    John
    Forum Host
    • Total Posts : 30467
    • Joined: 2003/11/06 11:53:17
    • Status: offline
    Re: MIDI Technique: Contrary Motion 2016/11/14 16:23:52 (permalink)
    Great work and very thoughtful to think of the forum.
     

    Best
    John
    #3
    Brando
    Max Output Level: -47.5 dBFS
    • Total Posts : 2776
    • Joined: 2003/11/06 11:47:20
    • Location: Canada
    • Status: offline
    Re: MIDI Technique: Contrary Motion 2016/11/14 19:15:57 (permalink)
    Thanks Jerry. Appreciate your generosity.

    Brando
    Cakewalk, Studio One Pro, Reaper
    Presonus Audiobox 1818VSL
    ASUS Prime Z370-A LGA1151, 32GB DDR4, Intel 8700K i7, 500 GB SSD, 3 x 1TB HDD, Windows 10 Pro 64
    #4
    Jump to:
    © 2025 APG vNext Commercial Version 5.1