Ejemplo n.º 1
0
def set_key(key, include_accidentals):
	arr = [ 'C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B' ]

	if key not in arr:
		G.error("key %s is invalid.  Select one of %s" % (key, arr))
		return None

	offset = arr.index(key)
	notes = ["%s%d" % (note,octave) 
		for (i, (octave,note)) in enumerate(itertools.product(range(0, 9), arr)) 
		if include_accidentals or ((i - offset) % 12 not in [ 1, 3, 6, 8, 10 ]) # filter accidentals
	]

	# Center on octave 4
	center = notes.index(key + '4')
	min = center - G.NSTAIRS / 2

	# Reduce to G.NSTAIRS notes
	assert min >= 0 and len(notes) >= G.NSTAIRS
	G.note_from_stair = notes[min : G.NSTAIRS + min]
	assert len(G.note_from_stair) == G.NSTAIRS

	if G.gui:
		G.gui.selected_key.set(key)
		G.gui.use_accidentals.set(include_accidentals)
		G.gui.draw_keyboard()

	if include_accidentals:
		G.output('Include all notes (centered on %s)' % (key))
	else:
		G.output('Key = %s' % (key))
Ejemplo n.º 2
0
def set_instrument(name):
	# We assume that the files were set up properly, so if C4 exists, the rest do as well
	name = name.replace(' ', '_')
	fname = get_sound_file(name, 'C4')
	if not name in list_instruments():
		G.error("%s is not a valid instrument" % (name))
		return None

	G.instrument = name
	if G.gui: G.gui.selected_instrument.set(G.instrument)
	G.output('Instrument = ' + G.instrument.replace('_', ' '))
Ejemplo n.º 3
0
	def load_views():
		"""
		Load views from all activated plugins, if they exists
		:return:
		"""
		for plugin in Plugin.model.objects(
				is_active=True).all():
			try:
				importlib.import_module(
					'server.plugins.%s.views' % plugin.name)
			except ImportError as e:
				config.output(' ! Could not load plugin "%s"\n   Error: %s' % (plugin.name, e))
Ejemplo n.º 4
0
def sound_play(note):
	if G.mute: return

	fname = get_sound_file(G.instrument, note)
	if not os.path.isfile(fname):
		G.error('File not found: ' + fname)
		return
	channel = pygame.mixer.Channel(G.index_from_note[note])
	sound = pygame.mixer.Sound(fname)
	sound.set_volume(G.volume)
	channel.play(sound)
	G.output('Play %s' % (note))
	G.debug("start %s on channel %d at volume %.1f" % (fname, G.index_from_note[note], 11.0 * G.volume))
Ejemplo n.º 5
0
def read_url_data(file='FinalDataIX.txt', num=None):
    lineList_all = list()
    with open(PATH + file, 'r', encoding='utf-8-sig') as f:
        for line in f:
            # delete blank space in the beginning or end of every URL
            line.strip()
            lineList_all.append(line)
    if num is not None:
        num = min(num, len(lineList_all))
        data = lineList_all[0:num]
    else:
        data = lineList_all
    # delete blank space in every URL
    data = [delSpace(x) for x in data if len(x) > 5]
    for i in range(len(data)):
        characters = list(data[i])
        characters = processing(characters)
        data[i] = "".join(characters)
    output(filename='urlResult.txt', data=data)
Ejemplo n.º 6
0
def sound_stop(note):
	channel = pygame.mixer.Channel(G.index_from_note[note])
	channel.stop()
	G.output('Stop %s' % (note))
	G.debug("stop channel %d" % (G.index_from_note[note]))
