-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMelodia_Casuale.ny
More file actions
30 lines (24 loc) · 1.02 KB
/
Melodia_Casuale.ny
File metadata and controls
30 lines (24 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$nyquist plug-in
$version 4
$type generate
$name (_ "Melodia Casuale")
$copyright (_ "GNU General Public License v2.0")
; Aggiungi semitoni alla melodia casuale
$control Gen (_ "N. Note") int "60 (Max)" 30 1 60
$control Choice (_ "Tipologia di generazione") choice ((_ "Solo Toni") (_ "Toni e Semitoni")) Solo Toni
(defun random-note ()
(let ((notes (if (equal Choice "Solo Toni")
'(60 62 64 65 67 69 71 72) ; Note della scala di Do maggiore
'(60 61 62 63 64 65 66 67 68 69 70 71 72)))) ; Note della scala cromatica
(nth (random (length notes)) notes)))
(defun random-duration ()
(let ((durations '(0.5 1 1.5 2)))
(nth (random (length durations)) durations)))
(defun midi-to-hz (midi-note)
(* 440 (expt 2 (/ (- midi-note 69) 12.0))))
(defun generate-melody (length)
(if (<= length 0)
(osc 0 0)
(seq (osc (hz-to-step (midi-to-hz (random-note))) (random-duration))
(generate-melody (- length 1)))))
(mult (generate-melody Gen) 0.5)