Example #1
0
	def emit(self, track):
		""" 
		Can be called by most child methods 
		by filling in self.data as a string, setting self.type, 
		then calling: Meta_Event.emit(self, track)
		"""
		track.append(chr(0xff))		# all meta start with 0xff
		track.append(chr(self.event_type))
		track.append(MFF.vlq(len(self.data)))
		track.append(self.data)
Example #2
0
	def create_MFF(self, outfile, txt_file):
		""" 
		Create a MIDI File Format file - based on the events
	    	in the song object - output to previously opened file
		"""
	
		# We emit a header chunk and then one or more track chunks.
	
		# create head object, initialize, post to file...
		head = MFF.Header_Chunk()
		# initialze the hearder chunk values...
		head.Init(fformat=self.format, tracks=self.track_count, ppq=self.PPQ)

		#head.dump()	# debug output
		head.post(outfile)	# output the header
		
		# 
		# initialize a table of positions for each track,
		# at the same time - create an event for each track 
		# that sets the name
		
		track_pos = []
		for i in range(self.track_count):
			track_pos.append(0)		# where we are in each tack...
			name_ev = Meta_Event()	# "generic"
			name_ev.type = "TRACK NAME"
			name_ev.event_type = 0x03	# sequence/track name
			name_ev.data = self.track_list[i].name
			name_ev.track_num = i
			name_ev.pos = 0
			self.append(name_ev)

		self.events.sort(key=poskey)	# put the events in time order...

		track_index = 0

		for event in self.events:
			track_index = event.track_num
			diff = event.pos - track_pos[track_index]
			if diff < 0:
				print "Event / pos", event.pos, track_pos[track_index]
			track = self.track_list[track_index]
			track.append(MFF.vlq(diff))	# add the delta-time
			event.emit(track)		# add the event...
			track_pos[track_index]= event.pos
		
		print "Track count:", self.track_count
		for track_num in range(self.track_count):
			#print "Ending track", track_num
			self.track_list[track_num].end()
			#print "Posting track", track_num
			#self.track_list[track_num].dump()
			self.track_list[track_num].post(outfile)
Example #3
0
	def emit(self, track):
		#print "Emitting Tempo Event", self.t_val, self.track_num, self.pos
		# 
		self.data = MFF.int2chars(self.t_val, 3) 	 # three byte value...
		# call the parent class...
		Meta_Event.emit(self, track)