From 03c7f74481a9659b69afaf6dbfdb08c96958281d Mon Sep 17 00:00:00 2001
From: flujoo
-
-
show(m, c("score", "audio"))
show(m)
gm 的语法有点像 ggplot2,你可以不断添加成分,然后查看,然后再添加,不断反复。
我们还可以加上拍速记号:
-
+加上新的声部:
-
+这个过程可以继续,但我们在此打住。
-
+
show(m, to = c("score", "audio"))
-
+
m <- m + Tempo(120)
show(m)
-
+Add another musical line as a part:
-
+Add another musical line as a voice:
-
+This process can keep going, but let’s stop here. If you want to go deeper, let’s first learn how to install and configure gm.
-
+As you may have noticed, to represent a musical line, we don’t directly supply notes, chords, or rests to Line()
as input. Instead, we separate the line’s pitch and durational contents. This is more convenient, since you may always want to deal with one aspect and in the meantime ignore the other.
pitches <- c(60, 62, 64, 65)
-
+We can transpose them up by a fifth easily:
pitches + 7
#> [1] 67 69 71 72
-
+However, this advantage comes at a cost: MIDI note numbers are always ambiguous. For example, the following three pitches are all equivalent to MIDI note number 73:
-
+gm interprets MIDI note numbers based on keys and neighbor pitches. In the following example, MIDI note number 73 is interpreted as C5 sharp in the first measure, but as D5 flat in the second measure, for these two measures have different keys.
l <- Line(list(73, 73), list(2, 2))
m <- Music() + Meter(2, 4) + Key(7, bar = 1) + Key(-7, bar = 2) + l
show(m)
-
+gm is not perfect in interpreting MIDI note numbers, so if you want it to be precise, use pitch notations.
m <- Music() + Meter(6, 4) + Line(list(NA, NA, NA), list("w", "q", "32"))
show(m)
-
+The duration type or its abbreviation can be followed by zero to four dots, in a duration notation, as in the following example:
l <- Line(rep(list(NA), 5), list("q", "q.", "q..", "q...", "q...."))
m <- Music() + Meter(9, 4) + l
show(m)
-
+You can also append what we call “tupler” notations in gm to a duration notation to represent a tuplet:
-
+In the above example, we use "q/3"
to represent a triplet. You can read "q/3"
as “divide a quarter note into three parts, and take one of them”. We will talk more about tuplets in the next section.
To sum up, a duration notation consists of
Duration notations can’t represent some complex tuplets.
For example, how to represent the first tuplet in the following score:
-
+This tuplet can read as “divide a quarter note into three parts, take two of them”. We can’t express “take two” in any duration notation. This is where we need tuplet()
and Tupler()
. Let’s look at an example.
We can express duration notation "quarter/3"
with tuplet()
and Tupler()
as:
-
+This may seem strange to you, but it’s syntactically valid.
We can even create complex nested tuplets like in the following score:
@@ -405,7 +405,7 @@-
+Yes, there is something wrong with this score. MuseScore (which gm uses internally) has some bugs, so it can’t convert MusicXML (which gm uses to represent musical scores internally) containing nested tuplets to score correctly. So if there are nested tuplets in your Music
object, you can export it to MusicXML file with export()
, and open the file with other notation software like Finale. Below is a correct score generated in Finale:
Note that in Line()
objects, tuplets must form tuplet groups, or you will get an error. For example,
-
+In tie = list(c(1, 1), c(2, 2), 3)
in the above example,
c(1, 1)
means we add a tie to the first note of the first chord to connect it with the first note of the second chord. Note that to tie two adjacent notes, we only specify the position of the first note.
m <- Music() + Meter(1, 4) + Line(list("C5"), list(4))
show(m)
-
+The C5 whole note is automatically split into four tied quarter notes, because the time signature is 1/4.
-
+We can insert it into the third measure after the second beat:
l <- Line(list("C5", "D5", "E5"), list(1, 1, 1), bar = 3, offset = 2)
m <- Music() + Meter(4, 4) + l
show(m)
-
+-
+The Line
object is named “a” with argument name
.
Below is another Line
object named “b”:
-
+Line
“b” is appended at the end by default. We can make Line
“b” come before Line
“a”, by specifying argument to
and after
:
-
+to = "a"
means we add Line
“b” with Line
“a” as a reference.
The Music
object contains two Line
objects now. Let’s introduce a third Line
object named “c”:
@@ -518,14 +518,14 @@m <- m + l3 show(m)
-
+Finally, below is a fourth Line
, let’s add it to Line
“b” as another staff:
-
+We can print this Music
to check its structure:
-
+By specifying arguments actual_number
and actual_unit
, we can create pickup measures. For example,
m <- Music() +
@@ -615,7 +615,7 @@
l <- Line(list("A4", "B4", "C5", "D5", "E5"), rep(list(1), 5))
show(m + l)
-
+The time signature which appears on the first measure is 4/4, but the actual one is 1/4. invisible = TRUE
makes the second time signature invisible.
-
+We can add a key signature to a specific part or staff, rather than to the whole score. For example, below is a musical score of two parts:
-
+We can change the key signature of only the first part:
-
+to = 1
means the Key
object is added only to the part containing the first Line
in the Music
object.
We can change the key signature of only the second staff of the second part:
-
+scope = "staff"
means the key signature is added only to a specific staff.
-
+If not satisfied, you can change it:
-
+You can also add a clef into other measures:
-
+Or even at other beat:
-
+-
+
-
+
Xh51RAz@tLt4U}z)9r4i1uS^ z^lkwDorF+A)SG(DmaYY61?u(#=K)9Y7S2cI2~5ESx2pojt@rI4SVjB2upw?awgAsp z(QbF816YP#qcgFW!f-68s1%z>4Yl^%76YFQ)a?h($CT1PDD2Tip`%FMvB38eC5|h{ zEG(H#x$`e0T@fS>V3RXKq>@^c+c4m3fw}|OwE7dy_pMl1l6r9-Uf87Itlt@!w>_B6 zEvR(EXvd3K5=3?=A)1g}$i5|5>(&dKj1@wy4$e0ST3gl)19*G)Z31^b^Mg*GpK7QbllqwtipVls%0vs z ?m|d<~;)v%q2V3co74E=1*|UKB+|o@fYfH}ye81c|5ttv^HG~g& zPX>NT^`VX@Q(Wd-fWKDRmJlMvL{)AxedSHqT2C;e{7prU@1$_1u?-u>4zA+7#cY7< zfiG0ih7ckHL{)A>edW7- d7f;anF2|?wy8?*iOM)BN) z5I&+Rx08M4r+nr4&gW5V=(-x~Sq;G=G&~J_8Z!jCEF^pg>(WZTTghSIJy_3g8`-j( z2_ec5Rk``yJ)ZTI-C4}91AlYMZthZlW}Y8lOSZuL)hbz{rFd>ah>8hw1-XLKGn#F_ z^6hvj_1vf#X94#+ jyOn%JIMP>MM|sx}f24|?n3L{oy#Hak@0`^z7*mc>{ ujitQ6ZWQ=-*8Gjz@{VWGQ2RwjfiMkJX2J6`k#gxw~Orfp=E~EPFT5-j56GEhn zup!|pJVSn^v|xT?r(m(PTAgzob@unfCKsaSBIu8;b|^ +aPRmpcdTryD-;}JF!WH?v!X{7PdZhMbd&a zh+8q=#EnS{B1Db!$6nO?itP*=mhN}9df^7p8%X!+CGEjhSY+kxeh4!aWaa-A=_T|Y zu1EH(N_hc`lv{GSglGtV1YSv62qEI8UP+lNp%cr7b!r38DGIqOX#s?21oc#IE!e7o zY1pFd2Z5IY$Gk}SG
LPX?h3KiQXV7RltKk$2O7Bws|r4T}ND_VfB;3>BIfeV4T zz!$M460cDhU{VMnnu2*)jJ9@6$sGZ vLI@#*5JCtc hgb+dqA%v)${{z)Gq4>UfLJ$A|002ovPDHLkV1h1cS+W2C