示例#1
0
    def paste_pattern_clipboard_text_received(self, clipboard, text, data):
        if not text or text == '':
            return
            
        lines = text.split("\n")
        if not len(lines):
            return
            
        if lines[0] != 'Pattern':
            return

        pattern = Pattern()
        self.song.add_pattern(pattern)

        level = 0
        for line in lines:
            if line == "Pattern":
                level = 1

            if line == "Track":
                track = pattern.add_track()
                level = 2
            
            if line == "Notes":
                level = 3

            if level == 1:
                #On Pattern Data
                if line[:5] == "Num: ":
                    pattern.set_num(int(line[5:]))
                elif line[:5] == "Len: ":
                    pattern.set_len(int(line[5:]))
                elif line[:6] == "Name: ":
                    pattern.set_name(line[6:])
            elif level == 2:
                if line[:5] == "Len: ":
                    track.set_len(int(line[5:]))
                elif line[:6] == "Name: ":
                    track.set_name(line[6:])
                elif line[:8] == "Volume: ":
                    track.set_volume(int(line[8:]))
                elif line[:7] == "Synth: ":
                    track.set_synth(line[7:])
                elif line[:6] == "Port: ":
                    track.set_port(int(line[6:]))
            elif level == 3:
                if line == "Notes":
                    pass
                elif line == "EndNotes":
                    level = 2
                else:
                    (note, pos, duration, volume) = line.split(', ')
                    track.add_note(int(note),int(pos),int(duration), int(volume))

        pattern.set_name("Copy of " + pattern.get_name())
        PatternWidget(self, pattern)
        self.refresh_channels()
        self.save_state = False
        return
示例#2
0
	def open(self, filename):
		# Patterns Object
		song = Song()

		f = open(filename)
		line = f.readline()
		#f.write("Desfonema Sequencer File Format Version 1.1\n")
		version = line[40:-1]
		
		#Old version 1 format used 8 ticks for each beat instead of 24
		#so we need to compensate if it's an old format file.
		if version == '1':
			shifter = 3
		else:
			shifter = 1
		#Level Pattern(0) Track(1) or Notes(2)
		level = 0
		while line:
			line = line[:-1]
			if line == "Pattern":
				pattern = Pattern()
				song.add_pattern(pattern)
				level = 1

			if line == "Track":
				track = pattern.add_track()
				level = 2
			
			if line == "Notes":
				level = 3
				
			if line == "Controls":
				level = 5
				
			if line == "Pitchbends":
				level = 6

			if line == "Channel":
				channel = Channel()
				song.add_channel(channel)
				level = 4

			if level == 0:
				if line[:5] == "Bpm: ":
					song.set_bpm(int(line[5:]))
			if level == 1:
				#On Pattern Data
				if line[:5] == "Num: ":
					pattern.set_num(int(line[5:]))
				elif line[:5] == "Len: ":
					pattern.set_len(int(line[5:]))
				elif line[:6] == "Name: ":
					pattern.set_name(line[6:])
			elif level == 2:
				if line[:5] == "Len: ":
					track.set_len(int(line[5:]))
				elif line[:6] == "Name: ":
					track.set_name(line[6:])
				elif line[:8] == "Volume: ":
					track.set_volume(int(line[8:]))
				elif line[:7] == "Synth: ":
					track.set_synth(line[7:])
				elif line[:6] == "Port: ":
					track.set_port(int(line[6:]))
			elif level == 3:
				if line == "Notes":
					pass
				elif line == "EndNotes":
					level = 2
				else:
					line_data = line.split(', ')
					(note, pos, duration) = (line_data[0], line_data[1], line_data[2])
					if len(line_data) == 4:
						volume = int(line_data[3])
					else:
						volume = 127
					track.add_note(int(note),int(pos)*shifter,int(duration)*shifter, volume)
			elif level == 5:
				if line == "Controls":
					pass
				elif line == "EndControls":
					level = 2
				else:
					line_data = line.split(', ')
					(pos, param, value) = (line_data[0], line_data[1], line_data[2])
					track.set_control(int(pos), int(param), int(value))
					
			elif level == 5:
				if line == "Pitchbends":
					pass
				elif line == "EndPitchbends":
					level = 2
				else:
					line_data = line.split(', ')
					(pos, value) = (line_data[0], line_data[1])
					track.set_control(int(pos), int(value))
			elif level == 4:
				if line[:5] == "Pat: ":
					channel.add_pattern(song.get_pattern_by_name(line[5:]))
			
			line = f.readline()

		f.close()
		
		return song