def play_note(note):
    """play_note determines the coordinates of a note on the keyboard image
    and sends a request to play the note to the fluidsynth server"""

    global text
    octave_offset = (note.octave - LOWEST) * width
    if note.name in WHITE_KEYS:

        # Getting the x coordinate of a white key can be done automatically

        w = WHITE_KEYS.index(note.name) * white_key_width
        w = w + octave_offset

        # Add a list containing the x coordinate, the tick at the current time
        # and of course the note itself to playing_w

        playing_w.append([w, tick, note])
    else:

        # For black keys I hard coded the x coordinates. It's ugly.

        i = BLACK_KEYS.index(note.name)
        if i == 0:
            w = 18
        elif i == 1:
            w = 58
        elif i == 2:
            w = 115
        elif i == 3:
            w = 151
        else:
            w = 187
        w = w + octave_offset
        playing_b.append([w, tick, note])

    # To find out what sort of chord is being played we have to look at both the
    # white and black keys, obviously:

    notes = playing_w + playing_b
    notes.sort()
    notenames = []
    for n in notes:
        notenames.append(n[2].name)

    # Determine the chord

    det = chords.determine(notenames)
    if det != []:
        det = det[0]
    else:
        det = ''

    # And render it onto the text surface

    t = font.render(det, 2, (0, 0, 0))
    text.fill((255, 255, 255))
    text.blit(t, (0, 0))
Example #2
0
def play_note(note):
	"""play_note determines the coordinates of a note on the keyboard image
	and sends a request to play the note to the fluidsynth server"""

	global text

	octave_offset = (note.octave - LOWEST) * width

	if note.name in WHITE_KEYS:

		# Getting the x coordinate of a white key can be done automatically
		w = WHITE_KEYS.index(note.name) * white_key_width
		w = w + octave_offset

		# Add a list containing the x coordinate, the tick at the current time and 
		# of course the note itself to playing_w
		playing_w.append([w, tick, note])
	else:
		# For black keys I hard coded the x coordinates. It's ugly.
		i = BLACK_KEYS.index(note.name) 
		if i == 0:
			w = 18
		elif i == 1:
			w = 58
		elif i == 2:
			w = 115
		elif i == 3:
			w = 151
		else:
			w = 187

		w = w + octave_offset
		playing_b.append([w, tick, note])

	# To find out what sort of chord is being played we have to look 
	# at both the white and black keys, obviously:
	notes = playing_w + playing_b
	notes.sort()
	notenames = []
	for n in notes:
		notenames.append(n[2].name)
	
	# Determine the chord
	det = chords.determine(notenames)
	if det != []:
		det = det[0]
	else:
		det = ""

	# And render it onto the text surface
	t = font.render(det, 2, (0,0,0))
	text.fill((255,255,255))
	text.blit(t, (0,0))

	# Play the note
	fluidsynth.play_Note(note, channel, 100)