PySimpleGUI/DemoPrograms/Demo_MIDI_Player.py

257 lines
52 KiB
Python
Raw Permalink Normal View History

2018-09-27 20:24:09 +00:00
#!/usr/bin/env python
import PySimpleGUI as sg
2018-08-24 12:03:56 +00:00
import os
import mido
import time
PLAYER_COMMAND_NONE = 0
PLAYER_COMMAND_EXIT = 1
PLAYER_COMMAND_PAUSE = 2
PLAYER_COMMAND_NEXT = 3
PLAYER_COMMAND_RESTART_SONG = 4
2019-12-24 23:52:47 +00:00
helv15 = 'Helvetica 15'
2018-08-24 12:03:56 +00:00
# ---------------------------------------------------------------------- #
# PlayerGUI CLASS #
# ---------------------------------------------------------------------- #
2018-08-24 12:03:56 +00:00
class PlayerGUI():
'''
Class implementing GUI for both initial screen but the player itself
'''
def __init__(self):
self.Window = None
2018-08-24 12:03:56 +00:00
self.TextElem = None
# use to get the list of midi ports
self.PortList = mido.get_output_names()
# reverse the list so the last one is first
self.PortList = self.PortList[::-1]
2018-08-24 12:03:56 +00:00
# ---------------------------------------------------------------------- #
# PlayerChooseSongGUI #
# Show a GUI get to the file to playback #
# ---------------------------------------------------------------------- #
def PlayerChooseSongGUI(self):
# ---------------------- DEFINION OF CHOOSE WHAT TO PLAY GUI ----------------------------
helv = ("Helvetica", 15)
layout = [[sg.Text('MIDI File Player', font=helv15, size=(20, 1), text_color='green')],
[sg.Text('File Selection', font=helv15, size=(20, 1))],
[sg.Text('Single File Playback', justification='right'),
sg.InputText(size=(65, 1), key='midifile'),
sg.FileBrowse(size=(10, 1), file_types=(("MIDI files", "*.mid"),))],
[sg.Text('Or Batch Play From This Folder', auto_size_text=False, justification='right'),
sg.InputText(size=(65, 1), key='folder'),
sg.FolderBrowse(size=(10, 1))],
2018-09-27 20:24:09 +00:00
[sg.Text('_' * 250, auto_size_text=False, size=(100, 1))],
[sg.Text('Choose MIDI Output Device', size=(22, 1)),
sg.Listbox(values=self.PortList, size=(30, len(self.PortList) + 1), default_values=(self.PortList[0],), key='device')],
2018-09-27 20:24:09 +00:00
[sg.Text('_' * 250, auto_size_text=False, size=(100, 1))],
[sg.SimpleButton('PLAY', size=(12, 2), button_color=('red', 'white'), font=helv15, bind_return_key=True),
sg.Text(' ' * 2, size=(4, 1)),
sg.Cancel(size=(8, 2), font=helv15)]]
2018-09-27 20:24:09 +00:00
window = sg.Window('MIDI File Player', layout, auto_size_text=False, default_element_size=(30, 1), font=helv)
self.Window = window
return window.read()
2018-08-24 12:03:56 +00:00
def PlayerPlaybackGUIStart(self, NumFiles=1):
# ------- Make a new FlexForm ------- #
self.TextElem = sg.Text('Song loading....',
size=(70, 5 + NumFiles),
font=("Helvetica", 14), auto_size_text=False)
self.SliderElem = sg.Slider(range=(1, 100),
size=(50, 8),
orientation='h', text_color='#f0f0f0')
def pbutton(image_data, key):
return sg.Button(image_data=image_data, key=key, image_size=(50,50), image_subsample=2, border_width=0, button_color=(sg.theme_background_color(), sg.theme_background_color()))
2018-08-24 12:03:56 +00:00
layout = [
[sg.Text('MIDI File Player', size=(30, 1), font=("Helvetica", 25))],
[self.TextElem],
[self.SliderElem],
[pbutton(image_pause,'PAUSE'), sg.Text(' '),
pbutton(image_next, 'NEXT'), sg.Text(' '),
pbutton(image_restart, key='Restart Song'), sg.Text(' '),
pbutton(image_exit, 'EXIT')]
]
window = sg.Window('MIDI File Player', layout, default_element_size=(
30, 1), font=("Helvetica", 25), finalize=True)
self.Window = window
2018-08-24 12:03:56 +00:00
# ------------------------------------------------------------------------- #
# PlayerPlaybackGUIUpdate #
# Refresh the GUI for the main playback interface (must call periodically #
# ------------------------------------------------------------------------- #
2018-08-24 12:03:56 +00:00
def PlayerPlaybackGUIUpdate(self, DisplayString):
window = self.Window
# if the widnow has been destoyed don't mess with it
if 'window' not in locals() or window is None:
2018-08-24 12:03:56 +00:00
return PLAYER_COMMAND_EXIT
self.TextElem.update(DisplayString)
event, (values) = window.read(timeout=0)
if event == sg.WIN_CLOSED:
2018-08-24 12:03:56 +00:00
return PLAYER_COMMAND_EXIT
if event == 'PAUSE':
2018-08-24 12:03:56 +00:00
return PLAYER_COMMAND_PAUSE
elif event == 'EXIT':
2018-08-24 12:03:56 +00:00
return PLAYER_COMMAND_EXIT
elif event == 'NEXT':
2018-08-24 12:03:56 +00:00
return PLAYER_COMMAND_NEXT
elif event == 'Restart Song':
2018-08-24 12:03:56 +00:00
return PLAYER_COMMAND_RESTART_SONG
return PLAYER_COMMAND_NONE
# ---------------------------------------------------------------------- #
# MAIN - our main program... this is it #
# Runs the GUI to get the file / path to play #
# Decodes the MIDI-Video into a MID file #
# Plays the decoded MIDI file #
# ---------------------------------------------------------------------- #
def main():
def GetCurrentTime():
'''
Get the current system time in milliseconds
:return: milliseconds
'''
return int(round(time.time() * 1000))
pback = PlayerGUI()
button, values = pback.PlayerChooseSongGUI()
2018-08-31 02:02:29 +00:00
if button != 'PLAY':
sg.popup_cancel('Cancelled...\nAutoclose in 2 sec...',
auto_close=True, auto_close_duration=2)
return
2018-08-24 12:36:45 +00:00
if values['device']:
2018-08-24 12:03:56 +00:00
midi_port = values['device'][0]
else:
sg.popup_cancel('No devices found\nAutoclose in 2 sec...',
auto_close=True, auto_close_duration=2)
2018-08-24 12:03:56 +00:00
batch_folder = values['folder']
midi_filename = values['midifile']
# ------ Build list of files to play --------------------------------------------------------- #
if batch_folder:
filelist = os.listdir(batch_folder)
filelist = [batch_folder+'/' +
f for f in filelist if f.endswith(('.mid', '.MID'))]
2018-08-24 12:03:56 +00:00
filetitles = [os.path.basename(f) for f in filelist]
elif midi_filename: # an individual filename
filelist = [midi_filename, ]
filetitles = [os.path.basename(midi_filename), ]
2018-08-24 12:03:56 +00:00
else:
sg.popup_error('*** Error - No MIDI files specified ***')
return
2018-08-24 12:03:56 +00:00
# ------ LOOP THROUGH MULTIPLE FILES --------------------------------------------------------- #
pback.PlayerPlaybackGUIStart(NumFiles=len(filelist) if len(filelist) <= 10 else 10)
2018-08-24 12:03:56 +00:00
port = None
2018-08-24 12:03:56 +00:00
# Loop through the files in the filelist
for now_playing_number, current_midi_filename in enumerate(filelist):
display_string = 'Playing Local File...\n{} of {}\n{}'.format(
now_playing_number+1, len(filelist), current_midi_filename)
2018-08-24 12:03:56 +00:00
midi_title = filetitles[now_playing_number]
# --------------------------------- REFRESH THE GUI ----------------------------------------- #
pback.PlayerPlaybackGUIUpdate(display_string)
# ---===--- Output Filename is .MID --- #
midi_filename = current_midi_filename
# --------------------------------- MIDI - STARTS HERE ----------------------------------------- #
if not port: # if the midi output port not opened yet, then open it
port = mido.open_output(midi_port if midi_port else None)
try:
mid = mido.MidiFile(filename=midi_filename)
except:
print(' Fail at playing Midi file = {}****'.format(midi_filename))
sg.popup_error('Exception trying to play MIDI file:',
midi_filename, 'Skipping file')
2018-08-24 12:03:56 +00:00
continue
# Build list of data contained in MIDI File using only track 0
midi_length_in_seconds = mid.length
display_file_list = '>> ' + \
'\n'.join([f for i, f in enumerate(
filetitles[now_playing_number:]) if i < 10])
2018-08-24 12:03:56 +00:00
paused = cancelled = next_file = False
######################### Loop through MIDI Messages ###########################
while True :
2018-08-24 12:03:56 +00:00
start_playback_time = GetCurrentTime()
port.reset()
for midi_msg_number, msg in enumerate(mid.play()):
#################### GUI - read values ##################
if not midi_msg_number % 4: # update the GUI every 4 MIDI messages
t = (GetCurrentTime() - start_playback_time)//1000
display_midi_len = '{:02d}:{:02d}'.format(
*divmod(int(midi_length_in_seconds), 60))
2018-08-24 12:03:56 +00:00
display_string = 'Now Playing {} of {}\n{}\n {:02d}:{:02d} of {}\nPlaylist:'.\
format(now_playing_number+1, len(filelist), midi_title, *divmod(t, 60), display_midi_len)
# display list of next 10 files to be played.
pback.SliderElem.update(t, range=(1, midi_length_in_seconds))
rc = pback.PlayerPlaybackGUIUpdate(
display_string + '\n' + display_file_list)
2018-08-24 12:03:56 +00:00
else: # fake rest of code as if GUI did nothing
rc = PLAYER_COMMAND_NONE
if paused:
rc = PLAYER_COMMAND_NONE
while rc == PLAYER_COMMAND_NONE: # TIGHT-ASS loop waiting on a GUI command
rc = pback.PlayerPlaybackGUIUpdate(display_string)
time.sleep(.25)
####################################### MIDI send data ##################################
port.send(msg)
# ------- Execute GUI Commands after sending MIDI data ------- #
if rc == PLAYER_COMMAND_EXIT:
cancelled = True
break
elif rc == PLAYER_COMMAND_PAUSE:
paused = not paused
port.reset()
elif rc == PLAYER_COMMAND_NEXT:
next_file = True
break
elif rc == PLAYER_COMMAND_RESTART_SONG:
break
if cancelled or next_file:
break
#------- DONE playing the song ------- #
port.reset() # reset the midi port when done with the song
if cancelled:
break
2018-08-24 12:03:56 +00:00
# ---------------------------------------------------------------------- #
# LAUNCH POINT -- program starts and ends here #
# ---------------------------------------------------------------------- #
image_exit = b'iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAACXBIWXMAAAsSAAALEgHS3X78AAAfmUlEQVR4nNV9WXAcx5nmV9U3uhvoxtk4iJskCEgUBEpBWo6lbFkULVGW7ZBNWxEjR+zE2i8zs/Y87JNnw54IR8w+ODzSzsixG3ZYsji2GAiSpnYFyitSNgWZMikRpACCAEg0AII4Gld34+qr+qh9ILKcnZ1ZVQ2SkvxHZFR1dVVl5v/lf+SfR0n4DFN9fb1LluW6pqam2urq6nav19uxe/fuXQBqAHip5Nl6ZBPABpUWb9y4cXNjY2NsaWkpOD09HcrlcvNzc3OJT6M+Zkj6tAtASJIk2Gw2e1tbW6Crq+tgfX39E1VVVQdkWa4FUApAJveqqmr6nRTlAKzncrnQ8vLyxbm5uT9cv369f2JiYiGdTitm33m/6VMHpLKy0tLe3v5gZ2fn0ba2tiMAugBYgELGb5dpDDD07yyA6xMTE30jIyO9wWDw2srKSnZbmdwj+lQAsVqtUnt7e11nZ+dXu7q6XnQ4HHsBlAD5TDdzrkc0ECbO46lUauj69evHRkZG3gwGg/OZTOYTF5tPHJA9e/bsfPzxx/+uvr7+OwD8AJ/ZZo8iIow2e2TOo3Nzc6+/9957r4yOjo4XX8vt0ycCiNVqldvb2/ccPHjwH+vr678hSVIZwGcySexv9hr9HEs0s9l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VAMQtGJBLBqVOnEI/H88Ys2PNMJoONjQ0cO3YMKysr2wZFL4LAJhoUl8uFffv25fGMBobm
image_next = b'iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAACxIAAAsSAdLdfvwAAB8WSURBVHhezZ17sJZVvccfN8ZFASER2GyQ5KLizgtC4x3MQjPUtJS0qaYxm2aOnVNNnZrKM+lMTae/Ujs459SMWmraTsyOIaOmJ0jykopIXFS2RggbNijiVm6Fnt9n8X5ff/vHet797s3e4HfmO2s961nPb631/T3r8lze5z2oeA+jqalpUENDw5jx48c3jhw5ctKQIUOOPeaYY462XaOMQxwHG8Gbxg7Hjc8///wLHR0dq9rb21evWbOm7e23316/bt267bbvPYn3jEMOOuig4n3ve1//iRMnjm5ubp5hzjjniCOOONUc0mi7hxobUkbDO++8U4nVBjYd3ja+YQ5p27Rp0+PmlEeWL1++qLW1dcM//vGPXfXa7GsccIeMGDGi36RJk44/7rjj5pgzZltSs7Ef+6JIPRUtOMZv7zYuN6fMX7FiRcvq1auXbd68mbQDhgPikIMPPvggc8IYc8InrDd8bsCAASdY8iHs86LXE68F74g64tt27tz5nPWa28w5vzPnrP/nP//ZszNgH7DfHTJlypTJM2fOvNqGpM/b5nDScmLXG5ZBQtcbAhffYkPaLxcuXDh35cqVL1bS9gverU0fwnpEg/WIKTNmzPi6OeJSa/hhpOdEFuN2TFM8By92jJeladuHZn+rOebuRYsW/cR6zErrMcxDfYo9JfchzBHDPvrRj17b2Nh4pW2yIioVF9qkW43XSoM6zsOLGmkLhJpp/jjFK+hoa2u7+Q9/+MO15pjXK2l9gj5zyPvf//7+1iPmnHjiiT+who0nLQrpiehirW1/DMxBooqILuEVL9v29LaAlbdm6dKl11iPaXnttdd2pcReRq87hMofddRRE+bMmXODTdbnW1I/CeeFhF50cffu3dm4qONkIweJmBMd9uvXLxv3lA1Rdg27bfJf0NLS8tWXX375pb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