bangkok 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +15 -0
- data/README +11 -2
- data/bin/bangkok +11 -7
- data/lib/bangkok/chessgame.rb +3 -4
- data/lib/bangkok/gamelistener.rb +43 -37
- data/lib/bangkok/info.rb +1 -1
- metadata +1 -1
data/ChangeLog
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
2005-03-25 Jim Menard <jimm@io.com>
|
2
|
+
|
3
|
+
* lib/bangkok/chessgame.rb: removed shebang line.
|
4
|
+
|
5
|
+
* lib/bangkok/gamelistener.rb (GameListener::initialize): added
|
6
|
+
config file path argument.
|
7
|
+
(GameListener::read_config): created.
|
8
|
+
(GameListener::end_game): io is an instance var, not a local var.
|
9
|
+
Restructured code around filling in config information.
|
10
|
+
|
11
|
+
* bin/bangkok: fixed really stupid syntax errors. Added -c command
|
12
|
+
line argument. Pass config file path to GameListener.
|
13
|
+
|
14
|
+
* Version 0.1.0 released.
|
15
|
+
|
1
16
|
2005-03-24 Jim Menard <jimm@io.com>
|
2
17
|
|
3
18
|
* Initial project creation.
|
data/README
CHANGED
@@ -10,12 +10,21 @@ Bangkok originated as the code for an art project by Tom Peak
|
|
10
10
|
|
11
11
|
The Web site of Bangkok is (http://bangkok.rubyforge.org). The RubyForge
|
12
12
|
project page is http://rubyforge.org/projects/bangkok, where the latest
|
13
|
-
version of bangkok may be downloaded.
|
13
|
+
version of bangkok may be downloaded. Bangkok is also available as a RubyGem.
|
14
14
|
|
15
15
|
|
16
16
|
=== Recent Changes
|
17
17
|
|
18
|
-
|
18
|
+
==== 0.1.1
|
19
|
+
|
20
|
+
* Fixed bugs in the bin/bangkok script.
|
21
|
+
|
22
|
+
* Implemented the -c command line argument.
|
23
|
+
|
24
|
+
* Fixed a bug in the GameListener that prevented the MIDI file from being
|
25
|
+
output.
|
26
|
+
|
27
|
+
* Added parsing of the config file to GameListener.
|
19
28
|
|
20
29
|
|
21
30
|
== Dependencies
|
data/bin/bangkok
CHANGED
@@ -8,9 +8,10 @@ end
|
|
8
8
|
|
9
9
|
def usage
|
10
10
|
$stderr.puts <<EOS
|
11
|
-
usage: bangkok [-v] chessgame.pgn ...
|
12
|
-
-
|
13
|
-
-
|
11
|
+
usage: bangkok [-c config_file] [-v] chessgame.pgn ...
|
12
|
+
-c file Passes config_file to the GameListener
|
13
|
+
-v Verbose (prints each move)
|
14
|
+
-h This message
|
14
15
|
|
15
16
|
Using the default GameListener, creates chessgame.mid for every chessgame.pgn.
|
16
17
|
To use your own GameListener, see the Bangkok README file.
|
@@ -20,10 +21,13 @@ EOS
|
|
20
21
|
end
|
21
22
|
|
22
23
|
$verbose = false
|
23
|
-
g = GetoptLong.new(['-
|
24
|
+
g = GetoptLong.new(['-c', '--config-file', GetoptLong::REQUIRED_ARGUMENT],
|
25
|
+
['-v', '--verbose', GetoptLong::NO_ARGUMENT],
|
24
26
|
['-h', '--help', GetoptLong::NO_ARGUMENT])
|
27
|
+
config_file_path = nil
|
25
28
|
g.each { | opt, arg |
|
26
29
|
case opt
|
30
|
+
when '-c'
|
27
31
|
when '-v'
|
28
32
|
$verbose = true
|
29
33
|
else
|
@@ -33,8 +37,8 @@ g.each { | opt, arg |
|
|
33
37
|
usage if ARGV.length == 0
|
34
38
|
|
35
39
|
ARGV.each { | fname |
|
36
|
-
game = ChessGame.new
|
40
|
+
game = ChessGame.new(GameListener.new(config_file_path))
|
37
41
|
File.open(fname, 'r') { | f | game.read_moves(f) }
|
38
|
-
midi_file_name = File.basename(fname).sub(/(\..+)
|
39
|
-
File.open(midi_file_name, '
|
42
|
+
midi_file_name = File.basename(fname).sub(/(\..+)?$/, '.mid')
|
43
|
+
File.open(midi_file_name, 'wb') { | f | game.play(f) }
|
40
44
|
}
|
data/lib/bangkok/chessgame.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
|
3
1
|
require 'bangkok/gamelistener'
|
4
2
|
require 'bangkok/board'
|
5
3
|
require 'bangkok/move'
|
6
4
|
|
7
|
-
#
|
8
|
-
#
|
5
|
+
# ChessGame takes a listener in its constructor and creates a Board. The
|
6
|
+
# method ChessGame#read_moves reads game data. Calling ChessGame#play moves
|
7
|
+
# the pieces, which in turn sends messages to the listener so it can react.
|
9
8
|
class ChessGame
|
10
9
|
|
11
10
|
def initialize(listener = GameListener.new)
|
data/lib/bangkok/gamelistener.rb
CHANGED
@@ -9,42 +9,6 @@ include MIDI
|
|
9
9
|
# The pieces and board call methods on an instance of GameListener, which
|
10
10
|
# turns those events into MIDI events.
|
11
11
|
class GameListener
|
12
|
-
PIECE_MIDI_INFO = {}
|
13
|
-
PIECE_MIDI_INFO[:white] = {}
|
14
|
-
PIECE_MIDI_INFO[:black] = {}
|
15
|
-
end
|
16
|
-
|
17
|
-
def white(piece_sym, program_change)
|
18
|
-
GameListener::PIECE_MIDI_INFO[:white][piece_sym] = program_change
|
19
|
-
end
|
20
|
-
def black(piece_sym, program_change)
|
21
|
-
GameListener::PIECE_MIDI_INFO[:black][piece_sym] = program_change
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
# Fill in some default values, in case the user does not specify any new ones.
|
26
|
-
black :K, 0
|
27
|
-
black :Q, 8
|
28
|
-
black :R, 16
|
29
|
-
black :B, 24
|
30
|
-
black :N, 32
|
31
|
-
black :P, 4
|
32
|
-
white :K, 4
|
33
|
-
white :Q, 12
|
34
|
-
white :R, 20
|
35
|
-
white :B, 28
|
36
|
-
white :N, 36
|
37
|
-
white :P, 44
|
38
|
-
|
39
|
-
class GameListener
|
40
|
-
|
41
|
-
attr_reader :seq # MIDI::Sequence
|
42
|
-
|
43
|
-
# TODO remove this and specify it some other way
|
44
|
-
begin
|
45
|
-
require 'chess_config' # Fills in PIECE_MIDI_INFO
|
46
|
-
rescue LoadError
|
47
|
-
end
|
48
12
|
|
49
13
|
PIECE_NAMES = {
|
50
14
|
:P => "Pawn",
|
@@ -69,6 +33,48 @@ class GameListener
|
|
69
33
|
4.times { | i | RANK_TO_VOL << 10 + ((117.0 / 3.0) * i).to_i }
|
70
34
|
4.times { | i | RANK_TO_VOL << 127 - (((117.0 / 3.0) * i).to_i) }
|
71
35
|
|
36
|
+
PIECE_MIDI_INFO = {}
|
37
|
+
PIECE_MIDI_INFO[:white] = {}
|
38
|
+
PIECE_MIDI_INFO[:black] = {}
|
39
|
+
|
40
|
+
# Used by config files to set the program change value for a piece.
|
41
|
+
def GameListener.white(piece_sym, program_change)
|
42
|
+
PIECE_MIDI_INFO[:white][piece_sym] = program_change
|
43
|
+
end
|
44
|
+
|
45
|
+
# Used by config files to set the program change value for a piece.
|
46
|
+
def GameListener.black(piece_sym, program_change)
|
47
|
+
GameListener::PIECE_MIDI_INFO[:black][piece_sym] = program_change
|
48
|
+
end
|
49
|
+
|
50
|
+
# Fill in some default values, in case the user does not specify any new
|
51
|
+
# ones.
|
52
|
+
black :K, 0
|
53
|
+
black :Q, 8
|
54
|
+
black :R, 16
|
55
|
+
black :B, 24
|
56
|
+
black :N, 32
|
57
|
+
black :P, 4
|
58
|
+
white :K, 4
|
59
|
+
white :Q, 12
|
60
|
+
white :R, 20
|
61
|
+
white :B, 28
|
62
|
+
white :N, 36
|
63
|
+
white :P, 44
|
64
|
+
|
65
|
+
attr_reader :seq # MIDI::Sequence
|
66
|
+
|
67
|
+
def initialize(config_file_path=nil)
|
68
|
+
read_config(config_file_path) if config_file_path
|
69
|
+
end
|
70
|
+
|
71
|
+
def read_config(config_file_path)
|
72
|
+
IO.readlines(config_file_path).each { | line |
|
73
|
+
line.chomp!
|
74
|
+
class_eval(line)
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
72
78
|
def track_of(piece)
|
73
79
|
i = [:white, :black].index(piece.color) * 6 +
|
74
80
|
[:P, :R, :N, :B, :Q, :K].index(piece.piece)
|
@@ -103,7 +109,7 @@ class GameListener
|
|
103
109
|
# When we created events, we set their start times, not their delta times.
|
104
110
|
# Now is the time to fix that.
|
105
111
|
@seq.tracks.each { | t | t.recalc_delta_from_times }
|
106
|
-
@seq.write(io)
|
112
|
+
@seq.write(@io)
|
107
113
|
end
|
108
114
|
|
109
115
|
def move(piece, from, to)
|
data/lib/bangkok/info.rb
CHANGED