create offiplayergui.py & update offitracker.py
Adds a GUI for easy usage
This commit is contained in:
parent
0af3446706
commit
ba2c5a6e39
45
offiplayergui.py
Normal file
45
offiplayergui.py
Normal file
@ -0,0 +1,45 @@
|
||||
import PySimpleGUI as sg
|
||||
import glob
|
||||
import offitracker as offi
|
||||
import sys
|
||||
import csv
|
||||
import numpy as np
|
||||
import sounddevice as sd
|
||||
import threading
|
||||
|
||||
names = glob.glob("./**/*.csv", recursive=True)
|
||||
toplay = ""
|
||||
|
||||
layout = [[sg.Text('Search')],
|
||||
[sg.Input(size=(200, 1), enable_events=True, key='-INPUT-')],
|
||||
[sg.Listbox(names, size=(200, 10), enable_events=True, key='-LIST-')],
|
||||
[sg.Button('Play'), sg.Button('Stop'), sg.Text("",key="file")]]
|
||||
|
||||
window = sg.Window('OffiPlayer', layout,size=(480, 320))
|
||||
|
||||
def playthread(window):
|
||||
offi.stop_signal = False
|
||||
offi.play_csv_file(toplay)
|
||||
window.write_event_value(('-THREAD-', '** DONE **'), 'Done!')
|
||||
|
||||
while True:
|
||||
event, values = window.read()
|
||||
if event in (sg.WIN_CLOSED, 'Exit'):
|
||||
break
|
||||
if values['-INPUT-'] != '':
|
||||
search = values['-INPUT-']
|
||||
new_values = [x for x in names if search in x]
|
||||
window['-LIST-'].update(new_values)
|
||||
else:
|
||||
window['-LIST-'].update(names)
|
||||
if event == '-LIST-' and len(values['-LIST-']):
|
||||
toplay = values['-LIST-'][0]
|
||||
window['file'].update(toplay)
|
||||
if event == 'Play':
|
||||
window.start_thread(lambda: playthread(window), ('-THREAD-', '-THEAD ENDED-'))
|
||||
if event == 'Stop':
|
||||
offi.stop_signal = True
|
||||
window.close()
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@ import sys
|
||||
import csv
|
||||
import numpy as np
|
||||
import sounddevice as sd
|
||||
|
||||
import time
|
||||
# OffiTracker, the tracker that no one asked for but I made it anyways :3
|
||||
# Usage: Make a CSV table in Excel or LibreOffice with the following format:
|
||||
# Frequency1 Effect1 Frequency2 Effect2 .... Noise Duration
|
||||
@ -12,8 +12,16 @@ import sounddevice as sd
|
||||
# Noise = noise amplitude from 0 to 10
|
||||
# Duration = tone duration in ms
|
||||
# (c) 2024 mueller_minki, Feel free to modify or share.
|
||||
stop_signal = False
|
||||
|
||||
def stop_playback():
|
||||
stop_signal = True
|
||||
|
||||
def play_square_waves(output_stream, frequencies, effects, duration, amplitude=1, noise_amplitude=0, sample_rate=44100):
|
||||
if stop_signal == True:
|
||||
output_stream.stop()
|
||||
pass
|
||||
else:
|
||||
num_waves = len(frequencies)
|
||||
t = np.linspace(0, duration / 1000, int(sample_rate * duration / 1000), endpoint=False)
|
||||
|
||||
@ -32,6 +40,8 @@ def play_square_waves(output_stream, frequencies, effects, duration, amplitude=1
|
||||
output_stream.write(combined_wave)
|
||||
|
||||
def play_csv_file(file_path):
|
||||
stop_signal = False
|
||||
|
||||
with open(file_path, 'r') as csv_file:
|
||||
csv_reader = csv.DictReader(csv_file)
|
||||
header = csv_reader.fieldnames
|
||||
@ -46,7 +56,7 @@ def play_csv_file(file_path):
|
||||
|
||||
# Check if 'Noise' column exists in the CSV file
|
||||
noise_amplitude = float(row.get('Noise', 0))
|
||||
|
||||
if stop_signal == False:
|
||||
play_square_waves(output_stream, frequencies, effects, duration, noise_amplitude=noise_amplitude)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
Reference in New Issue
Block a user