Allow input on command line

This commit is contained in:
Matthias Neeracher 2007-10-17 15:41:50 +00:00
parent 0755217a57
commit 37954c7b4f
5 changed files with 27 additions and 21 deletions

View File

@ -61,17 +61,17 @@ KEY = [[ 0, 1],
[ 3,-1], [-2,-1], [ 5,-1], [ 0,-1], [-5,-1], [ 2,-1],
[ 4,-1], [ 6,-1], [ 3,-1], [ 5,-1], [ 7,-1]]
$stdin.read(1) # Skip 1 Byte
titleLen = $stdin.read(1)[0]
OUTPUT['title'] = $stdin.read(titleLen)
INFILE.read(1) # Skip 1 Byte
titleLen = INFILE.read(1)[0]
OUTPUT['title'] = INFILE.read(titleLen)
$stdin.read(2) # Skip 2 Bytes
gr = $stdin.read(1)[0]-1
INFILE.read(2) # Skip 2 Bytes
gr = INFILE.read(1)[0]-1
groove = GROOVE[gr] || ['Swing']
key = KEY[$stdin.read(1)[0]]
key = KEY[INFILE.read(1)[0]]
PROP['key'] = key[0]
PROP['mode'] = key[1]
OUTPUT['tempo'] = $stdin.read(1)[0]
OUTPUT['tempo'] = INFILE.read(1)[0]
#
# Style map - not processed yet
@ -79,12 +79,12 @@ OUTPUT['tempo'] = $stdin.read(1)[0]
STYLES = []
i=0
while i < 256
st = $stdin.read(1)[0]
st = INFILE.read(1)[0]
if st > 0
STYLES[i-1] = st
i += 1
else
i += $stdin.read(1)[0]
i += INFILE.read(1)[0]
end
end
@ -282,12 +282,12 @@ EXT = [
STEPS = []
i = 0
while i < 1020
ex = $stdin.read(1)[0]
ex = INFILE.read(1)[0]
if ex > 0
STEPS[i] = EXT[ex]
i += 1
else
i += $stdin.read(1)[0]
i += INFILE.read(1)[0]
end
end
@ -297,7 +297,7 @@ CHORDS = []
ROOTS = []
i = 0
while i < 1021
cr = $stdin.read(1)[0]
cr = INFILE.read(1)[0]
if cr > 0
CHORDS[i] = PITCHES[cr % 18]
if cr > 18
@ -305,15 +305,15 @@ while i < 1021
end
i += 1
else
i += $stdin.read(1)[0]
i += INFILE.read(1)[0]
end
end
$stdin.read(1) # Start measure
numMeasures = $stdin.read(1)[0]
numRepeats = $stdin.read(1)[0]
INFILE.read(1) # Start measure
numMeasures = INFILE.read(1)[0]
numRepeats = INFILE.read(1)[0]
biab = $stdin.read
biab = INFILE.read
styleFile = nil
if biab =~ /B.(.{1,8})\.STY/m

View File

@ -14,7 +14,7 @@ OUTPUT = {'measures' => []}
# Lex
#
tokens = []
$stdin.each do |line|
INFILE.each do |line|
line.chomp!.sub!(/%.*/, "")
line.scan(%r$\G\s*(\{|\}|\(|\)|\||=|~|<<|>>|--|#'|#\(|##t|##f|\\\w+|\".*?\"|\w[-+\w\d.',:*/]+|.)$) do |token|
tokens.push(token[0])

View File

@ -444,7 +444,7 @@ class MusicXMLListener
end
listener = MusicXMLListener.new
REXML::Document.parse_stream($stdin, listener)
REXML::Document.parse_stream(INFILE, listener)
writePlist($stdout, OUTPUT)
# Local Variables:

View File

@ -7,7 +7,7 @@ require File.dirname($0)+'/plistReader'
require File.dirname($0)+'/vl'
require 'rexml/document'
INPUT = readPlist($stdin)
INPUT = readPlist(INFILE)
$USE_FLATS = false
$DIVISIONS = 3

View File

@ -112,7 +112,7 @@ class VL
@denom /= g
end
def -()
def -@()
return Fract.new(-@num, @denom)
end
@ -129,3 +129,9 @@ class VL
end
end
end
if ARGV.size > 0
INFILE = File.new(ARGV[0], "r")
else
INFILE = $stdin
end