{"id":1224,"date":"2012-02-02T22:04:15","date_gmt":"2012-02-02T13:04:15","guid":{"rendered":"http:\/\/inter-arteq.com\/?p=1224"},"modified":"2022-03-24T00:57:38","modified_gmt":"2022-03-23T15:57:38","slug":"translate_scale_to_midi_note_number","status":"publish","type":"post","link":"http:\/\/cms.inter-arteq.com\/translate_scale_to_midi_note_number\/","title":{"rendered":"\u97f3\u968e\u3092midi\u30ce\u30fc\u30c8\u30ca\u30f3\u30d0\u30fc\u306b\u5909\u63db\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8"},"content":{"rendered":"\n

\u97f3\u697d\u7cfb\u30e1\u30c7\u30a3\u30a2\u30a2\u30fc\u30c8\u3092\u4f5c\u308b\u3068\u304d\u3001\u3088\u304f\u97f3\u968e\u3092midi\u30ce\u30fc\u30c8\u30ca\u30f3\u30d0\u30fc\u306b\u7f6e\u304d\u63db\u3048\u3066\u6271\u3046\u306e\u3067\u3059\u304c\u3001\u97f3\u968e\u3092midi\u30ce\u30fc\u30c8\u30ca\u30f3\u30d0\u30fc\u306b\u5909\u3048\u308b\u306e\u304c\u3044\u3061\u3044\u3061\u8003\u3048\u3066\u6253\u3064\u306e\u306f\u9762\u5012\u306a\u306e\u3067\u3001\u5909\u63db\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7df4\u7fd2\u304c\u3066\u3089\u306bRuby\u3067\u66f8\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n

\u30b3\u30fc\u30c9<\/h2>\n\n\n\n
p 'e.g.) c d e- e g g+ a'\nline = gets\nnotes = line.split(" ");\n\nmidi = []\nnote_mapper = {\n  c: 0, d: 2, e: 4, f: 5, g: 7, a: 9, b: 11\n}\nacc_mapper = {\n  '+': 1, '-': -1\n}\n\nfor note in notes\n  if note !~ \/^[abcdefg][-+]?$\/\n    p "error! illegal string!"\n    exit()\n  end\n  # \u5e79\u97f3\n  tmp = note_mapper[note[0].to_sym]\n\n  # #\u3068\u266d\n  tmp += acc_mapper[note[1]] || 0\n  midi << tmp\nend\n\ni = 0\nwhile midi[i]+12 < 128\n  midi << midi[i] + 12\n  i += 1\nend\n\np midi<\/code><\/pre><\/div>\n\n\n\n

\u4f7f\u3044\u65b9<\/h2>\n\n\n\n

ruby\u3067\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u8d70\u3089\u305b\u308b\u3068\u3001\u5165\u529b\u5f85\u6a5f\u72b6\u614b\u306b\u306a\u308b\u306e\u3067\u3001\u5c0f\u6587\u5b57\u306e\u82f1\u8a9e\u97f3\u540d\u3092\u30b9\u30da\u30fc\u30b9\u3067\u533a\u5207\u3063\u3066\u5165\u529b\u3059\u308b\u3068midi\u30ce\u30fc\u30c8\u30ca\u30f3\u30d0\u30fc\u304c\u51fa\u3066\u304d\u307e\u3059\u3002\u305f\u3060\u3057\u3001#\u3068\u266d\u306f\u305d\u308c\u305e\u308c\uff0b\u3068\u30fc\u3067\u8868\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n

$ ruby app.rb\ninput scale...\ne.g.) c d e- e g g+ a\nc d e g a (\u5165\u529b\u3059\u308b)\n[0, 2, 4, 7, 9, 12, 14, 16, 19, 21, 24, 26, 28, 31, 33, 36, 38, 40, 43, 45, 48, 50, 52, 55, 57, 60, 62, 64, 67, 69, 72, 74, 76, 79, 81, 84, 86, 88, 91, 93, 96, 98, 100, 103, 105, 108, 110, 112, 115, 117, 120, 122, 124, 127]<\/code><\/pre><\/div>\n\n\n\n

\u3042\u3068\u306f\u5fc5\u8981\u306amidi\u30ce\u30fc\u30c8\u30ca\u30f3\u30d0\u30fc\u3092\u5fc5\u8981\u306a\u6570\u3060\u3051\u629c\u7c8b\u3057\u3066\u3042\u3052\u308c\u3070OK\u3067\u3059\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"

\u97f3\u697d\u7cfb\u30e1\u30c7\u30a3\u30a2\u30a2\u30fc\u30c8\u3092\u4f5c\u308b\u3068\u304d\u3001\u3088\u304f\u97f3\u968e\u3092midi\u30ce\u30fc\u30c8\u30ca\u30f3\u30d0\u30fc\u306b\u7f6e\u304d\u63db\u3048\u3066\u6271\u3046\u306e\u3067\u3059\u304c\u3001\u97f3\u968e\u3092midi\u30ce\u30fc\u30c8\u30ca\u30f3\u30d0\u30fc\u306b\u5909\u3048\u308b\u306e\u304c\u3044\u3061\u3044\u3061\u8003\u3048\u3066\u6253\u3064\u306e\u306f\u9762\u5012\u306a\u306e\u3067\u3001\u5909\u63db\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7df4\u7fd2\u304c\u3066\u3089\u306bRuby\u3067\u66f8\u304d\u307e\u3057\u305f\u3002 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5,53,25],"tags":[50],"class_list":["post-1224","post","type-post","status-publish","format-standard","hentry","category-program","category-ruby","category-music","tag-ruby"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/posts\/1224"}],"collection":[{"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/comments?post=1224"}],"version-history":[{"count":4,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/posts\/1224\/revisions"}],"predecessor-version":[{"id":208553,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/posts\/1224\/revisions\/208553"}],"wp:attachment":[{"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/media?parent=1224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/categories?post=1224"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/tags?post=1224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}