Ejemplo n.º 7
0
def playsong_aux(fname):
	infile = open(fname, 'r')
	tempo = 120 # andante
	prev_tones = []
	line = ''

	while G.gui and G.gui.button_demo.get():
		line = line.strip()
		#G.output('parse line: "%s"' % (line))

		if (not len(line)):
			line = infile.readline()
			if ('' == line):
				pygame.mixer.stop()
				# turn itself off gui-side
				G.gui.buttom_demo.set(0)
				G.gui.draw_keyboard()
				return None
		elif re.match(r'#', line):
			G.debug(line)
			line = ''
		elif re.match(r'\\tempo ([1-9][0-9]*)\s*$', line):
			# Yay! I get to pointlessly repeat myself because python doesn't trust the programmer with assignments that evaluate to a value!
			matches = re.match(r'\\tempo ([1-9][0-9]*)\s*$', line)
			try:
				tempo = int(matches.group(1))
				G.output('Tempo = %s' % (tempo))
			except:
				G.error("Can't happen. Invalid tempo: \"" + line + '"')
			line = ''
		elif re.match(r'\\instrument (.*)', line):
			matches = re.match(r'\\instrument (.*)', line)
			player.set_instrument(matches.group(1))
			line = '' # instruments can have spaces, so this command always uses the entire line
		elif re.match(r'\\key (.*)', line):
			matches = re.match(r'\\key (.*)', line)
			player.set_key(matches.group(1), 0)
			line = '' # instruments can have spaces, so this command always uses the entire line
		elif re.match(r'\(([~A-G0-8b ]*)\)([1-9][0-9]*\.?)(.*)', line): 
			matches = re.match(r'\(([~A-G0-8b ]*)\)([1-9][0-9]*\.?)(.*)', line)
			# Does admit a few notes that aren't on the keyboard, like G8, but those will get caught by sound_play()
			# Also admits things like (C4~3 A)3. If I can nest groups, I *could* catch those, but again, sound_play will handle it.
			# The checks here just need to make sure it doesn't do anything that could escape the SOUNDS_DIR
			tones = matches.group(1).split()
			try:
				s = matches.group(2)
				duration = 4.0 / float(s) # now equals number of quarter notes
				if '.' == s[len(s) - 1]: # dotted note
					duration = duration * 1.5;
				
				# Stop the previous set of notes
				for tone in prev_tones:
					if ('~' + tone) not in tones:
						player.sound_stop(tone)
						G.gui.key_up(tone)

				# Play this set
				for (i, tone) in enumerate(tones):
					if ('~' != tone[0]):
						# If it's a tie, we don't start it over
						player.sound_play(tone)
						G.gui.key_down(tone)
					else:
						tones[i] = tone[1:len(tone)] # prev_tones won't care if it was already a tie

				prev_tones = tones
				
				# (duration beats) / (tempo beats/minute) * 60 s/min* 1000 ms/s = x ms
				ms = int(1000 * 60 * duration / tempo)
				pygame.time.delay(ms)
				line = matches.group(3)
			except:
				G.error('Invalid note: "' + line + '"')
				print sys.exc_info()
				traceback.print_tb(sys.exc_info()[2])
				print ''

				line = ''
		else:
			G.error('Syntax error: "' + line + '"')
			line = ''

	pygame.mixer.stop()
Ejemplo n.º 8
0
def check_command(command, msg_window, input_window):
    try:
        commandlist = [
        "",
        "/command   [args]      - description",
        "",
        "/quit                  - Quits this application",
        "/help                  - Displays this menu",
        "/server    [server]    - Connect to a server",
        "/channel   [channel]   - Select a channel",
        "/list      [server]    - List channels for a server",
        "/add       [url]       - Add a server",
        "",
        ]

        if command == "":
            return

        elif command == "/help":
            count = 0
            config.output("["+time.ctime()+"] Help Menu:")
            for items in commandlist:
                config.output(commandlist[count])
                count+=1

        elif "/server" in command:
            server = command.split("/server ")[1]
            f = open("config", "r")
            content = f.readlines()
            for line in content[4:]:
                elements = line.strip("\n").split(" : ")
                if server == elements[2]:
                    config.output("["+time.ctime()+"] Successfully connected to " + server)
                    config.server = elements[2]
                    config.user = elements[0]
                    config.pin = elements[1]
            if config.server == "Not Connected":
                config.output("["+time.ctime()+"] Server " + server + " not found")

        else:
            config.output("["+time.ctime()+"] " + command)
            #send = {'user' : config.user, 'PIN' : config.pin, 'message' : command, 'channel' : config.channel}
            #x = requests.post(config.server + 'send', data = send)
        list_out(msg_window, input_window)
    except Exception as e:
        config.output("["+time.ctime()+"] Error: " + str(e))
        list_out(msg_window, input_window)