Skip to content

Instantly share code, notes, and snippets.

@asm256
Last active August 29, 2015 14:07
Show Gist options
  • Save asm256/fc51b24aeb0fe1f9f5ee to your computer and use it in GitHub Desktop.
Save asm256/fc51b24aeb0fe1f9f5ee to your computer and use it in GitHub Desktop.
data.csv 2 7keybms
#1小節 = 4beat
#160bpm -> 40小節/min
# 60*4 / 160 で1小節あたりの秒数がとれる
# = 1.5s
#1beat = 0.375s
require 'csv'
require 'rational'
#ここ適宜書き換え
#魔法のヒカリは160bpm
title = "魔法のヒカリ(short) Hard"
artist = "HIRO.K"
bpm = 160
difficulty = 3
#First Story
#title = "First Story(long) Hard"
#artist = "Elements Garden"
#bpm = 184
#difficulty = 5
#ここまで
bar_sec = 1.0/ bpm * 240
chtable = [11,12,13,14,15,18,19]
class Float
def self.set_bpm bpm
@@bme_yuragi = Rational(240,bpm ) / (256 * 256)
end
def to_rat
#128分音符以上が出現しないように正規化
(1..256).reduce(0){|_emp,x|
r = self.rationalize(@@bme_yuragi * x)
break r if r.denominator <= 128
}
end
end
Float.set_bpm bpm
#譜面読み込み
#Setting以降はアドリブ/プレミアゾーンなので捨てる
score = File.binread('data.csv').split('Setting')[0]
csv = CSV.parse(score ,converters: :numeric)
#TOTAL http://nekokan.dyndns.info/~268/memo/total.html
tnotes = csv.map{|x| x[1..-1].count(1)}.reduce(:+)
tscore =tnotes < 400 ? 200 + (tnotes / 5) :
tnotes < 600 ? 280 + ((tnotes - 400) / 2.5) :
360 + ((tnotes - 600) / 5)
offset = csv[0][0]
bar_offset = offset > bar_sec ? 1 : 0
offset = 0 if bar_offset == 0
File.write('mahou.bme',<<"BME" +
*---------------------- HEADER FIELD
#PLAYER 1
#GENRE GameMusic
#TITLE #{title}
#ARTIST #{artist}
#BPM #{bpm}
#PLAYLEVEL #{difficulty}
#RANK 2
#TOTAL #{tscore}
*---------------------- MAIN FIELD
#{<<"exBPM" if offset > bar_sec
#BPM11 #{240 / offset}
#00008:11
#00103:#{"%02X" % bpm}
exBPM
}
BME
csv.map{|c|
pos = c[0] - offset
#何小節目か?
bn = (pos / bar_sec).to_rat.floor
#小節内のオフセット
bo = pos - bn * bar_sec
bn += bar_offset
#有理化
timing = (bo / bar_sec).to_rat
note = (0..timing.denominator-1).map{|x|
next "00" unless x == timing.numerator
next "01"
}.join
print "error #{c}" if note.chars.count("1") == 0
#出力
notes = c[1,7].each_with_index.select{|v,i| v==1 }.map{|v,i|
ch = chtable[i]
index = "#%03d%02d:" % [ bn , ch] + note
}.join("\n")
}.join("\n") )
@asm256
Copy link
Author

asm256 commented Oct 5, 2014

小節線付近でちょっとバグる可能性あり

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment