{"id":6921,"date":"2026-01-22T17:20:05","date_gmt":"2026-01-22T09:20:05","guid":{"rendered":"http:\/\/192.168.1.29\/?p=6921"},"modified":"2026-01-24T00:03:21","modified_gmt":"2026-01-23T16:03:21","slug":"r%e8%af%ad%e8%a8%80%e7%8e%a9%e9%9f%b3%e4%b9%90","status":"publish","type":"post","link":"http:\/\/50btvfr9.ipyingshe.net:5347\/?p=6921","title":{"rendered":"R\u8bed\u8a00\u73a9\u97f3\u4e50"},"content":{"rendered":"\n<p>\u4f7f\u7528\u5e2e\u52a9\u4fe1\u606f\uff0c\u8bbf\u95ee\uff1a<a href=\"https:\/\/github.com\/flujoo\/gm?tab=readme-ov-file\" data-type=\"link\" data-id=\"https:\/\/github.com\/flujoo\/gm?tab=readme-ov-file\" target=\"_blank\" rel=\"noreferrer noopener\">readme<\/a><\/p>\n\n\n\n<div data-wp-interactive=\"core\/file\" class=\"wp-block-file\"><object data-wp-bind--hidden=\"!state.hasPdfPreview\" hidden class=\"wp-block-file__embed\" data=\"http:\/\/192.168.1.29\/wp-content\/uploads\/2026\/01\/rmusic.pdf\" type=\"application\/pdf\" style=\"width:100%;height:600px\" aria-label=\"\u5d4c\u5165 rmusic\"><\/object><a id=\"wp-block-file--media-c2b8176e-456d-47c7-97d2-3435913c2041\" href=\"http:\/\/192.168.1.29\/wp-content\/uploads\/2026\/01\/rmusic.pdf\">rmusic<\/a><a href=\"http:\/\/192.168.1.29\/wp-content\/uploads\/2026\/01\/rmusic.pdf\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-c2b8176e-456d-47c7-97d2-3435913c2041\">\u4e0b\u8f7d<\/a><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>---\ntitle: \"R Notebook\"\noutput: html_notebook\n---\n```{r}\n# \u52a0\u8f7dgm\u5305\nlibrary(gm)\n# \u751f\u6210\u4e50\u8c31\u6570\u636e\n# Create a flute \u4e50\u566874 \u957f\u7b1b\nflute &lt;- Instrument(74, pan = -90)\nflute\n# Create a tempo\ntempo &lt;- Tempo(60, marking = \"Adagio (half = 25)\")\ntempo\n#music \nmusic &lt;- \n  Music() +\n  Meter(4, 4) +  # 4\/4\u62cd\n  Line(c(\"E5\",\"E5\",\"E5\",\"G5\",\"A5\", \"G5\", \"c5\", \"D5\")) + flute + tempo  # \u97f3\u7b26\u5e8f\u5217\nmusic\n\n# \u5c55\u793a\u4e50\u8c31\uff08\u751f\u6210MP3\u97f3\u4e50\u3001\u53ef\u8c03\u7528MuseScore\u6e32\u67d3\u5e76\u6253\u5f00\uff09\nexport(music,\"~\/x.mp3\",\"musescore\")\nexport(music,\"~\/x.mscz\",\"musescore\")\n\n#\u6253\u5f00\u7f51\u9875\u3001musescore \u7f16\u8f91\u67e5\u770b\u4e50\u66f2\nshow(music,musescore = \"-r 800 -T 5\")\n\n#vignette(\"gm\") \u663e\u793a\u5e2e\u52a9\u4fe1\u606f\n\n```<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u66f4\u591a\u793a\u4f8b\u4ee3\u7801\uff1a<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>---\ntitle: \"R Notebook\"\noutput:\n  pdf_document: default\n  html_notebook: default\n---\n# R\u8bed\u8a00gm\u97f3\u4e50\u5305\u57fa\u672c\u8bed\u6cd5\n```{r}\n# \u52a0\u8f7dgm\u5305\nlibrary(gm)\n# \u751f\u6210\u4e50\u8c31\u6570\u636e\n# Create a flute \u4e50\u566874 \u957f\u7b1b\nflute &lt;- Instrument(41, pan = -90)\nflute\nslur &lt;- Slur(3, 8) #\u8fde\u97f3\u7ebf\n# Create a tempo\ntempo &lt;- Tempo(60, marking = \"Adagio (half = 25)\")\nnotehead &lt;- Notehead(1, shape = \"diamond\", color = \"#800080\")\ntie &lt;- Tie(1) #\u8fde\u97f3 \nline &lt;- Line(\n  pitches = c(\"E5\",\"E5\",\"E5\",\"G5\",\"A5\", \"G5\", \"c5\",\"D5\",\"e5\",\"c5\",\"g4\",\"a4\",\"c5\",\"a4\",\"g4\",\"c-5\",\"g#4\"),\n  durations = c(1, 1, 1,1,0.5,0.5 )\n)\n#music \nmusic &lt;- \n  Music() +\n  Meter(3, 4) +  # 4\/4\u62cd\n  line + #\u58f0\u8c03 -\u964d\u8c03\n  flute + \n  tempo +\n  notehead  +\n  slur +       # lianyinfu\n  tie          # \u97f3\u7b26\u5e8f\u5217\n\n# \u5c55\u793a\u4e50\u8c31\uff08\u751f\u6210MP3\u97f3\u4e50\u3001\u53ef\u8c03\u7528MuseScore\u6e32\u67d3\u5e76\u6253\u5f00\uff09\nexport(music,\"~\/x.mp3\",\"musescore\")\nexport(music,\"~\/x.mscz\",\"musescore\")\n\n#\u6253\u5f00\u7f51\u9875\u3001musescore \u7f16\u8f91\u67e5\u770b\u4e50\u66f2\nshow(music,musescore = \"-r 800 -T 5\")\n\n#vignette(\"gm\") \u663e\u793a\u5e2e\u52a9\u4fe1\u606f\n\n```\n# example1\n```{r}\n# \u5047\u8bbe gm \u652f\u6301\u5b57\u7b26\u4e32\u89e3\u6790\uff08\u5426\u5219\u9700\u624b\u52a8\u8f6c\u6362\uff09\nnotes &lt;- c(\"C4\", \"E4\", \"G4\", \"C4\",\"E4\",\"E4\",\"E4\",\"G4\",\"A4\", \"G4\")\n# \u8f6c\u6362\u4e3a MIDI \u7f16\u53f7\uff08\u624b\u52a8\u6620\u5c04\uff09\ninstrument= Instrument(77)\nnote_to_midi &lt;- function(note) {\n  notes_map &lt;- list(\n    C4 = 60, Cs4 = 61, D4 = 62, Ds4 = 63, E4 = 64, F4 = 65,\n    Fs4 = 66, G4 = 67, Gs4 = 68, A4 = 69, As4 = 70, B4 = 71\n  )\n  notes_map&#91;&#91;note]]\n}\npitches &lt;- sapply(notes, note_to_midi)\npitches\nmusic&lt;- Music() +\n        Meter(3, 4) +   # 4\/4\u62cd\n        Line(pitches)+\n        instrument\n\nshow(music)\n```\n# example2 \u6df7\u5408\u65f6\u503c\uff0c\u4e0d\u540c\u4e50\u5668\n```{r}\npitches &lt;-c(67, 67, 67, 62, 65, 67, 69, 67)\ndurations &lt;- c(0.5, 0.5, 1, 2, 0.5, 0.5, 1, 2)   # \u516b\u5206+\u516b\u5206+\u56db\u5206 \/ \u4e8c\u5206 \/ ...\ntempo = Tempo(120)\nvelocity = Velocity(100)  #\u529b\u5ea6\nriff &lt;-Music()+ \n  Meter(3,4)+\n  Line(pitches,durations) +\n  tempo+ \n  velocity\n\nexport(riff, \"~\\\\riff.mid\")\nshow(riff)\n```\n# example3 \u7b80\u5355\u65cb\u5f8b\n\n```{r}\nlibrary(gm)\n\n# \u5b9a\u4e49\u65f6\u503c\uff08\u5168\u90e8\u4e3a\u56db\u5206\u97f3\u7b26\uff09\ninstrument = Instrument(41) #\u5c0f\u63d0\u7434\ntempo= Tempo(90)\nline &lt;- Line(\n  pitches = c(60, 62, 64, 65, 67, 69, 71, 72,73,69, 71, 72,73) , \n  durations = c(1, 1, 1.5, 0.5,1)\n)\n# \u521b\u5efa\u97f3\u4e50\u7ebf\u6761\nmelody &lt;- \n  Music() +\n  Meter(4, 4) +   # 4\/4\u62cd\n  line +\n  instrument + \n  tempo          # \u97f3\u7b26\u5e8f\u5217\n\n# \u64ad\u653e\u6216\u5bfc\u51fa\n#show(melody,musescore = \"-r 800 -T 5\") \nshow(melody) # \u5982\u679c\u6709\u97f3\u9891\u8f93\u51fa\u652f\u6301\nexport(melody, \"~\/scale.mid\",\"musescore\")\n\n```\n\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u5e2e\u52a9\u4fe1\u606f\uff0c\u8bbf\u95ee\uff1areadme \u66f4\u591a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,27],"tags":[],"class_list":["post-6921","post","type-post","status-publish","format-standard","hentry","category-r","category-music"],"_links":{"self":[{"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/6921","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6921"}],"version-history":[{"count":4,"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/6921\/revisions"}],"predecessor-version":[{"id":6928,"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/6921\/revisions\/6928"}],"wp:attachment":[{"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6921"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}