class String
@@MultiByteToWideChar = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
@@WideCharToMultiByte = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
def s2u
i = @@MultiByteToWideChar.call(0, 0, self, -1, nil, 0)
buffer = "\0" * (i*2)
@@MultiByteToWideChar.call(0, 0, self, -1, buffer, buffer.size / 2)
i = @@WideCharToMultiByte.call(65001, 0, buffer, -1, nil, 0, nil, nil)
result = "\0" * i
@@WideCharToMultiByte.call(65001, 0, buffer, -1, result, result.size, nil, nil)
result.chop!
return result
end
end
class Lrc
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
def initialize(songname)
# 获取歌词
lrc = File.open("Audio/BGM/#{songname}.lrc").read.s2u.split("\n")
# 分析歌词
@content = []
for line in lrc
unless line[/(?<=\[)\d{2}:\d{2}.\d{2}(?=\])/].nil?
t = line.split(']').size - 1
txt = line.split(']').size == 1 ? "" : line[10*t..-1]
for i in 0..t
l = line[(1+10*i)..(8+10*i)]
min = l.split(':')[0].to_i
a = l.split(':')[1].to_s
sec = a.split('.')[0].to_i
msec = a.split('.')[1].to_i
unless min*60000+sec*1000+msec*10 == 0
@content.push([min*60000+sec*1000+msec*10, txt])
end
end
end
end
@content.sort!
@content.push([1800000, ''])
# 画图
@sprite = Sprite.new
@sprite.bitmap = Bitmap.new(640,22)
@sprite.x,@sprite.y = 0,458
#@content.each_with_index{|l,i|@sprite.bitmap.draw_text(0,i*22+2,640,22,l[1],1)}
# 记时开始
[url=home.php?mod=space&uid=263426]@temp[/url] = ""
start
end
#--------------------------------------------------------------------------
# ● 刷新精灵
#--------------------------------------------------------------------------
def update
@sprite.opacity += 25 unless @sprite.opacity == 255
if now_lrc != @temp
@sprite.bitmap.clear
@sprite.bitmap.draw_text(0,0,640,22,now_lrc,1)
@temp = now_lrc
@sprite.opacity = 0
end
end
#--------------------------------------------------------------------------
# ● 释放精灵
#--------------------------------------------------------------------------
def dispose
@sprite.bitmap.dispose
@sprite.dispose
@temp = nil
@content = nil
@start_time = nil
end
#--------------------------------------------------------------------------
# ● 获取当前一句歌词
#--------------------------------------------------------------------------
def now_lrc
@content.each_with_index do | t, i |
return @content[i-1][1] if current_time - t[0] <= 0
end
end
#--------------------------------------------------------------------------
# ● 调整纵坐标
#--------------------------------------------------------------------------
def y
return @sprite.y
end
def y=(int)
@sprite.y = int
end
#--------------------------------------------------------------------------
# ● 获取当前毫秒数
#--------------------------------------------------------------------------
def msec
t = Time.now
t.to_i * 1000 + t.usec / 1000
end
#--------------------------------------------------------------------------
# ● 开始 重置 start_time
#--------------------------------------------------------------------------
def start
@start_time = msec
end
#--------------------------------------------------------------------------
# ● 获取时间
#--------------------------------------------------------------------------
def current_time
msec - @start_time
end
end