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