8 # Required information for a loader module. If this isn't here, the game
9 # will crash and burn and it will be ALL YOUR FAULT.
10 name = "BeMusic BMS/BME"
14 res = [re.compile("^#PLAYLEVEL"), re.compile("^#WAV"), re.compile("^#BMP")]
19 for n in range(0,len(res)):
20 if res[n].match(line):
22 return sum(match) / float(len(match))
27 r = re.compile('(WAV|BMP|\d{5}:)')
29 if len(line) == 0 or line[0] != "#":
38 d[cmd.lower()] = arg.strip()
41 def load(file,status=lambda x,y:None):
42 keymapping = {0:1, 1:2, 2:3, 3:4, 4:5, 5:0, 7:6, 8:7}
44 kf.numkeys = len(keymapping)
46 dir = os.path.dirname(file)
51 if len(line) == 0 or line[0] != "#":
70 kf.add(BMEvent(0, BME_TEMPO, None, lastbpm))
72 print "Invalid value for BPM"
73 #kf.ms_per_measure = 240000.0 / kf.bpm
74 elif cmd == "PLAYLEVEL":
76 kf.playlevel = int(arg)
78 print "Invalid value for PLAYLEVEL"
83 print "Invalid value for RANK"
84 elif cmd == "STAGEFILE":
85 # This will stay here for now. Eventually, this
86 # will go into the "status" routine or somewhere
89 kf.stagefile = loadBMP(os.path.join(dir,arg))
90 status("STAGEFILE",kf.stagefile)
92 kf.volwav = float(arg) / 100.0
93 elif cmd[0:3] == "WAV":
94 slot = int(cmd[3:5],36)
95 if arg[-3:].lower() == 'mp3':
96 wav = loadMP3(os.path.join(dir,arg))
98 wav = loadWAV(os.path.join(dir,arg))
100 wav.set_volume(kf.volwav)
105 status("ERROR","Could not load " + arg)
106 pygame.time.wait(1500)
107 elif cmd[0:3] == "BMP":
108 slot = int(cmd[3:5],36)
109 bmp = loadBMP(os.path.join(dir,arg))
114 status("ERROR","Could not load " + arg)
115 elif len(cmd) > 5 and cmd[5] == ":":
116 # Hmm. Should "track" really be "measure"?
117 track = int(cmd[0:3])
118 channel = int(cmd[3:5])
122 # Channel 2 is a floating-point
123 # multiplier that changes the length of
125 kf.add(BMEvent(track*4, BME_LONGMEASURE, None, float(message)))
127 if track != kf.track:
128 status("TRACK",track)
131 v = [int(message[n*2:n*2+2],36) for n in range(0,len(message)/2)]
132 l = float(len(v)) / 4.0
136 for n in range(0,len(v)):
139 bme = BMEvent(track*4 + n / l, BME_BGM, None, v[n])
142 v = [int(message[n*2:n*2+2],16) for n in range(0,len(message)/2)]
143 for n in range(0,len(v)):
144 # WTF is up with the low tempos?
145 if v[n] == 0 or v[n] < 30:
147 print "new BPM: " + str(v[n])
148 bme = BMEvent(track*4 + n / l, BME_TEMPO, None, v[n])
152 for n in range(0,len(v)):
155 bme = BMEvent(track*4 + n / l, BME_BGA, None, v[n])
157 elif (channel >= 11 and channel <= 19) or (channel >= 21 and channel <= 29):
158 if channel >= 21 and channel <= 29:
164 for n in range(0,len(v)):
165 if v[n] == 0 or not (channel - b) in keymapping:
167 bme = BMEvent(track*4 + n / l, type, keymapping[channel - b], v[n])
170 print "Unknown command:",cmd