{"id":6865,"date":"2026-01-16T00:00:00","date_gmt":"2026-01-15T16:00:00","guid":{"rendered":"http:\/\/192.168.1.29\/?p=6865"},"modified":"2026-01-16T09:50:08","modified_gmt":"2026-01-16T01:50:08","slug":"r%e8%af%ad%e8%a8%80%e5%b9%b2%e5%98%9b%e9%9f%b3%e4%b9%90%e5%8c%85%e4%bd%bf%e7%94%a8%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/xc.ipyingshe.net:5347\/?p=6865","title":{"rendered":"R\u8bed\u8a00gm\u97f3\u4e50\u5305\u4f7f\u7528\u65b9\u6cd5"},"content":{"rendered":"\n<p>\u4f60\u60f3\u8981\u4e86\u89e3 R \u8bed\u8a00\u4e2d gm\uff08Graphical Music\uff09\u5305\u7684\u4f7f\u7528\u65b9\u6cd5\u5e76\u83b7\u53d6\u53ef\u8fd0\u884c\u7684\u793a\u4f8b\uff0c\u6211\u4f1a\u4ece\u5b89\u88c5\u3001\u6838\u5fc3\u6982\u5ff5\u5230\u5177\u4f53\u793a\u4f8b\uff0c\u5e2e\u4f60\u5168\u9762\u638c\u63e1\u8fd9\u4e2a\u5305\u7684\u4f7f\u7528\u3002gm \u5305\u662f R \u8bed\u8a00\u4e2d\u7528\u4e8e\u4ee5\u7f16\u7a0b\u65b9\u5f0f\u521b\u5efa\u3001\u4fee\u6539\u548c\u5bfc\u51fa\u4e50\u8c31\u7684\u5de5\u5177\uff0c\u5b83\u5c06\u97f3\u4e50\u7ed3\u6784\uff08\u97f3\u7b26\u3001\u548c\u5f26\u3001\u62cd\u53f7\u3001\u8c03\u53f7\u7b49\uff09\u8f6c\u5316\u4e3a\u53ef\u6e32\u67d3\u7684\u4e50\u8c31\uff0c\u652f\u6301\u5bfc\u51fa\u4e3a MusicXML\u3001PDF\u3001PNG \u7b49\u683c\u5f0f\uff0c\u975e\u5e38\u9002\u5408\u97f3\u4e50\u5206\u6790\u548c\u7a0b\u5e8f\u5316\u4f5c\u66f2\u3002<\/p>\n\n\n\n<p>\u97f3\u4e50\u7f16\u8f91\u6d89\u53ca\u8f6f\u4ef6musescore  and   LilyPond(\u7b26\u53f7\u751f\u6210\u97f3\u4e50)<\/p>\n\n\n\n<p>\u6ce8\u610f\u4e8b\u9879<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>gm\u5305\u4f7f\u7528\u94fe\u5f0f\u7f16\u7a0b\u98ce\u683c\uff08%&gt;%\u64cd\u4f5c\u7b26\uff09\uff0c\u4f7f\u4ee3\u7801\u66f4\u5177\u53ef\u8bfb\u6027<\/li>\n\n\n\n<li>\u53ef\u4ee5\u901a\u8fc7help(package = &#8220;gm&#8221;)\u67e5\u770b\u5b8c\u6574\u7684\u51fd\u6570\u6587\u6863<\/li>\n\n\n\n<li>\u652f\u6301\u591a\u79cd\u97f3\u7b26\u65f6\u503c\uff1a&#8221;w&#8221;(\u5168\u97f3\u7b26), &#8220;h&#8221;(\u4e8c\u5206\u97f3\u7b26), &#8220;q&#8221;(\u56db\u5206\u97f3\u7b26), &#8220;e&#8221;(\u516b\u5206\u97f3\u7b26), &#8220;s&#8221;(\u5341\u516d\u5206\u97f3\u7b26)\u7b49<\/li>\n\n\n\n<li>\u53ef\u4ee5\u8bbe\u7f6e\u97f3\u7b26\u7684\u529b\u5ea6\uff08velocity\uff09\u3001\u516b\u5ea6\uff08octave\uff09\u548c\u97f3\u957f\uff08duration\uff09\u5e0c\u671b\u8fd9\u4e9b\u793a\u4f8b\u4ee3\u7801\u80fd\u5e2e\u52a9\u4f60\u5f00\u59cb\u4f7f\u7528R\u8bed\u8a00\u7684gm\u5305\u521b\u5efa\u81ea\u5df1\u7684\u97f3\u4e50\u4f5c\u54c1\uff01<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e00\u3001\u5b89\u88c5\u4e0e\u73af\u5883\u51c6\u5907<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5b89\u88c5 gm \u5305\u9996\u5148\u9700\u8981\u5b89\u88c5 gm \u5305\u53ca\u5176\u4f9d\u8d56\uff0cgm \u4f9d\u8d56xml2\u3001fs\u7b49\u5305\uff0c\u8fd8\u9700\u8981lilypond\u8f6f\u4ef6\u6765\u6e32\u67d3\u4e50\u8c31\uff08\u5bfc\u51fa PDF\/PNG \u5fc5\u9700\uff09\uff1a \u5b89\u88c5CRAN\u7248\u672c\uff08\u5982\u679c\u5df2\u53d1\u5e03\uff09 install.packages(&#8220;gm&#8221;)<br> \u6216\u5b89\u88c5\u5f00\u53d1\u7248\uff08\u63a8\u8350\uff0c\u529f\u80fd\u66f4\u65b0\uff09   ***<strong>\u7528\u8fd9\u4e2a<\/strong>***\u5426\u5219\u4e0d\u8f93\u51fa\u5185\u5bb9<br> install.packages(&#8220;devtools&#8221;)<br> devtools::install_github(&#8220;flujoo\/gm&#8221;)<\/li>\n\n\n\n<li>\u5b89\u88c5 LilyPond\uff08\u5173\u952e\u4f9d\u8d56\uff09gm \u6e32\u67d3\u4e50\u8c31\u4f9d\u8d56 LilyPond\uff0c\u9700\u5355\u72ec\u5b89\u88c5\uff1aWindows\uff1a\u4eceLilyPond \u5b98\u7f51\u4e0b\u8f7d\u5b89\u88c5\u5305\uff0c\u5b89\u88c5\u540e\u5c06\u8def\u5f84\uff08\u5982C:\\Program Files\\LilyPond\\usr\\bin\uff09\u6dfb\u52a0\u5230\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u3002\uff08\u4e0b\u8f7d\u7684\u81ea\u62cd\u538b\u7f29\u5305bin\u76ee\u5f55\uff0c\u653e\u5165\u4e0a\u8ff0\u76ee\u5f55\u5373\u53ef\uff09<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5355\u72ec\u4f7f\u7528\u8fd9\u4e2a\u8f6f\u4ef6\uff0c\u5b89\u88c5\u65b9\u6cd5,\u67e5\u770b\u8fde\u63a5\u5185\u6587\u6863\uff1a<a href=\"https:\/\/lilypond.org\/doc\/v2.25\/Documentation\/learning.pdf\">learning.pdf<\/a><\/li>\n\n\n\n<li>\u6216\u8005\u5b89\u88c5<a href=\"https:\/\/github.com\/frescobaldi\/frescobaldi\/releases\">[Frescobaldi 4.0.4](https:\/\/github.com\/frescobaldi\/frescobaldi\/releases\/tag\/v4.0.4)<\/a> \u6253\u5f00\u8f6f\u4ef6\uff0c\u7f16\u8f91\u83dc\u5355-&gt;\u9996\u9009\u9879-&gt;\u9009\u62e9LilyPond\u4f1a\u81ea\u52a8\u5b89\u88c5\uff0c\u5c31\u53ef\u4ee5\u7528\u7b26\u53f7\u6253\u8c31\u4e86\uff0c\u4f8b\u5982 C {c&#8217;} \u663e\u793a\u4e94\u7ebf\u8c31do <\/li>\n\n\n\n<li>Mac\/Linux\uff1a\u901a\u8fc7\u7ec8\u7aef\u5b89\u88c5\uff08brew install lilypond \u6216 sudo apt-get install lilypond\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4f60\u8fd8\u9700\u8981\u5b89\u88c5&nbsp;MuseScore\uff0c\u5b83\u662f\u4e00\u6b3e\u5f00\u6e90\u514d\u8d39\u7684\u6253\u8c31\u8f6f\u4ef6\u3002\u7f16\u8f91\u751f\u6210\u7684\u4e50\u8c31MuseScore \u6709\u9ed8\u8ba4\u7684\u5b89\u88c5\u8def\u5f84\uff0c\u5982\u679c\u4f60\u5b89\u88c5\u5230\u5176\u5b83\u8def\u5f84\uff0c\u8bf7\u5728 .Renviron \u6587\u4ef6\u4e2d\u8bbe\u7f6e\uff1a<\/li>\n\n\n\n<li>\u6253\u5f00 .Renviron \u6587\u4ef6\u3002\u53ef\u4ee5\u7528\u547d\u4ee4&nbsp;<code>file.edit(\"~\/.Renviron\")<\/code>\u3002<\/li>\n\n\n\n<li>\u5728\u5176\u4e2d\u52a0\u5165&nbsp;<code>MUSESCORE_PATH=&lt;MuseScore \u53ef\u6267\u884c\u6587\u4ef6\u7684\u8def\u5f84&gt;<\/code>\uff0c\u6bd4\u5982&nbsp;<code>MUSESCORE_PATH=\"C:\/Program Files (x86)\/MuseScore 3\/bin\/MuseScore3.exe\"<\/code>\u3002<\/li>\n\n\n\n<li>\u91cd\u542f R\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e8c\u3001gm \u5305\u6838\u5fc3\u6982\u5ff5<\/h3>\n\n\n\n<p>gm \u7684\u6838\u5fc3\u662f\u901a\u8fc7Music\u5bf9\u8c61\u6784\u5efa\u4e50\u8c31\uff0c\u4e3b\u8981\u5305\u542b\u4ee5\u4e0b\u5c42\u7ea7\uff1a Music \u5bf9\u8c61\uff1a\u6574\u4e2a\u4e50\u8c31\u7684\u5bb9\u5668\uff0c\u5305\u542b\u591a\u4e2aPart\uff08\u58f0\u90e8\uff09\u3002 Part \u5bf9\u8c61\uff1a\u5355\u4e2a\u58f0\u90e8\uff08\u5982\u94a2\u7434\u53f3\u624b\u3001\u5c0f\u63d0\u7434\u58f0\u90e8\uff09\uff0c\u5305\u542b\u591a\u4e2aMeasure\uff08\u5c0f\u8282\uff09\u3002 Measure \u5bf9\u8c61\uff1a\u5c0f\u8282\uff0c\u5305\u542b\u97f3\u7b26\u3001\u4f11\u6b62\u7b26\u3001\u548c\u5f26\u7b49\u97f3\u4e50\u5143\u7d20\uff0c\u4ee5\u53ca\u62cd\u53f7 \/ \u8c03\u53f7\u5b9a\u4e49\u3002 Note\/Rest\/Chord \u5bf9\u8c61\uff1a\u97f3\u7b26\u3001\u4f11\u6b62\u7b26\u3001\u548c\u5f26\uff0c\u9700\u6307\u5b9a\u97f3\u9ad8\u3001\u65f6\u503c\u3001\u516b\u5ea6\u7b49\u5c5e\u6027\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e09\u3001\u5b8c\u6574\u4f7f\u7528\u793a\u4f8b<\/h3>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u4ece\u57fa\u7840\u5230\u8fdb\u9636\u7684\u793a\u4f8b\uff0c\u8986\u76d6 gm \u5305\u7684\u6838\u5fc3\u529f\u80fd\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u52a0\u8f7dgm\u5305\nlibrary(gm)\n# \u751f\u6210\u4e50\u8c31\u6570\u636e\nmusic &lt;- \n  Music() +\n  Meter(4, 4) +  # 4\/4\u62cd\n  Line(c(\"C5\", \"D5\", \"E5\", \"F5\"))  # \u97f3\u7b26\u5e8f\u5217\nmusic\n# \u5c55\u793a\u4e50\u8c31\uff08\u8c03\u7528MuseScore\u6e32\u67d3\u5e76\u6253\u5f00\uff09\nshow(music)\nvignette(\"gm\")<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u56db\u3001\u5173\u952e\u53c2\u6570\u8bf4\u660e<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u5143\u7d20<\/th><th>\u5e38\u7528\u53c2\u6570<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>note()<\/code><\/td><td><code>pitch<\/code>\uff08\u97f3\u9ad8\uff09\u3001<code>octave<\/code>\uff08\u516b\u5ea6\uff09\u3001<code>duration<\/code>\uff08\u65f6\u503c\uff09<\/td><td>\u65f6\u503c\u53ef\u9009\uff1a<code>whole<\/code>\uff08\u5168\u97f3\u7b26\uff09\u3001<code>half<\/code>\uff08\u4e8c\u5206\uff09\u3001<code>quarter<\/code>\uff08\u56db\u5206\uff09\u3001<code>eighth<\/code>\uff08\u516b\u5206\uff09\u3001<code>16th<\/code>\uff08\u5341\u516d\u5206\uff09<\/td><\/tr><tr><td><code>chord()<\/code><\/td><td><code>pitches<\/code>\uff08\u97f3\u9ad8\u5411\u91cf\uff09\u3001<code>octave<\/code>\u3001<code>duration<\/code><\/td><td>\u591a\u4e2a\u97f3\u9ad8\u540c\u65f6\u53d1\u58f0\uff0c\u5982<code>chord(c(\"C\",\"E\",\"G\"), 4)<\/code><\/td><\/tr><tr><td><code>rest()<\/code><\/td><td><code>duration<\/code><\/td><td>\u4f11\u6b62\u7b26\uff0c\u53c2\u6570\u540c\u97f3\u7b26<\/td><\/tr><tr><td><code>export()<\/code><\/td><td><code>file<\/code>\u3001<code>format<\/code><\/td><td>format \u53ef\u9009\uff1a<code>musicxml<\/code>\uff08\u9ed8\u8ba4\uff09\u3001<code>pdf<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u603b\u7ed3<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6838\u5fc3\u6d41\u7a0b<\/strong>\uff1a\u521d\u59cb\u5316<code>Music<\/code>\u5bf9\u8c61 \u2192 \u8bbe\u7f6e\u5168\u5c40\u5c5e\u6027\uff08\u62cd\u53f7 \/ \u8c03\u53f7 \/ \u901f\u5ea6\uff09 \u2192 \u6dfb\u52a0<code>Part<\/code>\uff08\u58f0\u90e8\uff09 \u2192 \u7ed9<code>Measure<\/code>\uff08\u5c0f\u8282\uff09\u6dfb\u52a0\u97f3\u7b26 \/ \u548c\u5f26 \/ \u4f11\u6b62\u7b26 \u2192 \u5bfc\u51fa \/ \u9884\u89c8\u3002<\/li>\n\n\n\n<li><strong>\u5173\u952e\u4f9d\u8d56<\/strong>\uff1a\u4f7f\u7528<code>pdf\/png<\/code>\u5bfc\u51fa\u529f\u80fd\u5fc5\u987b\u5b89\u88c5 LilyPond \u5e76\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u5426\u5219\u4ec5\u80fd\u5bfc\u51fa MusicXML\u3002<\/li>\n\n\n\n<li><strong>\u7075\u6d3b\u64cd\u4f5c<\/strong>\uff1a\u53ef\u901a\u8fc7<code>modify_note()<\/code>\/<code>add_measure()<\/code>\u7b49\u51fd\u6570\u52a8\u6001\u4fee\u6539\u4e50\u8c31\uff0c\u652f\u6301\u7a0b\u5e8f\u5316\u751f\u6210\u590d\u6742\u65cb\u5f8b\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u5982\u679c\u9700\u8981\u7279\u5b9a\u573a\u666f\u7684\u793a\u4f8b\uff08\u5982\u8282\u594f\u578b\u751f\u6210\u3001\u8c03\u5f0f\u8f6c\u6362\uff09\uff0c\u53ef\u4ee5\u544a\u8bc9\u6211\uff0c\u6211\u4f1a\u8865\u5145\u5bf9\u5e94\u7684\u4ee3\u7801\u3002<\/p>\n\n\n\n<p>\u4f5c\u8005flujoo\uff1a\u6211\u7684 R \u9879\u76ee\uff1ahttps:\/\/github.com\/flujoo\/gm<\/p>\n\n\n\n<p>See&nbsp;<a href=\"https:\/\/flujoo.github.io\/gm\/articles\/gm.html\"><code>vignette(\"gm\")<\/code><\/a>&nbsp;for a complete guide to gm.<\/p>\n\n\n\n<p><a href=\"https:\/\/flujoo.github.io\/gm\/articles\/gm.html\">Complete Guide to gm \u2022 gm<\/a> \u67e5\u770bgm\u5b8c\u6574\u6559\u7a0b<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f60\u60f3\u8981\u4e86\u89e3 R \u8bed\u8a00\u4e2d gm\uff08Graphical Music\uff09\u5305\u7684\u4f7f\u7528\u65b9\u6cd5\u5e76\u83b7\u53d6 <span class=\"readmore\"><a href=\"http:\/\/xc.ipyingshe.net:5347\/?p=6865\">Continue Reading<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["post-6865","post","type-post","status-publish","format-standard","hentry","category-music"],"_links":{"self":[{"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/6865","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6865"}],"version-history":[{"count":6,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/6865\/revisions"}],"predecessor-version":[{"id":6881,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/6865\/revisions\/6881"}],"wp:attachment":[{"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6865"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}