More on playing real midi notes

80 views
Skip to first unread message

George

unread,
Mar 27, 2023, 6:38:26 PM3/27/23
to Extempore
Hello all

;; I did some experimenting in pattern language playing vectors of pairs of real midi
;; notes which differ by small amounts. Like this for example:
; (:> test1 4 0 (play samp1 @1 80 dur) '(#(63.5 64.5) #(61.5 62.5) #(59.5 60.5)))
;; Rather than manually change '(64 62 63) into '(#(63.5 64.5) #(61.5 62.5) #(59.5 60.5))
;; I wanted to be able to do it on the fly.
;; I had to learn quite a lot about deep recursion in Scheme!
;; This is where I landed:

;; Function g_itnote
;; Function g_itnote will replace a midi note, other than notes within a vector,
;; by a vector containing two slightly different real midi notes.
;; One note is a bit lower and the other a bit higher than the original midi.
;; Then new pair of notes has a "beating effect" when played together as a vector.
;; The frequency shift delta can be changed on the fly.

(define g_itnote
(let ((delta 0.4321)) ;; Can redefine g_itnote with a new value of delta
(lambda (note)
(vector (- note delta) (+ note delta)))))

(println (g_itnote 70))

;; Function g_it
;; Apply the g_itnote function to members of list and all levels of sublists ....
;; This function g_it retains vectors, rests '_ and ties '| without modification.

(define (g_it L)
(cond ((null? L) '())
((vector? (car L)) (cons (car L) (g_it (cdr L)))) ;; copy vectors as-is
((symbol? (car L)) (cons (car L) (g_it (cdr L)))) ;; copy '_ and '| as-is
((list? (car L)) (cons (g_it (car L)) (g_it (cdr L))))
(else (cons (g_itnote (car L)) (g_it (cdr L))))))

;; Some tests:
(println (g_it '(40.0 _ #(94 67) | 55)))
(println (g_it '(1 (3 _ 5) 7 #(18 19) 9 | (11 | 13))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Make some sounds and try the function.

;; Set up dsp with some fmsynth output ....
(sys:load "libs/external/instruments_ext.xtm")
(sys:load "libs/core/pattern-language.xtm")
(*metro* 'set-tempo 80)
;; Use the built-in fmsynth instrument.
(make-instrument fmsynth fmsynth)
;; Set up the sound output:
(bind-func dsp:DSP
(lambda (in time chan dat)
(cond ((< chan 2)
(* 1.0 (fmsynth in time chan dat)))
(else 0.0))))

(dsp:set! dsp)

;; To change the delta value you have to redefine g_itnote with a new delta value
;; You can do this 'on the fly'
(define g_itnote
(let ((delta 0.0))
(lambda (note)
(vector (- note delta) (+ note delta)))))
;; Play something which includes sublists, vectors, ties and rests:
(:> g_itC 4 0 (play fmsynth @1 80 dur) (g_it '(60 _ (64 _ (66 | 68)) #(66 68) | | 67 _ 70)))
;; TO CHANGE DELTA NEED TO REDEFINE g_itnote
(define g_itnote
(let ((delta 3.4321))
(lambda (note)
(vector (- note delta) (+ note delta)))))

;; Footnote: I wonder if there is a different way to execute changes to delta?
;; One that would allow you to use cosr to change the delta automatically as the
;; tune plays?

Would be interested in any ideas.
Regards
George

Minoru

unread,
Mar 30, 2023, 3:20:19 AM3/30/23
to Extempore
;; Hi George,
;; How are these ?

;; besides your g_it,

(define g_itnote)

(define def-g
    (lambda (delta)
        (set!  g_itnote

                  (lambda (note)  (vector (- note delta) (+ note delta))))
        (lambda (n)  (set! delta n))))

;; making function set-delta(any name is ok though),
;; 0.4321 is the first delta's value, of course, any number is ok.
(define set-delta (def-g 0.4321))

(println (g_itnote 70)) ;#(69.567900 70.432100), ok.

(set-delta 0.0)         ; the value of delata is changed.
(println (g_itnote 70)) ;#(70.000000 70.000000), ok.

(get-closure-code set-delta) ;(lambda (n) (set! delta n))

;; of course, any time you can change the value of delta
;; by this set-delta while playing (:> g_itC 4 0 .....) etc, too.

;; Just sample for auto changing the value of delta
(define auto-chg
    (lambda (beat d)
        (set-delta (* (random) (random 1 21)))
        (callback (*metro* (+ beat (* .5 d)))    'auto-chg (+ beat d) d)))
;; if you like cosr, then use it for above random

;; same as your example

(:> g_itC 4 0 (play fmsynth @1 80 dur) (g_it '(60 _ (64 _ (66 | 68)) #(66 68) | | 67 _ 70)))

;; changing sounds while playing
(set-delta 4.4321)
(set-delta 0.0)
(set-delta 7.4321)

;; or automatically ...
(auto-chg (*metro* 'get-beat 4) 2)
(define auto-chg (lambda ())) ; to stop

;; stop playing

(:| g_itC 4 0 (play fmsynth @1 80 dur) (g_it '(60 _ (64 _ (66 | 68)) #(66 68) | | 67 _ 70)))

;; Regards
2023年3月28日火曜日 7:38:26 UTC+9 George:

George

unread,
Mar 30, 2023, 3:30:20 AM3/30/23
to Extempore
Nice to hear from you again Minoru!
Thanks for these ideas.
I was just beginning to find out about currying and about to try some things.
I'll get back to you after I try your suggestions.

Regards
George

George Wright

unread,
Apr 4, 2023, 9:21:31 PM4/4/23
to extemp...@googlegroups.com
Thank you Minoru
I tried that and it worked very well!
Haven’t yet had time to work on the cosr version yet but will soon.
Also I have an idea to redefine the g_itnote to have only a single note+delta  replacing the original
and have the delta cycle up and down around the original.
Should get dome nice detuning effects.
Will let you know how I get on.

Regards
George

George Wright



--
You received this message because you are subscribed to a topic in the Google Groups "Extempore" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/extemporelang/x0TGM2KTGHE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to extemporelan...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/extemporelang/ee662beb-31eb-4fc4-89e2-1e6558e22995n%40googlegroups.com.

Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

George

unread,
Apr 20, 2023, 6:50:15 AM4/20/23
to Extempore
Just Testing
George

George

unread,
Apr 20, 2023, 6:51:51 AM4/20/23
to Extempore
An update on my playing_real_midi_extempore.xtm

Regards
George
Reply all
Reply to author
Forward
0 new messages