主題
R可以使用 gm 套件建立音樂。gm亦可內嵌於R Markdown.
感謝 Alpha Lee 提供音樂簡譜:
Youtube: https://youtu.be/Jx2YmiNm-6o
Piano : Moonlight Sonata Op.27 No.2 (Beethoven)
使用方法
1. 下載免費跨平台(Windows, Mac, Linux)譜曲軟體 MuseScore, 下載網址 https://musescore.org/zh-hant/download
2. 下載 gm 套件
3. 使用 Music, Line建立音樂, 最後以 show 顯示樂譜.
4. 使用時, 按下 [三角形] 播放鍵即可播放音樂.
關鍵字
#music
#MuseScore
#gm
執行成果
1. 內建範例
MP3下載: https://github.com/rwepa/DataDemo/blob/master/music/gm-sample1.mp3
2. Alpha Lee 提供音樂簡譜
Youtube: https://youtu.be/N0PK1u5ZfBE
R程式碼下載
https://github.com/rwepa/DataDemo/blob/master/gm_demo.R
R程式碼
# title : gm-音樂創作
# author : Ming-Chang Lee
# email : alan9956@gmail.com
# RWEPA : http://rwepa.blogspot.tw/
# GitHub : https://github.com/rwepa
# 載入 gm
library(gm)
# sample 1 - 內建範例
# 建立 Music 對象
m <-
# 初始化 Music 對象
Music() +
# 加上 4/4 拍號
Meter(4, 4) +
# 加上一條包含四個音的聲部
Line(list("C5", "D5", "E5", "F5"), list(1, 1, 1, 1))
# 轉化成樂譜和音訊
show(m, c("score", "audio"))
# sample 2 - Alpha Lee 提供
t <- tuplet("quarter", Tupler(3, unit = "eighth", take = "eighth"))
z1 <- Line(list("G#3", "C#4", "E4","G#3", "C#4", "E4","G#3", "C#4", "E4","G#3", "C#4", "E4","G#3", "C#4", "E4","G#3", "C#4", "E4","G#3", "C#4", "E4","G#3", "C#4", "E4","A3", "C#4", "E4","A3", "C#4", "E4","A3", "D4", "F#4","A3", "D4", "F#4","G#3", "B#3", "F#4", "G#3", "C#4", "E4", "G#3", "C#4", "D#4", "F#3", "B#3", "D#4","E3", "G#3", "C#4",c("C#4", "E4")),list(t, t, t, t, t, t,t, t, t, t, t, t,t, t, t, t, t, t,t, t, t, t, t, t,t, t, t, t, t, t,t, t, t, t, t, t,t, t, t, t, t, t,t, t, t, t, t, t, t, t, t,3), name = "a")
z2 <- Line(list(c("C#2", "C#3"), c("B1", "B2"),c("A1", "A2"), c("F#1", "F#2"),c("G#1", "G#2"),c("G#1", "G#2"),c("C#2", "G#2", "C#3")), list(4, 4, 2, 2, 2, 2, 4), to = "a", as = "staff", name = "b")
m1 <- Music() + Tempo(48)+ Meter(4, 4) + z1 + z2 + Key(4)
m1 <- m1 + Clef("G", to = "a") + Clef("F", to = "b")
show(m1, c("score", "audio"))
# end
請問一下,我現在碰到的問題是,雖然可以把譜寫出來,但聲音無法出來,也就是三角形的圖案,程式不讓我按,請問大神我是出了什麼問題呢?
回覆刪除Hi friend,
回覆刪除聲音與三角形按鈕問題可能是 gm 套件安裝的問題, 建議在Windows檔案總管中,刪除 gm 資料夾,再重新安裝試看看. 目前是使用 Windows 10-64位元系統測試OK, 或是再po整個RStudio執行畫面.