summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNils Gey <denemo@nilsgey.de>2011-02-12 21:02:07 +0100
committerNils Gey <denemo@nilsgey.de>2011-02-12 21:02:07 +0100
commite98ff24d925aeace31cea71aa0a47bdc374b9e35 (patch)
tree4a38c2d819b348b1ae1c833000ffd0df7214c46a
parent9f8f88c1a36f107020543cd886e99cf13cdc0d21 (diff)
Notationmagick: Generate rhythm from numbers and ascii. No commands yet
-rw-r--r--actions/notationmagick.scm104
1 files changed, 91 insertions, 13 deletions
diff --git a/actions/notationmagick.scm b/actions/notationmagick.scm
index 02fb2ffc..468830f2 100644
--- a/actions/notationmagick.scm
+++ b/actions/notationmagick.scm
@@ -1,13 +1,13 @@
-;;;; Various scripts and variables for Denemos note-generation and filter section: NotationMagick
-;;; By Nils Gey 2010
-;;; Needs loaded ans.scm
+; Various scripts and variables for Denemos note-generation and filter section: NotationMagick
+;; By Nils Gey 2010
+;; Needs loaded ans.scm
;; A global var, used by several NotationMagick functions to remember the last value used
(define NotationMagick::NOTATIONSTRING "c' e' g'")
-;;;; Lilypond wrappers for ANS functions
-;;;;;;;;;;;;;;;;;;;;;;
+; Lilypond wrappers for ANS functions
+;;;;;
;Random Diatonic: Wrapper for Lilypond syntax
(define* (NotationMagick::RandomDiatonicLy #:optional (from 'c,,,) (to 'b''''))
@@ -19,20 +19,17 @@
;Shuffled List Insert for Lilypond syntax
(define (NotationMagick::InsertListRandomlyLy lylist)
- (ANS::InsertListRandomly (map ANS::Ly2Ans lylist))
-)
+ (ANS::InsertListRandomly (map ANS::Ly2Ans lylist)))
;Insert a random member of a list for Lilypond syntax
(define (NotationMagick::InsertMemberRandomlyLy lylist)
- (ANS::InsertMemberRandomly (map ANS::Ly2Ans lylist))
-)
+ (ANS::InsertMemberRandomly (map ANS::Ly2Ans lylist)))
;; Ask for a new NOTATIONSTRING with an input-window, remember the value and return it as list of symbols for ANS
(define (NotationMagick::AskNewNotationstring)
(define new (d-GetUserInput "Enter Lilypond notes" "Please insert a list of lilypond notes, separated by Space." NotationMagick::NOTATIONSTRING))
(set! NotationMagick::NOTATIONSTRING new)
-(map string->symbol (string-tokenize NotationMagick::NOTATIONSTRING))
-)
+(map string->symbol (string-tokenize NotationMagick::NOTATIONSTRING)))
;; Insert a random note which is in a reasonable range according to the prevailing clef. Up to one step above/under the first Ledger line.
;; First the prototype, then one derived version for chromatic, one for diatonic.
@@ -49,9 +46,90 @@
((string-ci=? currentclef "Tenor") (proc 'a, 'a'))
((string-ci=? currentclef "Soprano") (proc 'g 'g''))
((string-ci=? currentclef "French") (proc 'd' 'd'''))
- ))
-)
+ )))
+
;; Usable versions for diatonic and chromatic
(define (NotationMagick::RandomWithinClefRangeDiatonic) (NotationMagick::RandomWithinClefRange NotationMagick::RandomDiatonicLy))
(define (NotationMagick::RandomWithinClefRangeChromatic) (NotationMagick::RandomWithinClefRange NotationMagick::RandomChromaticLy))
+; Generators and Cryptographic Functions
+;;;;;
+
+;Binary Rhythm Creation - Based on "Using Binary Numbers in Music" from Vi Hart. http://vihart.com
+;Implementation by Nils Gey - Feb. 2011
+#! From her paper: "Binary numbers used as rhythms (not to be confused with binary rhythms) can be used in music to create
+a mathematical aspect to a piece which can be heard and appreciated by mathematicians, yet still be
+pleasant to the ears of the uninitiated. Even someone who has never heard of binary numbers can still
+understand the patterns on an intuitive level. Binary numbers, especially those affiliated with computer
+science, have a structure which goes very well with the standard forms of music."
+
+"Binary Numbers as Rhythm. Let 1 be a note and 0 be a rest. Thus a number becomes a rhythm!
+In computer science, binary numbers are usually seen in groups of eight bits (a byte), which
+happens to fit perfectly into a 4/4 measure if we assign bits to eighth notes. Powers of two are involved in
+the usual form of western music, where four or eight bar phrases might make up a 16 measure section of a
+64 measure song. This creates a constraint on the rhythm, but leaves the composer free to choose the
+melody."
+
+ASCII Code. 8bit. One 4/4 measure = one letter. The code for each lowercase letter used begins
+with 011, and the following five digits are the position of the letter in the alphabet. Lowercase “a,” then,
+is 01100001.
+You can reverse the ascii/binary digits to get more variation in the measure beginning.
+!#
+
+(define (NotationMagick::LeadingZerosFiller stringy digits)
+ (define needed (- digits (string-length stringy)))
+ (if (> (string-length stringy) digits)
+ stringy
+ (string-append (make-string needed #\0) stringy)))
+
+(define (NotationMagick::Char->binary char digits)
+ (NotationMagick::LeadingZerosFiller (number->string (char->integer char) 2) digits))
+
+(define (NotationMagick::String->CharsAsBinary stringy)
+ (map (lambda (x) (NotationMagick::Char->binary x 8)) (string->list stringy)))
+
+;Digit->binary is basically (number->string n 2) which fills with leading zeros to 4 digits.
+(define (NotationMagick::NotationMagick::Digit->binary numbery)
+ (define numberstring (number->string numbery 2))
+ (NotationMagick::LeadingZerosFiller numberstring 4))
+
+(define (NotationMagick::ListOfNumbers->NumbersAsBinary listy digits)
+ (map (lambda (x) (NotationMagick::LeadingZerosFiller (number->string x 2) digits)) listy))
+
+;This is of limited use because you can't access all 4-digit variations. 10-15 (decimal) are out of range.
+;If you want those create your own list of numbers and use
+;TODO: Keep an initial 0 for a scheme number. Guile built-in? (number->string)
+(define (NotationMagick::Number->DigitsAsBinary numbery)
+ ; this is really awkward
+ (define digitstringlist (map (lambda (x) (make-string 1 x)) (string->list (number->string numbery))))
+ (set! digitstringlist (map string->number digitstringlist))
+ (map NotationMagick::Digit->binary digitstringlist))
+
+(define (NotationMagick::ReverseStringsInList listy)
+ (map string-reverse listy))
+
+; Denemo connection
+(define (NotationMagick::PutBinaryString stringy)
+ (define (PutBinary digit)
+ (if (equal? digit #\0)
+ (d-EnterRest))
+ (if (equal? digit #\1)
+ (d-Enter) ; TODO: Replace this with a built-in version.
+ #f))
+ (for-each PutBinary (string->list stringy)))
+
+(define (NotationMagick::PutBinaryStringList listy)
+ (for-each NotationMagick::PutBinaryString listy))
+
+;TODO: Put binary as lyrics
+
+#! examples
+(d-Set3)
+(NotationMagick::PutBinaryStringList (NotationMagick::String->CharsAsBinary "bach")) ; bach
+(d-AddAfter)
+(NotationMagick::PutBinaryStringList (reverse (NotationMagick::String->CharsAsBinary "bach"))) ;hcab
+(d-AddAfter)
+(NotationMagick::PutBinaryStringList (NotationMagick::ReverseStringsInList (NotationMagick::String->CharsAsBinary "bach"))) ; bach, each ascii is reverted
+(d-AddAfter)
+(NotationMagick::PutBinaryStringList (reverse (NotationMagick::ReverseStringsInList (NotationMagick::String->CharsAsBinary "bach")))) ; hcab, each ascii is reverted
+!#