OffiMaker/PyOffiMaker.py

918 lines
41 KiB
Python
Raw Permalink Normal View History

2024-01-12 23:04:41 +00:00
#!/usr/bin/env python
from turtle import width
from webbrowser import BackgroundBrowser
import PySimpleGUI as sg
import csv,re
import math
import OffiTracker.offitracker as oftr
import pandas as pd
frequencyTable = []
frequencyTable.append(["C0","16.35"])
frequencyTable.append(["C#0","17.32"])
frequencyTable.append(["D0","18.35"])
frequencyTable.append(["D#0","19.45"])
frequencyTable.append(["E0","20.60"])
frequencyTable.append(["F0","21.83"])
frequencyTable.append(["F#0","23.12"])
frequencyTable.append(["G0","24.50"])
frequencyTable.append(["G#0","25.96"])
frequencyTable.append(["A0","27.50"])
frequencyTable.append(["A#0","29.14"])
frequencyTable.append(["B0","30.87"])
frequencyTable.append(["C1","32.70"])
frequencyTable.append(["C#1","34.65"])
frequencyTable.append(["D1","36.71"])
frequencyTable.append(["D#1","38.89"])
frequencyTable.append(["E1","41.20"])
frequencyTable.append(["F1","43.65"])
frequencyTable.append(["F#1","46.25"])
frequencyTable.append(["G1","49.00"])
frequencyTable.append(["G#1","51.91"])
frequencyTable.append(["A1","55.00"])
frequencyTable.append(["A#1","58.27"])
frequencyTable.append(["B1","61.74"])
frequencyTable.append(["C2","65.41"])
frequencyTable.append(["C#2","69.30"])
frequencyTable.append(["D2","73.42"])
frequencyTable.append(["D#2","77.78"])
frequencyTable.append(["E2","82.41"])
frequencyTable.append(["F2","87.31"])
frequencyTable.append(["F#2","92.50"])
frequencyTable.append(["G2","98.00"])
frequencyTable.append(["G#2","103.83"])
frequencyTable.append(["A2","110.00"])
frequencyTable.append(["A#2","116.54"])
frequencyTable.append(["B2","123.47"])
frequencyTable.append(["C3","130.81"])
frequencyTable.append(["C#3","138.59"])
frequencyTable.append(["D3","146.83"])
frequencyTable.append(["D#3","155.56"])
frequencyTable.append(["E3","164.81"])
frequencyTable.append(["F3","174.61"])
frequencyTable.append(["F#3","185.00"])
frequencyTable.append(["G3","196.00"])
frequencyTable.append(["G#3","207.65"])
frequencyTable.append(["A3","220.00"])
frequencyTable.append(["A#3","233.08"])
frequencyTable.append(["B3","246.94"])
frequencyTable.append(["C4","261.63"])
frequencyTable.append(["C#4","277.18"])
frequencyTable.append(["D4","293.66"])
frequencyTable.append(["D#4","311.13"])
frequencyTable.append(["E4","329.63"])
frequencyTable.append(["F4","349.23"])
frequencyTable.append(["F#4","369.99"])
frequencyTable.append(["G4","392.00"])
frequencyTable.append(["G#4","415.30"])
frequencyTable.append(["A4","440.00"])
frequencyTable.append(["A#4","466.16"])
frequencyTable.append(["B4","493.88"])
frequencyTable.append(["C5","523.25"])
frequencyTable.append(["C#5","554.37"])
frequencyTable.append(["D5","587.33"])
frequencyTable.append(["D#5","622.25"])
frequencyTable.append(["E5","659.25"])
frequencyTable.append(["F5","698.46"])
frequencyTable.append(["F#5","739.99"])
frequencyTable.append(["G5","783.99"])
frequencyTable.append(["G#5","830.61"])
frequencyTable.append(["A5","880.00"])
frequencyTable.append(["A#5","932.33"])
frequencyTable.append(["B5","987.77"])
frequencyTable.append(["C6","1046.50"])
frequencyTable.append(["C#6","1108.73"])
frequencyTable.append(["D6","1174.66"])
frequencyTable.append(["D#6","1244.51"])
frequencyTable.append(["E6","1318.51"])
frequencyTable.append(["F6","1396.91"])
frequencyTable.append(["F#6","1479.98"])
frequencyTable.append(["G6","1567.98"])
frequencyTable.append(["G#6","1661.22"])
frequencyTable.append(["A6","1760.00"])
frequencyTable.append(["A#6","1864.66"])
frequencyTable.append(["B6","1975.53"])
frequencyTable.append(["C7","2093.00"])
frequencyTable.append(["C#7","2217.46"])
frequencyTable.append(["D7","2349.32"])
frequencyTable.append(["D#7","2489.02"])
frequencyTable.append(["E7","2637.02"])
frequencyTable.append(["F7","2793.83"])
frequencyTable.append(["F#7","2959.96"])
frequencyTable.append(["G7","3135.96"])
frequencyTable.append(["G#7","3322.44"])
frequencyTable.append(["A7","3520.00"])
frequencyTable.append(["A#7","3729.31"])
frequencyTable.append(["B7","3951.07"])
frequencyTable.append(["C8","4186.01"])
frequencyTable.append(["C#8","4434.92"])
frequencyTable.append(["D8","4698.63"])
frequencyTable.append(["D#8","4978.03"])
frequencyTable.append(["E8","5274.04"])
frequencyTable.append(["F8","5587.65"])
frequencyTable.append(["F#8","5919.91"])
frequencyTable.append(["G8","6271.93"])
frequencyTable.append(["G#8","6644.88"])
frequencyTable.append(["A8","7040.00"])
frequencyTable.append(["A#8","7458.62"])
frequencyTable.append(["B8","7902.13"])
global currentTable
currentTable = 1
global emptyrow
emptyrow = ["C0", "0"]
sg.theme('Dark Red')
def openFile(window = None):
filename = sg.popup_get_file('filename to open', no_window=True, file_types=(("CSV Files","*.csv"),))
data = []
header_list = []
print(filename)
if filename is not None and filename != "":
pandaData = pd.read_csv(filename)
newData1 = pandaData.loc[:,["Frequency1","Effect1"]]
newData2 = pandaData.loc[:,["Frequency2","Effect2"]]
newData3 = pandaData.loc[:,["Frequency3","Effect3"]]
newData4 = pandaData.loc[:,["Noise","Duration"]]
reader = []
reader1 = []
reader2 = []
reader3 = []
reader4 = []
readers = []
df1 = pd.DataFrame(newData1).fillna(0)
df2 = pd.DataFrame(newData2).fillna(0)
df3 = pd.DataFrame(newData3).fillna(0)
df4 = pd.DataFrame(newData4).fillna(0)
listF1 = df1['Frequency1'].values.tolist()
listF2 = df2['Frequency2'].values.tolist()
listF3 = df3['Frequency3'].values.tolist()
listE1 = df1['Effect1'].values.tolist()
listE2 = df2['Effect2'].values.tolist()
listE3 = df3['Effect3'].values.tolist()
listN = df4['Noise'].values.tolist()
listD = df4['Duration'].values.tolist()
for entry, data in enumerate(listF1):
reader1.append([listF1[entry],listE1[entry]])
reader2.append([listF2[entry],listE2[entry]])
reader3.append([listF3[entry],listE3[entry]])
reader4.append([listN[entry],listD[entry]])
data1 = list(reader1)
data2 = list(reader2)
data3 = list(reader3)
data4 = list(reader4)
for index1, row in enumerate(data1):
# or cell == row[3] or cell == row[5] or cell == row[6] or cell == row[7]
for index, cell in enumerate(row):
if cell == row[1]:
pass
else:
if cell == "" or cell =='' or cell == "nan":
cell = 0
for note in frequencyTable:
if str(math.ceil(float(note[1]))) == str( cell) or str(math.floor(float(note[1]))) == str( cell):
#print(str(math.ceil(float(note[1]))) + " : " + str( cell))
cell = note[0]
row[index] =cell
data1[index1] = row
# read everything else into a list of rows
for index1, row in enumerate(data2):
# or cell == row[3] or cell == row[5] or cell == row[6] or cell == row[7]
for index, cell in enumerate(row):
if cell == row[1]:
pass
else:
if cell == "" or cell =='' or cell == "nan":
cell = 0
for note in frequencyTable:
if str(math.ceil(float(note[1]))) == str( cell) or str(math.floor(float(note[1]))) == str( cell):
#print(str(math.ceil(float(note[1]))) + " : " + str( cell))
cell = note[0]
row[index] =cell
data2[index1] = row
for index1, row in enumerate(data3):
# or cell == row[3] or cell == row[5] or cell == row[6] or cell == row[7]
for index, cell in enumerate(row):
if cell == row[1]:
pass
else:
if cell == "" or cell =='' or cell == "nan":
cell = 0
for note in frequencyTable:
if str(math.ceil(float(note[1]))) == str( cell) or str(math.floor(float(note[1]))) == str( cell):
#print(str(math.ceil(float(note[1]))) + " : " + str( cell))
cell = note[0]
row[index] =cell
data3[index1] = row
for index1, row in enumerate(data4):
# or cell == row[3] or cell == row[5] or cell == row[6] or cell == row[7]
for index, cell in enumerate(row):
if cell == "" or cell =='' or cell == "nan":
cell = 0
row[index] =cell
data4[index1] = row
readers.append(data1)
readers.append(data2)
readers.append(data3)
readers.append(data4)
#print(readers)
return readers
def make_table(val,uid,num_rows, num_cols):
data = [[j for j in range(num_cols)] for i in range(num_rows)]
data[0] = ["0" for _ in range(num_cols)]
for i in range(0, num_rows):
if uid == 4:
emptyrow = ["0","100"]
else:
emptyrow = ["C4","50"]
data[i] = emptyrow
val.append(data[i])
return data
def playThread(window):
oftr.stop_signal = False
oftr.play_csv_file("./temp.csv")
def save_csv(name,data):
with open(name, 'w', newline='', encoding='utf-8') as file:
# Create a CSV writer object
csv_writer = csv.DictWriter(file,quoting=csv.QUOTE_NONE,dialect="unix",fieldnames=header_list)
csv_writer.writeheader()
if isinstance(data, list):
for row in data:
for index, cell in enumerate(row):
if cell == "" or cell == "nan":
cell = 0
row[index] =(cell)
for note in frequencyTable:
if cell == note[0]:
cell = note[1]
row[index] =float(cell)
csv_writer.writerow({'Frequency1': row[0], 'Effect1': row[1], 'Frequency2': row[2], 'Effect2': row[3], 'Frequency3': row[4], 'Effect3': row[5], 'Noise': row[6], 'Duration': row[7]})
# Write multiple rows of data
else:
for row in data.values.tolist():
for index, cell in enumerate(row):
if cell == "" or cell == "nan":
cell = 0
row[index] =(cell)
for note in frequencyTable:
if cell == note[0]:
cell = note[1]
row[index] =float(cell)
csv_writer.writerow({'Frequency1': row[0], 'Effect1': row[1], 'Frequency2': row[2], 'Effect2': row[3], 'Frequency3': row[4], 'Effect3': row[5], 'Noise': row[6], 'Duration': row[7]})
# Write multiple rows of data
new_lines = re.compile('\n{2,9}')
with open(name) as f:
contents = f.read()
contents = re.sub(new_lines, '\n\n\n', contents.strip())
with open(name, 'w') as f:
f.write(contents)
def initButtons(window,state = True):
window["-SAVEEDITNEXT-"].update(disabled=state)
window["-NR-"].update(disabled=state)
window["-RR-"].update(disabled=state)
window["o1-"].update(disabled=state)
window["o2-"].update(disabled=state)
window["o3-"].update(disabled=state)
window["o1+"].update(disabled=state)
window["o2+"].update(disabled=state)
window["o3+"].update(disabled=state)
window["n1-"].update(disabled=state)
window["n2-"].update(disabled=state)
window["n3-"].update(disabled=state)
window["n1+"].update(disabled=state)
window["n2+"].update(disabled=state)
window["n3+"].update(disabled=state)
window["n"].update(disabled=state)
window["d"].update(disabled=state)
window["f1"].update(disabled=state)
window["e1"].update(disabled=state)
window["f2"].update(disabled=state)
window["e2"].update(disabled=state)
window["f3"].update(disabled=state)
window["e3"].update(disabled=state)
def changeButtonset1(window,state = False):
window["o1-"].update(disabled=state)
window["o1+"].update(disabled=state)
window["n1-"].update(disabled=state)
window["n1+"].update(disabled=state)
window["f1"].update(disabled=state)
window["e1"].update(disabled=state)
def changeButtonset2(window,state = False):
window["o2-"].update(disabled=state)
window["o2+"].update(disabled=state)
window["n2-"].update(disabled=state)
window["n2+"].update(disabled=state)
window["f2"].update(disabled=state)
window["e2"].update(disabled=state)
def changeButtonset3(window,state = False):
window["o3-"].update(disabled=state)
window["o3+"].update(disabled=state)
window["n3-"].update(disabled=state)
window["n3+"].update(disabled=state)
window["f3"].update(disabled=state)
window["e3"].update(disabled=state)
def changeButtonset4(window,state = False):
window["d"].update(disabled=state)
window["n"].update(disabled=state)
def main():
global canInit
canInit = True
global lastRow
lastRow = 0
global cur_row
cur_row = 0
global cur_col
cur_col = 0
global edit
global data_values
data_values = []
data_values1 = []
data_values2 = []
data_values3 = []
data_values4 = []
edit = False
data = make_table(data_values,0, num_rows=1, num_cols=2)
data1 = make_table(data_values1,1, num_rows=1, num_cols=2)
data2 = make_table(data_values2,2, num_rows=1, num_cols=2)
data3 = make_table(data_values3,3, num_rows=1, num_cols=2)
data4 = make_table(data_values4,4, num_rows=1, num_cols=2)
global header_list
header_list = ["Frequency1", "Effect1", "Frequency2", "Effect2", "Frequency3","Effect3", "Noise", "Duration"]
headers1 = [header_list[0],header_list[1]]
headers2 = [header_list[2],header_list[3]]
headers3 = [header_list[4],header_list[5]]
headers4 = [header_list[6],header_list[7]]
filename = "template.csv"
currentTable = 1
global BackgroundData
BackgroundData = []
for i in range(0, 1000):
BackgroundData.append([])
tab1_layout = [[sg.Table(values=data, headings=header_list, max_col_width=25,
auto_size_columns=True,
#display_row_numbers=True,
justification='right',
num_rows=20,
#alternating_row_color=sg.theme_button_color()[1],
key='-TABLE-',
selected_row_colors='red on yellow',
enable_events=True,
# select_mode=sg.TABLE_SELECT_MODE_BROWSE,
select_mode=sg.TABLE_SELECT_MODE_BROWSE,
expand_x=True,
expand_y=True,
visible=False,
#enable_click_events=True, # Comment out to not enable header and other clicks
),
sg.Table(values=data1, headings=headers1, max_col_width=25,
auto_size_columns=True,
display_row_numbers=True,
justification='right',
num_rows=20,
#alternating_row_color=sg.theme_button_color()[1],
key='-TABLE1-',
selected_row_colors='red on yellow',
enable_events=True,
# select_mode=sg.TABLE_SELECT_MODE_BROWSE,
select_mode=sg.TABLE_SELECT_MODE_BROWSE,
expand_x=True,
expand_y=True,
#enable_click_events=True, # Comment out to not enable header and other clicks
),
sg.Table(values=data2, headings=headers2, max_col_width=25,
auto_size_columns=True,
display_row_numbers=True,
justification='right',
num_rows=20,
#alternating_row_color=sg.theme_button_color()[1],
key='-TABLE2-',
selected_row_colors='red on yellow',
enable_events=True,
# select_mode=sg.TABLE_SELECT_MODE_BROWSE,
select_mode=sg.TABLE_SELECT_MODE_BROWSE,
expand_x=True,
expand_y=True,
#enable_click_events=True, # Comment out to not enable header and other clicks
),
sg.Table(values=data3, headings=headers3, max_col_width=25,
auto_size_columns=True,
display_row_numbers=True,
justification='right',
num_rows=20,
#alternating_row_color=sg.theme_button_color()[1],
key='-TABLE3-',
selected_row_colors='red on yellow',
enable_events=True,
# select_mode=sg.TABLE_SELECT_MODE_BROWSE,
select_mode=sg.TABLE_SELECT_MODE_BROWSE,
expand_x=True,
expand_y=True,
#enable_click_events=True, # Comment out to not enable header and other clicks
),
sg.Table(values=data4, headings=headers4, max_col_width=25,
auto_size_columns=True,
display_row_numbers=True,
justification='right',
num_rows=20,
#alternating_row_color=sg.theme_button_color()[1],
key='-TABLE4-',
selected_row_colors='red on yellow',
enable_events=True,
# select_mode=sg.TABLE_SELECT_MODE_BROWSE,
select_mode=sg.TABLE_SELECT_MODE_BROWSE,
expand_x=True,
expand_y=True,
#enable_click_events=True, # Comment out to not enable header and other clicks
)],
[sg.Text("Current Row: " + str(cur_row),key="-counter-"),sg.Text("Current Col: None",key="-countercol-")],
[sg.Text('Note 1', size =(15, 1)),sg.Button("O-",key="o1-",size=(2,1)),sg.Button("N-",key="n1-",size=(2,1)), sg.InputText(size =(3, 1),key="f1",default_text="C0"),sg.Button("N+",key="n1+",size=(2,1)),sg.Button("O+",key="o1+",size=(2,1)),sg.Text('Effect 1', size =(15, 1)), sg.InputText(size =(3, 1),key="e1",default_text="50")],
[sg.Text('Note 2', size =(15, 1)),sg.Button("O-",key="o2-",size=(2,1)), sg.Button("N-",key="n2-",size=(2,1)),sg.InputText(size =(3, 1),key="f2",default_text="C0"),sg.Button("N+",key="n2+",size=(2,1)),sg.Button("O+",key="o2+",size=(2,1)),sg.Text('Effect 2', size =(15, 1)), sg.InputText(size =(3, 1),key="e2",default_text="50")],
[sg.Text('Note 3', size =(15, 1)),sg.Button("O-",key="o3-",size=(2,1)),sg.Button("N-",key="n3-",size=(2,1)), sg.InputText(size =(3, 1),key="f3",default_text="C0"),sg.Button("N+",key="n3+",size=(2,1)),sg.Button("O+",key="o3+",size=(2,1)),sg.Text('Effect 3', size =(15, 1)), sg.InputText(size =(3, 1),key="e3",default_text="50")],
[sg.Text('Noise', size =(15, 1)), sg.InputText(size =(3, 1),key="n",default_text="0"),sg.Text('Duration', size =(15, 1)), sg.InputText(size =(3, 1),key="d",default_text="100")],
[sg.Button("Save Row",key="-SAVE-"),sg.Button("Save Row & Edit next",key="-SAVEEDITNEXT-"),sg.Checkbox("New Line on end?",key="nl")],
[sg.Button("Create new Row at last Position",key="-NR-",visible=False),sg.Button("Remove selected Row",key="-RR-",visible=False)],
[sg.Button("New File",key="-NF-"),sg.InputText(size =(16, 1),key="-sfname-",enable_events=False,default_text="unnamed.csv"),sg.Button("Save File",key="-SaF-"),sg.Button("Load File",key="-LF-"),sg.Button("Play File",key="-PF-"),sg.Button("Stop File",key="-StF-")]
]
tab2_layout = [[sg.Text('Tab 2')]]
tab3_layout = [[sg.Text('Tab 3')]]
tab4_layout = [[sg.Text('Tab 3')]]
# The TabgGroup layout - it must contain only Tabs
tab_group_layout = [[sg.Tab('Edit', tab1_layout, key='-TAB1-'),
sg.Tab('Samples', tab2_layout, key='-TAB2-'),
sg.Tab('Settings', tab3_layout, key='-TAB3-')]]
# The window layout - defines the entire window
layout = [[sg.TabGroup(tab_group_layout,
enable_events=True,
key='-TABGROUP-')]]
window = sg.Window('OffiMAKER - OffiTracker Editor', layout, grab_anywhere=False,size=(1020, 640))
event, values = window.read()
window.bind("<Alt_L><q>", "ALT-q")
initButtons(window,True)
row_colors = [(0, "yellow","dark red")]
window["-TABLE1-"].update(row_colors=row_colors)
window["-TABLE2-"].update(row_colors=row_colors)
window["-TABLE3-"].update(row_colors=row_colors)
window["-TABLE4-"].update(row_colors=row_colors)
BackgroundData[cur_row] = [window["-TABLE1-"].get()[cur_row],window["-TABLE2-"].get()[cur_row],window["-TABLE3-"].get()[cur_row],window["-TABLE4-"].get()[cur_row]]
def OctavePlus(window,field):
if window[field].get() == "":
window[field].update("C0")
for index, entry in enumerate(frequencyTable):
if window[field].get() == entry[0] and index+12 < len(frequencyTable):
window[field].update(frequencyTable[index+12][0])
return
elif window[field].get() == entry[1] and index+12 < len(frequencyTable):
window[field].update(frequencyTable[index+12][1])
return
def OctaveMinus(window,field):
if window[field].get() == "":
window[field].update("C0")
for index, entry in enumerate(frequencyTable):
if window[field].get() == entry[0] and index-12 >= 0:
window[field].update(frequencyTable[index-12][0])
return
elif window[field].get() == entry[1] and index-12 >= 0:
window[field].update(frequencyTable[index-12][1])
return
def NotePlus(window,field):
if window[field].get() == "":
window[field].update("C0")
for index, entry in enumerate(frequencyTable):
if window[field].get() == entry[0] and index+1 < len(frequencyTable):
window[field].update(frequencyTable[index+1][0])
return
elif window[field].get() == entry[1] and index+1 < len(frequencyTable):
window[field].update(frequencyTable[index+1][1])
return
def NoteMinus(window,field):
if window[field].get() == "":
window[field].update("C0")
for index, entry in enumerate(frequencyTable):
if window[field].get() == entry[0] and index-1 >= 0:
window[field].update(frequencyTable[index-1][0])
return
elif window[field].get() == entry[1] and index-1 >= 0:
window[field].update(frequencyTable[index-1][1])
return
while True:
event, values = window.read()
#sg.popup_non_blocking(event, values)
print(event,values)
if event == sg.WIN_CLOSED: # always, always give a way out!
break
elif event == '-TABGROUP-':
pass
elif event == '-TAB1-':
pass
elif event == 'nl':
pass
elif event == 'o1-':
OctaveMinus(window,"f1")
elif event == 'o2-':
OctaveMinus(window,"f2")
elif event == 'o3-':
OctaveMinus(window,"f3")
elif event == 'n1-':
NoteMinus(window,"f1")
elif event == 'n2-':
NoteMinus(window,"f2")
elif event == 'n3-':
NoteMinus(window,"f3")
elif event == 'o1+':
OctavePlus(window,"f1")
elif event == 'o2+':
OctavePlus(window,"f2")
elif event == 'o3+':
OctavePlus(window,"f3")
elif event == 'n1+':
NotePlus(window,"f1")
elif event == 'n2+':
NotePlus(window,"f2")
elif event == 'n3+':
NotePlus(window,"f3")
elif event == "-NF-":
ch = sg.popup_yes_no("Create new File and discard current changes?", title="New File?")
if ch == "Yes":
window["-TABLE1-"].update(make_table(data_values1,1, num_rows=1, num_cols=2))
window["-TABLE2-"].update(make_table(data_values2,2, num_rows=1, num_cols=2))
window["-TABLE3-"].update(make_table(data_values3,3, num_rows=1, num_cols=2))
window["-TABLE4-"].update(make_table(data_values4,4, num_rows=1, num_cols=2))
else:
pass
elif event == "-StF-":
oftr.stop_signal = True
elif event == "-SaF-":
ch = sg.popup_yes_no("Do you want to Save the File?", title="Save File?")
if ch == "Yes":
df1 = pd.DataFrame(window["-TABLE1-"].get(),columns=headers1)
df2 = pd.DataFrame(window["-TABLE2-"].get(),columns=headers2)
df3 = pd.DataFrame(window["-TABLE3-"].get(),columns=headers3)
df4 = pd.DataFrame(window["-TABLE4-"].get(),columns=headers4)
tosave = df1.join(df2).join(df3).join(df4)
print(tosave)
if window["-sfname-"].get() == "unnamed.csv":
ch2 = sg.popup_yes_no("Default Filename will be used. This could lead to data loss. Are you sure to save?", title="Default Filename will be used.")
if ch2 == "Yes":
save_csv(window["-sfname-"].get(),tosave)
else:
save_csv(window["-sfname-"].get(),tosave)
else:
pass
elif event == "-LF-":
#data_values = []
#openFile(window)
returned = openFile(window)
#print(returned)
if returned is not None:
for i in returned[0]:
data_values1.append(["", ""])
data_values2.append(["", ""])
data_values3.append(["", ""])
data_values4.append(["", ""])
for i in returned:
print("i:" + str(i))
print("\n\n")
BackgroundData[cur_row] = [i[0],i[1],i[3],i[4]]
window["-TABLE1-"].update(returned[0])
window["-TABLE2-"].update(returned[1])
window["-TABLE3-"].update(returned[2])
window["-TABLE4-"].update(returned[3])
elif event == "-PF-":
df1 = pd.DataFrame(window["-TABLE1-"].get(),columns=headers1)
df2 = pd.DataFrame(window["-TABLE2-"].get(),columns=headers2)
df3 = pd.DataFrame(window["-TABLE3-"].get(),columns=headers3)
df4 = pd.DataFrame(window["-TABLE4-"].get(),columns=headers4)
tosave = df1.join(df2).join(df3).join(df4)
save_csv("temp.csv",tosave)
window.start_thread(lambda: playThread(window), ('-THREAD-', '-THEAD ENDED-'))
elif event == '-THREAD-' or event == '-THEAD ENDED-':
pass
elif event == '-NR-':
# newData = window["-TABLE-"].get()
# newData.append(["C0", "50", "C0", "50", "C0", "50", "0","100"])
# data_values.append(["", "", "", "", "","", "", ""])
# window["-TABLE-"].update(newData)
pass
elif event == '-RR-':
try:
if cur_row != 0:
newData = window["-TABLE-"].get()
del newData[cur_row]
del data_values[cur_row]
window["-TABLE-"].update(newData)
else:
print("Dont remove last Row")
except Exception as e:
print (e)
elif event == '-TABLE1-':
try:
#if lastRow != 0:
# row_colors = [(lastRow, "yellow","dark red")]
# window["-TABLE"+ str(currentTable) + "-"].update(row_colors=row_colors)
if canInit == True:
initButtons(window,False)
canInit = False
print(values[event])
data_selected = [data_values1[row] for row in values[event]]
row = values[event]
if row:
changeButtonset1(window,False)
changeButtonset2(window,True)
changeButtonset3(window,True)
changeButtonset4(window,True)
lastRow = row
print(f'Selected row is {row}')
print(data_selected)
cur_row = row[0]
currentTable = 1
window["-counter-"].update("Current Row: " + str(cur_row))
window["-countercol-"].update("Current Col: Note/Frequency 1")
# window['-TABLE1-'].update(select_rows=(row))
window['-TABLE2-'].update(select_rows=())
window['-TABLE3-'].update(select_rows=())
window['-TABLE4-'].update(select_rows=())
print(f'Selected data is {BackgroundData[cur_row]}')
window["f1"].update(BackgroundData[cur_row][0][0])
window["e1"].update(BackgroundData[cur_row][0][1])
except Exception as e:
print (e)
elif event == '-TABLE2-':
try:
#if lastRow != 0:
# row_colors = [(lastRow, "yellow","dark red")]
# window["-TABLE"+ str(currentTable) + "-"].update(row_colors=row_colors)
if canInit == True:
initButtons(window,False)
canInit = False
print(values[event])
data_selected = [data_values2[row] for row in values[event]]
row = values[event]
print(row)
if row:
changeButtonset1(window,True)
changeButtonset2(window,False)
changeButtonset3(window,True)
changeButtonset4(window,True)
lastRow = row
print(f'Selected row is {row}')
print(data_selected)
cur_row = row[0]
currentTable = 2
window["-counter-"].update("Current Row: " + str(cur_row))
window["-countercol-"].update("Current Col: Note/Frequency 2")
window['-TABLE1-'].update(select_rows=())
# window['-TABLE2-'].update(select_rows=(row))
window['-TABLE3-'].update(select_rows=())
window['-TABLE4-'].update(select_rows=())
window["f2"].update(BackgroundData[cur_row][1][0])
window["e2"].update(BackgroundData[cur_row][1][1])
except Exception as e:
print (e)
elif event == '-TABLE3-':
try:
#if lastRow != 0:
# row_colors = [(lastRow, "yellow","dark red")]
# window["-TABLE"+ str(currentTable) + "-"].update(row_colors=row_colors)
if canInit == True:
initButtons(window,False)
canInit = False
print(values[event])
data_selected = [data_values3[row] for row in values[event]]
row = values[event]
print(row)
if row:
changeButtonset1(window,True)
changeButtonset2(window,True)
changeButtonset3(window,False)
changeButtonset4(window,True)
lastRow = row
print(f'Selected row is {row}')
print(data_selected)
cur_row = row[0]
currentTable = 3
window["-counter-"].update("Current Row: " + str(cur_row))
window["-countercol-"].update("Current Col: Note/Frequency 3")
window['-TABLE1-'].update(select_rows=())
window['-TABLE2-'].update(select_rows=())
# window['-TABLE3-'].update(select_rows=(row))
window['-TABLE4-'].update(select_rows=())
window["f3"].update(BackgroundData[cur_row][2][0])
window["e3"].update(BackgroundData[cur_row][2][1])
except Exception as e:
print (e)
elif event == '-TABLE4-':
try:
#if lastRow != 0:
#row_colors = [(lastRow, "yellow","dark red")]
#window["-TABLE"+ str(currentTable) + "-"].update(row_colors=row_colors)
if canInit == True:
initButtons(window,False)
canInit = False
print(values[event])
data_selected = [data_values4[row] for row in values[event]]
row = values[event]
print(row)
if row:
changeButtonset1(window,True)
changeButtonset2(window,True)
changeButtonset3(window,True)
changeButtonset4(window,False)
lastRow = row
print(f'Selected row is {row}')
print(data_selected)
cur_row = row[0]
currentTable = 4
window["-counter-"].update("Current Row: " + str(cur_row))
window["-countercol-"].update("Current Col: Noise/Duration")
window['-TABLE1-'].update(select_rows=())
window['-TABLE2-'].update(select_rows=())
window['-TABLE3-'].update(select_rows=())
# window['-TABLE4-'].update(select_rows=(row))
window["n"].update(BackgroundData[cur_row][3][0])
window["d"].update(BackgroundData[cur_row][3][1])
except Exception as e:
print (e)
elif event == '-TABLE-':
# print(values[event])
# data_selected = [data_values[row] for row in values[event]]
# row = values[event]
# print(row)
# if row:
# print(f'Selected row is {row}')
# print(data_selected)
# cur_row = row[0]
# window["-counter-"].update("Current Row: " + str(cur_row))
# window["f1"].update(data_selected[0][0])
# window["e1"].update(data_selected[0][1])
# window["f2"].update(data_selected[0][2])
# window["e2"].update(data_selected[0][3])
# window["f3"].update(data_selected[0][4])
# window["e3"].update(data_selected[0][5])
# window["n"].update(data_selected[0][6])
# window["d"].update(data_selected[0][7])
pass
elif event == '-SAVE-':
try:
if cur_row >= 0 and currentTable < 4:
newData = window["-TABLE"+ str(currentTable) + "-"].get()
#print(window["f1"].get())
newData[cur_row][0] = str(window["f"+ str(currentTable)].get())
newData[cur_row][1] = str(window["e"+ str(currentTable)].get())
print(newData)
window["-TABLE"+ str(currentTable) + "-"].update(newData)
#row_colors = [(cur_row+1, sg.theme_button_color()[1])]
#row_colors2 = [(cur_row, "yellow","dark red")]
#window["-TABLE"+ str(currentTable) + "-"].update(row_colors=row_colors)
#window["-TABLE"+ str(currentTable) + "-"].update(row_colors=row_colors2)
elif cur_row >= 0 and currentTable == 4:
newData = window["-TABLE"+ str(currentTable) + "-"].get()
#print(window["f1"].get())
newData[cur_row][0] = str(window["n"].get())
newData[cur_row][1] = str(window["d"].get())
window["-TABLE"+ str(currentTable) + "-"].update(newData)
#row_colors = [(cur_row+1, sg.theme_button_color()[1])]
#row_colors2 = [(cur_row, "yellow","dark red")]
#window["-TABLE"+ str(currentTable) + "-"].update(row_colors=row_colors)
#window["-TABLE"+ str(currentTable) + "-"].update(row_colors=row_colors2)
BackgroundData[cur_row] = [window["-TABLE1-"].get()[cur_row],window["-TABLE2-"].get()[cur_row],window["-TABLE3-"].get()[cur_row],window["-TABLE4-"].get()[cur_row]]
except Exception as e:
print(e)
#print(str(cur_row+1) + " : " + str(len(window["-TABLE-"].get())))
elif event == '-SAVEEDITNEXT-' or event == "ALT-q":
try:
if cur_row >= 0 and currentTable < 4:
newData = window["-TABLE"+ str(currentTable) + "-"].get()
#print(window["f1"].get())
newData[cur_row][0] = str(window["f"+ str(currentTable)].get())
newData[cur_row][1] = str(window["e"+ str(currentTable)].get())
window["-TABLE"+ str(currentTable) + "-"].update(newData)
row_colors = [(cur_row+1, sg.theme_button_color()[1])]
#row_colors2 = [(cur_row, "yellow","dark red")]
window["-TABLE"+ str(currentTable) + "-"].update(row_colors=row_colors)
#window["-TABLE"+ str(currentTable) + "-"].update(row_colors=row_colors2)
elif cur_row >= 0 and currentTable == 4:
newData = window["-TABLE"+ str(currentTable) + "-"].get()
#print(window["f1"].get())
newData[cur_row][0] = str(window["n"].get())
newData[cur_row][1] = str(window["d"].get())
window["-TABLE"+ str(currentTable) + "-"].update(newData)
row_colors = [(cur_row+1, sg.theme_button_color()[1])]
#row_colors2 = [(cur_row, "yellow","dark red")]
window["-TABLE"+ str(currentTable) + "-"].update(row_colors=row_colors)
#window["-TABLE"+ str(currentTable) + "-"].update(row_colors=row_colors2)
BackgroundData[cur_row] = [window["-TABLE1-"].get()[cur_row],window["-TABLE2-"].get()[cur_row],window["-TABLE3-"].get()[cur_row],window["-TABLE4-"].get()[cur_row]]
except Exception as e:
print(e)
#print(str(cur_row+1) + " : " + str(len(window["-TABLE-"].get())))
print(window["nl"].get())
if window["nl"].get() == True:
if cur_row+1 == len(window["-TABLE1-"].get()):
print("Made new Row")
newData1 = window["-TABLE1-"].get()
newData1.append(["", ""])
data_values1.append(["", ""])
window["-TABLE1-"].update(newData1)
newData2 = window["-TABLE2-"].get()
newData2.append(["", ""])
data_values2.append(["", ""])
window["-TABLE2-"].update(newData2)
newData3 = window["-TABLE3-"].get()
newData3.append(["", ""])
data_values3.append(["", ""])
window["-TABLE3-"].update(newData3)
newData4 = window["-TABLE4-"].get()
newData4.append(["", "100"])
data_values4.append(["", ""])
window["-TABLE4-"].update(newData4)
cur_row += 1
#window["-TABLE"+ str(currentTable) + "-"].update(select_rows=(cur_row))
row_colors = [(cur_row, sg.theme_button_color()[1])]
window["-TABLE"+ str(currentTable) + "-"].update(row_colors=row_colors)
BackgroundData[cur_row] = [window["-TABLE1-"].get()[cur_row],window["-TABLE2-"].get()[cur_row],window["-TABLE3-"].get()[cur_row],window["-TABLE4-"].get()[cur_row]]
window.close()
main()