root/lang/ruby/smtools/lrcconv.rb

Revision 27252, 2.5 kB (checked in by isaisstillalive, 6 years ago)

StepMania用譜面データを操作するライブラリ。

ライブラリ自体は未完成だが、それを使用した

のソースコード付き。

Line 
1require "optparse"
2require File.expand_path(File.join(File.dirname(__FILE__), "lib", "lyric_converter"))
3
4$application = LyricConverter.new
5
6ARGV.options do |option|
7  option.program_name = "LyricConverter"
8  option.version = "1.0.2"
9  option.release = nil
10  option.summary_indent = "  "
11  option.summary_width = 24
12 
13  option.banner = "Usage: lrcconv [options] source-file"
14 
15  option.separator(" ")
16  option.separator("Convert options:")
17  option.on("-s", "--sm-file=filename", String, "StepMania sequence file (use BPMS and OFFSET)") do |value|
18    $application.sequence = SMTools::Sequence.parse(File.read(value))
19  end
20  option.on("-b", "--bpm=BPM", Float, "BPM") do |value|
21    $application.bpm = value
22  end
23  option.on("--bpms=BPMS", String, "StepMania compatible BPMS format") do |value|
24    $application.bpms = value
25  end
26  option.on("-o", "--offset=seconds", Float, "Offset seconds") do |value|
27    $application.offset = value
28  end
29  option.separator(" ")
30  option.separator("Output options:")
31  option.on("-f", "--format=type", [:lrc, :sm, :miku], "Output format type (lrc, sm, miku)") do |value|
32    $application.format = value
33  end
34 
35  option.separator(" ")
36  option.separator("Source file format:")
37  source_file_format = <<-'SOURCE_FILE_FORMAT'
38  #!          command-line options (first line only)
39  {number}    beat lyric line
40  [number]    time lyric line
41  #           ignore line
42  string      through line
43  [string]    through line
44 
45  ex)
46  source:
47    #! --bpm=120 --offset=-0.5
48    [COLOUR]0xFFFFFF
49   
50    [0.0]Hello Goodbye
51    {0.0}Hello, World.
52    {8.0}Goodbye, World.
53   
54  output lrc:
55    [COLOUR]0xFFFFFF
56   
57    [00:00:00]Hello Goodbye
58    [00:00:50]Hello, World.
59    [00:04:50]Goodbye, World.
60  SOURCE_FILE_FORMAT
61 
62  source_file_format.lines.each do |line|
63    option.separator line.chomp
64  end
65 
66  begin
67    option.parse!
68  rescue => err
69    $stderr << err
70    exit(false)
71  end
72 
73  unless $source
74    import_file = ARGV.shift
75    unless import_file
76      $stdout << option.help
77      exit
78    end
79    unless File.exist? import_file
80      $stderr << "No such file or directory -- #{import_file}"
81      exit(false)
82    end
83   
84    $source = File.read(import_file)
85    if $source[0, 2] == "#!"
86      match = /\A#!(.*)$/u.match $source
87      ARGV.replace match[1].split(" ")
88      retry
89    end
90  end
91end
92
93begin
94  $stdout << $application.execute($source)
95rescue IndexError => e
96  $stderr << "Error: #{e.message}"
97end
Note: See TracBrowser for help on using the browser.