Permalink
Browse files

add some polish to literal rhythm syntax

  • Loading branch information...
1 parent 78b31c0 commit b3490b50d43a5f0feae7b778dedcf43bcfe4a9ce @k7f committed Apr 8, 2012
@@ -1,9 +1,9 @@
! Copyright (C) 2012 krzYszcz.
! See http://factorcode.org/license.txt for BSD license.
-USING: addenda.help.markup addenda.math arrays assocs help.markup help.syntax
- kernel math om.help.markup om.help.reference om.rhythm.meter
- om.rhythm.private sequences ;
+USING: addenda.help.markup arrays assocs help.markup help.syntax kernel math
+ om.help.markup om.help.reference om.rhythm.meter om.rhythm.private
+ sequences ;
IN: om.rhythm
HELP: rhythm
@@ -56,31 +56,31 @@ HELP: <rhythm>
{ $values
{ "dur" object }
{ "dvn" sequence }
- { "rht" rhythm-tree }
+ { "rtree" rhythm-tree }
}
{ $description "" } ;
HELP: ?change-division
{ $values
- { "rht" rhythm-tree }
+ { "rtree" rhythm-tree }
{ "quot" { $quotation "( ... value -- ... value' ? )" } }
- { "rht" rhythm-tree }
+ { "rtree" rhythm-tree }
{ "?" boolean }
}
{ $description "" } ;
HELP: onsets>rhythm
{ $values
{ "onsets" { $sequence-of number } }
- { "rht" rhythm-tree }
+ { "rtree" rhythm-tree }
}
{ $description "" } ;
HELP: absolute-rhythm
{ $values
{ "onsets" { $sequence-of number } }
{ "total" number }
- { "rht" rhythm-tree }
+ { "rtree" rhythm-tree }
}
{ $description "" } ;
@@ -145,7 +145,7 @@ HELP: zip-measures
{ $values
{ "durs" { $sequence-of rational } }
{ "tsigs" { $sequence-of pair } }
- { "rht" rhythm-tree }
+ { "rtree" rhythm-tree }
}
{ $description "Takes a sequence of durations followed by a sequence of time signatures, and outputs a corresponding " { $link rhythm-tree } ", which contains a sequence of " { $link measure } "s in the " { $snippet "division" } " slot." } ;
@@ -247,26 +247,28 @@ HELP: rhythm-atoms
{ $contract "Outputs a flat sequence containing all atoms of a " { $link rhythm } "." } ;
HELP: {<
-{ $syntax "{< duration elements... >}" }
+{ $syntax "{< tokens... >}" }
{ $values
- { "duration" rhythm-duration }
- { "elements" "a list of " { $link rhythm-element } "s" }
+ { "tokens" "a list of strings representing a " { $link rhythm-duration } " followed by a list of " { $link rhythm-element } "s" }
+}
+{ $description "Marks the beginning of a literal " { $link rhythm-tree } ". Literal rhythms are terminated by " { $link POSTPONE: >} } "."
+ $nl
+ "A numeric duration token must be followed by the separator \"><\". The separator may be omitted after non-numeric duration tokens. If the first token parses to a number and isn't followed by the separator, it is implicitly preceded by two extra tokens: \"1\" and \"><\". The same two extra tokens are prepended, if the first explicit token is the \"{<\"."
+ $nl
+ "Two special forms of duration token are allowed, apart from numeric and metric duration:"
+ { $list
+ { "the " { $snippet "t" } " form is substituted by the sum of all element durations;" }
+ { "the " { $snippet "f" } " form postpones the computation and parses to an unspecified duration." }
+ }
}
-{ $description "Marks the beginning of a literal " { $link rhythm-tree } ". Literal rhythms are terminated by " { $link POSTPONE: >} } "." }
{ $notes
{ $list
- { "Two special forms of the first token are allowed, apart from numeric and metric duration."
- { $list
- { "The " { $snippet "t" } " form is substituted by the sum of all element durations." }
- { "The " { $snippet "f" } " form postpones that computation and parses to an unspecified duration." }
- }
- }
"If literal rhythm has empty contents, it is interpreted as a unit duration rest. The unit at the top level is semibreve (whole note). The unit at lower levels is context-dependent."
{ "If there is only one token inside, it is interpreted as a single-element rhythm, whose details are type-dependent."
{ $list
{ "If the token parses to a number, the value of the " { $link rhythm-element } " is that number, and " { $link rhythm-duration } " is its absolute integer part." }
{ "If the token parses to a " { $link meter } ", the duration is that meter, and the rhythm contains a single rest." }
- { "The token " { $snippet "t" } " is ignored, hence the literal rhythm parses to a unit duration rest." }
+ { "The token " { $snippet "t" } " is ignored (hence the literal rhythm parses to a unit duration rest)." }
{ "The token " { $snippet "f" } " is interpreted as a single rest of unspecified duration." }
}
}
@@ -276,11 +278,15 @@ HELP: {<
"A single measure with a rest on the first beat, followed by two crotchets:"
{ $code "{< 3//4 -1 1 1 >}" }
"A variation: a quaver tripplet on the second beat and a tie to the third beat:"
- { $code "{< 3//4 -1 {< 1 1 1 1 >} 1. >}" }
+ { $code "{< 3//4 -1 {< 1 1 1 >} 1. >}" }
"A single note of unspecified duration:"
{ $code "{< f 1 >}" }
- "A single note of unit duration:"
- { $code "{< t 1 >}" }
+ "Two notes, each of unit duration:"
+ { $code "{< t 1 1 >}" }
+ "Two notes, each of half-unit duration:"
+ { $code "{< 1 1 >}" }
+ "Two notes, each of one-and-half-unit duration:"
+ { $code "{< 3 >< 1 1 >}" }
} ;
HELP: >}
@@ -1,86 +1,86 @@
! Copyright (C) 2012 krzYszcz.
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math om.rhythm om.rhythm.meter tools.test ;
+USING: accessors kernel math om.rhythm tools.test ;
IN: om.rhythm.tests
-[ {< 1 1/4 1/4 1/4 1/4 >} ] [
- t { 1/4 1/4 1/4 1/4 } <rhythm>
+[ {< 1/4 1/4 1/4 1/4 >} 1 ] [
+ t { 1/4 1/4 1/4 1/4 } <rhythm> dup duration>>
] unit-test
-[ {< 3/4 1/4 1/4 1/4 >} ] [
+[ {< 3/4 >< 1/4 1/4 1/4 >} ] [
t { 1/4 1/4 1/4 } <rhythm>
] unit-test
-[ {< 1 1 1 1 1 >} ] [
+[ {< 1 >< 1 1 1 1 >} ] [
1 { 1 1 1 1 } <rhythm>
] unit-test
[ {< 4//4 1 1 1 1 >} ] [
{ 4 4 } { 1 1 1 1 } <rhythm>
] unit-test
-[ {< 1 1 1 1 1 >} ] [
+[ {< 1 >< 1 1 1 1 >} ] [
{ 1 2 3 4 5 } onsets>rhythm
] unit-test
-[ {< 1 1. 1 -1 >} ] [
+[ {< 1 >< 1. 1 -1 >} ] [
{ 2 -3 4 } onsets>rhythm
] unit-test
-[ {< 1 {< 2 1 1 1 >} -1 1 >} ] [
+[ {< 1 >< {< 2 >< 1 1 1 >} -1 1 >} ] [
{ 1 3 5 -7 10 13 } onsets>rhythm
] unit-test
-[ {< 1 1 -1 {< 2 1 1 1 >} >} ] [
+[ {< 1 >< 1 -1 {< 2 >< 1 1 1 >} >} ] [
{ 1 -4 7 9 11 13 } onsets>rhythm
] unit-test
-[ {< 1 -1 {< 2 1 1 1 >} 1 >} ] [
+[ {< 1 >< -1 {< 2 >< 1 1 1 >} 1 >} ] [
{ -1 4 6 8 10 13 } onsets>rhythm
] unit-test
-[ {< 1 1. {< 2 1 1 1 >} -1 >} ] [
+[ {< 1 >< 1. {< 2 >< 1 1 1 >} -1 >} ] [
{ 4 6 8 -10 13 } onsets>rhythm
] unit-test
-[ {< 1 1 1 {< 2 2 1 >} >} ] [
+[ {< 1 >< 1 1 {< 2 >< 2 1 >} >} ] [
{ 1 4 7 11 13 } onsets>rhythm
] unit-test
-[ {< 1 {< 2 2 1 >} 1 1 >} ] [
+[ {< 1 >< {< 2 >< 2 1 >} 1 1 >} ] [
{ 1 5 7 10 13 } onsets>rhythm
] unit-test
-[ {< 1 {< 2 1 2 >} 1 1 >} ] [
+[ {< 1 >< {< 2 >< 1 2 >} 1 1 >} ] [
{ 1 3 7 10 13 } onsets>rhythm
] unit-test
-[ {< 1 1 1 {< 2 1 2 >} >} ] [
+[ {< 1 >< 1 1 {< 2 >< 1 2 >} >} ] [
{ 1 4 7 9 13 } onsets>rhythm
] unit-test
-[ {< 1 1 {< 1 1 1 1 >} >} ] [
+[ {< 1 >< 1 {< 1 >< 1 1 1 >} >} ] [
{ 1 4 5 6 7 } onsets>rhythm
] unit-test
-[ {< 1 1. {< 1 1 1 1 >} >} ] [
+[ {< 1 >< 1. {< 1 >< 1 1 1 >} >} ] [
{ 4 5 6 7 } onsets>rhythm
] unit-test
-[ {< 1 {< 1 1 1 1 >} 1 >} ] [
+[ {< 1 >< {< 1 >< 1 1 1 >} 1 >} ] [
{ 1 2 3 4 7 } onsets>rhythm
] unit-test
-[ {< 1 1 1 1 1 >} ] [
+[ {< 1 >< 1 1 1 1 >} ] [
{ 1 2 3 4 } 4 absolute-rhythm
] unit-test
-[ {< 1 1. 1 1 >} ] [
+[ {< 1 >< 1. 1 1 >} ] [
{ 2 3 } 3 absolute-rhythm
] unit-test
-[ {< 1 1. 2 1 >} ] [
+[ {< 1 >< 1. 2 1 >} ] [
{ 1+1/4 1+3/4 } 1 absolute-rhythm
] unit-test
@@ -100,16 +100,16 @@ IN: om.rhythm.tests
{ 1 1. -1 } fuse-rests-and-ties
] unit-test
-[ { 1 {< 1 1 {< 1 4 1 >} 3 >} 2 } ] [
- { 1 {< 1 1 {< 1 1 2. 1. 1 >} 1 1. 1. >} 1 1. } fuse-notes-deep
+[ { 1 {< 1 >< 1 {< 1 >< 4 1 >} 3 >} 2 } ] [
+ { 1 {< 1 >< 1 {< 1 >< 1 2. 1. 1 >} 1 1. 1. >} 1 1. } fuse-notes-deep
] unit-test
-[ { {< 1 -1 {< 1 1 -3 1 >} -3 >} } ] [
- { {< 1 -1 {< 1 1 -2 -1 1 >} -1 -1 -1 >} } fuse-rests-deep
+[ { {< 1 >< -1 {< 1 >< 1 -3 1 >} -3 >} } ] [
+ { {< 1 >< -1 {< 1 >< 1 -2 -1 1 >} -1 -1 -1 >} } fuse-rests-deep
] unit-test
-[ { {< 1 -2 -1 -1 >} } ] [
- { {< 1 -1 -1 {< 1 -2 -1 >} -1 >} } fuse-rests-deep
+[ { {< 1 >< -2 -1 -1 >} } ] [
+ { {< 1 >< -1 -1 {< 1 >< -2 -1 >} -1 >} } fuse-rests-deep
] unit-test
[ t ] [
@@ -144,12 +144,12 @@ IN: om.rhythm.tests
{ 1/4 1/4 4/4 } { { 3 4 } { 3 4 } } zip-measures
] unit-test
-[ {< 4//4 {< 1 2 >} 2 4 >} ] [
- {< 4//4 {< 1 1 >} 1 2 >} [ 2 * ] map-rhythm
+[ {< 4//4 {< 1 >< 2 >} 2 4 >} ] [
+ {< 4//4 {< 1 >< 1 >} 1 2 >} [ 2 * ] map-rhythm
] unit-test
-[ {< 4//4 {< 1 2 >} 2 4 >} ] [
- {< 4//4 {< 1 1 >} 1 2 >} [ 2 * ] map-rhythm!
+[ {< 4//4 {< 1 >< 2 >} 2 4 >} ] [
+ {< 4//4 {< 1 >< 1 >} 1 2 >} [ 2 * ] map-rhythm!
] unit-test
[ f ] [
@@ -160,27 +160,27 @@ IN: om.rhythm.tests
{< 4//4 1 >} dup [ ] map-rhythm! eq?
] unit-test
-[ {< f {< 1 1 {< 1 1 1 >} 1 >} {< 1 1 >} >} ] [
- {< f {< 1 -1 {< 1 1 -1 >} 1 >} {< 1 -1 >} >} map-rests>notes
+[ {< f {< 1 >< 1 {< 1 >< 1 1 >} 1 >} {< 1 >< 1 >} >} ] [
+ {< f {< 1 >< -1 {< 1 >< 1 -1 >} 1 >} {< 1 >< -1 >} >} map-rests>notes
] unit-test
-[ {< f {< 1 1 {< 1 1 1 >} 1 >} {< 1 1 >} >} ] [
- {< f {< 1 -1 {< 1 1 -1 >} 1 >} {< 1 -1 >} >} map-rests>notes!
+[ {< f {< 1 >< 1 {< 1 >< 1 1 >} 1 >} {< 1 >< 1 >} >} ] [
+ {< f {< 1 >< -1 {< 1 >< 1 -1 >} 1 >} {< 1 >< -1 >} >} map-rests>notes!
] unit-test
-[ {< f {< 1 -1 {< 1 -1 -1 >} -1 >} {< 1 -1 >} >} ] [
- {< f {< 1 -1 {< 1 1 -1 >} 1 >} {< 1 -1 >} >} map-notes>rests
+[ {< f {< 1 >< -1 {< 1 >< -1 -1 >} -1 >} {< 1 >< -1 >} >} ] [
+ {< f {< 1 >< -1 {< 1 >< 1 -1 >} 1 >} {< 1 >< -1 >} >} map-notes>rests
] unit-test
-[ {< f {< 1 -1 {< 1 -1 -1 >} -1 >} {< 1 -1 >} >} ] [
- {< f {< 1 -1 {< 1 1 -1 >} 1 >} {< 1 -1 >} >} map-notes>rests!
+[ {< f {< 1 >< -1 {< 1 >< -1 -1 >} -1 >} {< 1 >< -1 >} >} ] [
+ {< f {< 1 >< -1 {< 1 >< 1 -1 >} 1 >} {< 1 >< -1 >} >} map-notes>rests!
] unit-test
-[ {< f {< 1 1 {< 1 -1 1 >} -1 >} {< 1 1 >} >} ] [
- {< f {< 1 -1 {< 1 1 -1 >} 1 >} {< 1 -1 >} >}
+[ {< f {< 1 >< 1 {< 1 >< -1 1 >} -1 >} {< 1 >< 1 >} >} ] [
+ {< f {< 1 >< -1 {< 1 >< 1 -1 >} 1 >} {< 1 >< -1 >} >}
{ { -1 1 } { 1 -1 } } rhythm-substitute
] unit-test
[ { -1 1 -1 1 -1 } ] [
- {< f {< 1 -1 {< 1 1 -1 >} 1 >} {< 1 -1 >} >} rhythm-atoms
+ {< f {< 1 >< -1 {< 1 >< 1 -1 >} 1 >} {< 1 >< -1 >} >} rhythm-atoms
] unit-test
Oops, something went wrong.

0 comments on commit b3490b5

Please sign in to comment.