From a312e0540c4916587ba9ccee32cfd7b2fba5512b Mon Sep 17 00:00:00 2001 From: Thomas Herrmann Date: Wed, 6 Apr 2022 17:06:53 +0200 Subject: [PATCH 1/2] Added modifier Exclusion Possibility to deactivate effects and midi modifiers for export --- underbridge.py | 56 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/underbridge.py b/underbridge.py index 91bd6e8..bfaf64d 100644 --- a/underbridge.py +++ b/underbridge.py @@ -25,7 +25,8 @@ addsec = 0 projectpath = 0 cancel = 0 RATE = 0 - +mute_list =[0] * 14 #Midi mute selection of all 14 necessary channels +#modifier_dict = {"mod1": modifier1_va} def getMIDIDevice(): global device_list @@ -108,11 +109,24 @@ def setProject(projnr): outport.send(msg) def muteAll(): + global mute_list global outport - for i in range (0,15): - msg = mido.Message('control_change',control= 53, channel= i, value=1) + checkbutton_name = 0 + print(mute_list) + + for j in range (0,7): + mute_list[j] = 1 + + for i in range (1,7): + checkbutton_name = 'modifier{}_value'.format(i) #'k{}'.format(i) + #print(checkbutton_name) + mute_list[i+7] = eval(checkbutton_name).get() + + for k in range (0,13): + msg = mido.Message('control_change',control= 53, channel= k, value= mute_list[k]) outport.send(msg) - + print("Muted Channels",mute_list) + def setSolo(chn): global outport msg = mido.Message('control_change',control= 53, channel= chn, value=0) @@ -300,13 +314,23 @@ upperframe= LabelFrame(root, text= "Parameter",padx= 10, pady =2, fg = 'white') upperframe.grid(row = 0, column = 0, padx =2, pady =2,) lowerframe= Frame(root,padx= 10, pady =5) -lowerframe.grid(row = 1, column = 0, padx =2, pady =2) +lowerframe.grid(row = 2, column = 0, padx =2, pady =2) + +modifiers = LabelFrame(root, text= "Exclude Modifiers",padx= 10, pady =2, fg = 'white') +modifiers.grid(row = 1, column = 0, padx =2, pady =2) footer= Frame(root,padx= 15, pady =2) -footer. grid(row = 2, column = 0, padx =2, pady =2) +footer. grid(row = 3, column = 0, padx =2, pady =2) mode_select = IntVar() displaymsg = StringVar() +modifier1_value = IntVar() +modifier2_value = IntVar() +modifier3_value = IntVar() +modifier4_value = IntVar() +modifier5_value = IntVar() +modifier6_value = IntVar() + #root.geometry('550x150+0+0') Get_BPM = Button(upperframe, text="Get BPM",width = buttonsize_x, height = buttonsize_y, fg = 'lightgrey', command = lambda:getBPM()) @@ -337,6 +361,24 @@ name_input = Entry(upperframe, width =10, text="Name",bg = 'lightgrey', relief= name_input.insert(0, "Name") #name_text = Label(upperframe,text="Prj Name", width = 8, height = 1) +modifier1 = Checkbutton(modifiers, text="Send 1", variable=modifier1_value) +modifier1.grid(row = 0, column = 0, padx =5, pady =2) + +modifier2 = Checkbutton(modifiers,text="Send 2", variable=modifier2_value) +modifier2.grid(row = 0, column = 1, padx =5, pady =2) + +modifier3 = Checkbutton(modifiers,text="Tape",variable=modifier3_value ) +modifier3.grid(row = 0, column = 2, padx =5, pady =2) + +modifier4 = Checkbutton(modifiers,text="Master", variable= modifier4_value) +modifier4.grid(row = 0, column = 3, padx =5, pady =2) + +modifier5 = Checkbutton(modifiers,text="Perform", variable= modifier5_value) +modifier5.grid(row = 0, column = 4, padx =5, pady =2) + +modifier6 = Checkbutton(modifiers,text="Module", variable= modifier6_value) +modifier6.grid(row = 0, column = 5, padx =5, pady =2) + set_param = Button(lowerframe, text="Set Prmtr",width = buttonsize_x, height = buttonsize_y, fg = 'white',bg= '#0095FF', command = lambda:setParam()) set_path = Button(lowerframe, text="Directory",width = buttonsize_x, height = buttonsize_y,fg = 'white',bg= '#0095FF', command = lambda:setPath()) start_recording = Button(lowerframe, text="RECORD",width = buttonsize_x, height = buttonsize_y,fg = 'white', bg = '#FF2200', command = lambda:threading.Thread(target = sequenceMaster).start()) @@ -349,8 +391,6 @@ cancel.grid(row = 0, column = 6, padx =2, pady =2) donate = Label(footer, text= "donate <3 @ https://link.raise-uav.com", height = 1) donate.grid(row = 3, column = 4, padx =2, pady =10, columnspan=2) - - #Get_BPM.grid(row = 1, column = 0, padx =2, pady =2) #ALL.grid() From 0207f61739d8de898a490e35dad2d5b7c5c43d9a Mon Sep 17 00:00:00 2001 From: Thomas Herrmann Date: Fri, 8 Apr 2022 20:21:20 +0200 Subject: [PATCH 2/2] Now with 100% more classes --- underbridge.py | 751 +++++++++++++++++++++++-------------------------- 1 file changed, 350 insertions(+), 401 deletions(-) diff --git a/underbridge.py b/underbridge.py index bfaf64d..1d5e495 100644 --- a/underbridge.py +++ b/underbridge.py @@ -6,418 +6,367 @@ import pyaudio import wave from tkinter import * from tkinter import filedialog as fd +from tkinter import ttk import time import threading import os -device_list = [] -op_device = [] -audio_device = [] -loop_time = 0 -inport = 0 -outport = 0 -path = 0 -folder = 0 -pattern_nr = 0 -j = 0 -mode_select=0 -addsec = 0 -projectpath = 0 -cancel = 0 -RATE = 0 -mute_list =[0] * 14 #Midi mute selection of all 14 necessary channels -#modifier_dict = {"mod1": modifier1_va} -def getMIDIDevice(): - global device_list - global op_device - device_list = mido.get_output_names() - print (device_list) - try: - op_device = list(filter(lambda x: 'OP-Z' in x, device_list)) - op_device = op_device[0] - print (op_device) - displaymsg.set("OP-Z found") - except: - displaymsg.set("Can´t find OP-Z : MIDI Error.") +class Midirecorder: + def __init__(self): -def getAudioDevice(): - global audio_device - global RATE - p = pyaudio.PyAudio() - try: - info = p.get_host_api_info_by_index(0) - numdevices = info.get('deviceCount') - for i in range(0, numdevices): - if (p.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels')) > 0: - print("Input Device id ", i, " - ", p.get_device_info_by_host_api_device_index(0, i).get('name')) - for i in range(0, numdevices): - #audio_device = p.get_device_info_by_host_api_device_index(0, i).get('name') - if "OP-Z" in p.get_device_info_by_host_api_device_index(0, i).get('name') and (p.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels')) > 0: - audio_device = i - #audio_device = 4 - print ("Detected OP-Z audio at Index:",audio_device, p.get_device_info_by_host_api_device_index(0, audio_device).get('name')) - except: - displaymsg.set("OP-Z Audio Device not found.") + self.window = Tk() + self.window.title('underbridge') + self.window.resizable(width=False, height=False) #565A5E + self.window.tk_setPalette(background='#565A5E', foreground='black',activeBackground='#283867', activeForeground='black' ) + #device_list = [] + self.op_device = [] + self.audio_device = [] + self.loop_time = 0 + self.inport = 0 + self.outport = 0 + self.path = 0 + self.folder = 0 + self.pattern_nr = 0 + self.j = 0 + self.addsec = 0 + self.projectpath = 0 + self.cancel = 0 + self.RATE = 0 + self.mute_list =[0] * 14 #Midi mute selection of all 14 necessary channels + #modifier_dict = {"mod1": modifier1_va} - devinfo = p.get_device_info_by_index(audio_device) - try: - devinfo = p.get_device_info_by_index(audio_device) - test = p.is_format_supported(48000, input_device=devinfo['index'], input_channels=devinfo['maxInputChannels'],input_format=pyaudio.paInt16) - RATE = 48000 - print("48kHz") - except: - RATE = 44100 - print("44100kHz compatibility mode") + #GUI Main + self.buttonsize_x = 7 + self.buttonsize_y = 2 + + self.mode_select = IntVar() + self.displaymsg = StringVar() + self.modifier1_value = IntVar() + self.modifier2_value = IntVar() + self.modifier3_value = IntVar() + self.modifier4_value = IntVar() + self.modifier5_value = IntVar() + self.modifier6_value = IntVar() -def getBPM(): - global op_device - inport= mido.open_input(op_device) - msg = inport.poll() - #print(msg) + upperframe= LabelFrame(self.window, text= "Parameter",padx= 10, pady =2, fg = 'white') + upperframe.grid(row = 0, column = 0, padx =2, pady =2,) -def setLoop(): - global loop_time - try: - bpm = bpm_input.get() - bar = bar_input.get() - addsec = add_sec.get() - loop_time = (240 / int(bpm) * int(bar)) + int(addsec) - print("Loop time set!") - displaymsg.set("BPM Set!") - except: - displaymsg.set("Please enter accurate BPM.") - return time + lowerframe= Frame(self.window,padx= 10, pady =5) + lowerframe.grid(row = 2, column = 0, padx =2, pady =2) -def setParam(): - setLoop() - #mode = mode_select.get() - #if mode == 2: - # projnr = project_input.get() - # setProject(projnr) + modifiers = LabelFrame(self.window, text= "Exclude Modifiers",padx= 10, pady =2, fg = 'white') + modifiers.grid(row = 1, column = 0, padx =2, pady =2) -def openMidi(): - global outport - global op_device - outport= mido.open_output(op_device) - #displaymsg.set("OP-Z MIDI not connected :(") - print(outport) + footer= Frame(self.window,padx= 15, pady =2) + footer. grid(row = 3, column = 0, padx =2, pady =2) -def setProject(projnr): - global outport - msg= mido.Message('program_change',song= projnr, program = 1) - outport.send(msg) + #Get_BPM = Button(upperframe, text="Get BPM",width = self.buttonsize_x, height = self.buttonsize_y, fg = 'lightgrey', command = getBPM) + Song = Radiobutton(lowerframe, text= 'Project', value = 2 , variable = self.mode_select, width = self.buttonsize_x, height = self.buttonsize_y , indicatoron = 0, bg= '#1b7d24' ) + Pattern = Radiobutton(lowerframe, text= 'Pattern', value = 3 , variable = self.mode_select, width = self.buttonsize_x, height = self.buttonsize_y, indicatoron = 0,bg= '#1b7d24' ) + Pattern.select() + + self.bar_input = Scale(upperframe, from_ = 1, to = 4, orient = HORIZONTAL, label="Nr. Bars", sliderlength= 10, length= 75, fg = 'white') + self.patterns_input = Scale(upperframe, from_ = 1, to = 10, orient = HORIZONTAL, label="Patterns",sliderlength= 10, length= 75, fg = 'white') + self.patterns_input.set(value=10) + self.bpm_input = Entry(upperframe, width =10, text="BPM",bg= 'lightgrey', relief= FLAT) + self.bpm_input.insert(0, "BPM") + self.add_sec = Scale(upperframe, from_ = 0, to = 10, orient = HORIZONTAL, label="extra Sec", sliderlength= 10, length= 75, fg = 'white') + + self.name_input = Entry(upperframe, width =10, text="Name",bg = 'lightgrey', relief= FLAT) + self.name_input.insert(0, "Name") + + modifier1 = Checkbutton(modifiers, text="Send 1", variable=self.modifier1_value) + modifier1.grid(row = 0, column = 0, padx =5, pady =2) + + modifier2 = Checkbutton(modifiers,text="Send 2", variable=self.modifier2_value) + modifier2.grid(row = 0, column = 1, padx =5, pady =2) + + modifier3 = Checkbutton(modifiers,text="Tape",variable=self.modifier3_value ) + modifier3.grid(row = 0, column = 2, padx =5, pady =2) + + modifier4 = Checkbutton(modifiers,text="Master", variable= self.modifier4_value) + modifier4.grid(row = 0, column = 3, padx =5, pady =2) + + modifier5 = Checkbutton(modifiers,text="Perform", variable= self.modifier5_value) + modifier5.grid(row = 0, column = 4, padx =5, pady =2) + + modifier6 = Checkbutton(modifiers,text="Module", variable=self.modifier6_value) + modifier6.grid(row = 0, column = 5, padx =5, pady =2) + + set_param = Button(lowerframe, text="Set Prmtr",width = self.buttonsize_x, height = self.buttonsize_y, fg = 'white',bg= '#0095FF', command = self.setParam) + set_path = Button(lowerframe, text="Directory",width = self.buttonsize_x, height = self.buttonsize_y,fg = 'white',bg= '#0095FF', command = self.setPath) + start_recording = Button(lowerframe, text="RECORD",width = self.buttonsize_x, height = self.buttonsize_y,fg = 'white', bg = '#FF2200', command = lambda:threading.Thread(target = self.sequenceMaster).start()) + + tutorial = Label(footer,text="Enter Parameter, then press set Param, choose directory and start recording", height = 2, bg ='grey',fg= 'white', relief = FLAT) + display = Label(lowerframe,textvariable= self.displaymsg,width = 60, height = self.buttonsize_y -1, bg ='lightgrey', relief = FLAT) + + cancel = Button(lowerframe,text = "CANCEL" , width = self.buttonsize_x, height = self.buttonsize_y, bg ='#FFCC00', fg= 'white', command =self.cancelRec) + cancel.grid(row = 0, column = 6, padx =2, pady =2) + + donate = Label(footer, text= "donate <3 @ https://link.raise-uav.com", height = 1) + donate.grid(row = 3, column = 4, padx =2, pady =10, columnspan=2) + + Song.grid(row = 0, column = 1, padx =5, pady =2) + Pattern.grid(row = 0, column = 2, padx =5, pady =2) + + self.name_input.grid(row = 0, column = 0, padx =5, pady =0) + self.bpm_input.grid(row = 0, column = 1, padx =5, pady =0) + self.bar_input.grid(row = 0, column = 3, padx =5, pady =2) + self.patterns_input.grid(row = 0, column = 4, padx =5, pady =2) + self.add_sec.grid(row = 0, column = 5, padx =5, pady =2) + + set_param.grid(row = 0, column = 3, padx =5, pady =2) + set_path.grid(row = 0, column = 4, padx =5, pady =2) + start_recording.grid(row = 0, column = 5, padx =5, pady =2) + + tutorial.grid(row = 1, column = 0, padx =5, pady =5, columnspan=5) + display.grid(row = 1, column = 0, padx =2, pady =10, columnspan= 7) + + self.window.mainloop() + + def getMIDIDevice(self): + #global device_list + #global op_device + device_list = mido.get_output_names() + print (device_list) + try: + self.op_device = list(filter(lambda x: 'OP-Z' in x, device_list)) + self.op_device = self.op_device[0] + print (self.op_device) + self.displaymsg.set("OP-Z found") + except: + self.displaymsg.set("Can´t find OP-Z : MIDI Error.") + + def getAudioDevice(self): + #global audio_device + #global RATE + p = pyaudio.PyAudio() + try: + info = p.get_host_api_info_by_index(0) + numdevices = info.get('deviceCount') + for i in range(0, numdevices): + if (p.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels')) > 0: + print("Input Device id ", i, " - ", p.get_device_info_by_host_api_device_index(0, i).get('name')) + for i in range(0, numdevices): + #audio_device = p.get_device_info_by_host_api_device_index(0, i).get('name') + if "OP-Z" in p.get_device_info_by_host_api_device_index(0, i).get('name') and (p.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels')) > 0: + self.audio_device = i + #audio_device = 4 + print ("Detected OP-Z audio at Index:",self.audio_device, p.get_device_info_by_host_api_device_index(0, self.audio_device).get('name')) + except: + self.displaymsg.set("OP-Z Audio Device not found.") + + #devinfo = p.get_device_info_by_index(self.audio_device) + try: + devinfo = p.get_device_info_by_index(self.audio_device) + test = p.is_format_supported(48000, input_device=devinfo['index'], input_channels=devinfo['maxInputChannels'],input_format=pyaudio.paInt16) + self.RATE = 48000 + print("48kHz") + except: + self.RATE = 44100 + print("44100kHz compatibility mode") + + def getBPM(self): + inport= mido.open_input(self.op_device) + msg = inport.poll(self) + #print(msg) + + def setLoop(self): + try: + bpm = self.bpm_input.get() + bar = self.bar_input.get() + addsec = self.add_sec.get() + self.loop_time = (240 / int(bpm) * int(bar)) + int(addsec) + print("Loop time set!", self.loop_time) + self.displaymsg.set("BPM Set!") + except: + self.displaymsg.set("Please enter accurate BPM.") + #return self.loop_time + + def setParam(self): + self.setLoop() + #mode = mode_select.get() + #if mode == 2: + # projnr = project_input.get() + # setProject(projnr) + + def openMidi(self): + #global outport + #global op_device + self.outport= mido.open_output(self.op_device) + #displaymsg.set("OP-Z MIDI not connected :(") + print(self.outport) + + def setProject(self,projnr): + msg= mido.Message('program_change',song= self.projnr, program = 1) + self.outport.send(msg) + + def muteAll(self): + checkbutton_name = 0 + print(self.mute_list) + + for j in range (0,7): + self.mute_list[j] = 1 + + for i in range (1,6): + checkbutton_name = 'self.modifier{}_value'.format(i) #checkbutton 1- 6 + self.mute_list[i+7] = eval(checkbutton_name).get() #9th position in mute list + + for k in range (0,13): + msg = mido.Message('control_change',control= 53, channel= k, value= self.mute_list[k]) + self.outport.send(msg) + print("Muted Channels",self.mute_list) + + def setSolo(self,chn): + msg = mido.Message('control_change',control= 53, channel= chn, value=0) + self.outport.send(msg) + + def start_MIDI(self): + msg = mido.Message('start') + self.outport.send(msg) + self.displaymsg.set("Playback started") + print("midi") + + def stop_MIDI(self): + msg = mido.Message('stop') + self.outport.send(msg) + self.displaymsg.set("Playback stopped") + + def unmuteAll(self): + for i in range (0,15): + msg = mido.Message('control_change',control= 53, channel= i, value=0) + self.outport.send(msg) + + def nextPattern(self): + msg = mido.Message('control_change', control = 103, value = 16) + self.outport.send(msg) + self.displaymsg.set("Next Pattern") + + def nextSong(self): + pass + + def closeMidi(self): + self.outport.close() + self.displaymsg.set("MIDI closed") + + def setPath(self): + #global path + folder = self.name_input.get() + path = fd.askdirectory() + self.displaymsg.set("Directory set!") + self.makeDir(path,folder) + + def makeDir(self,path,folder): + #global folder + #global projectpath + #folder = name_input.get() + self.projectpath = path + '/' + folder + try: + os.mkdir(self.projectpath) + except: + self.displaymsg.set("Directory Error. Please enter different Name.") + + def makeDirNr(self, pattern_nr): + #global projectpath + #Pfad wird addiert deswegen zusätzliche verzeichnisse + #projectpath = projectpath + '/' + str(pattern_nr) + try: + os.mkdir(self.projectpath + '/' + str(pattern_nr)) + except: + self.displaymsg.set("Directory Error") + #print(projectpath) + + def start_Rec(self): + print("record") + self.displaymsg.set("Recording...") + CHUNK = 128 + FORMAT = pyaudio.paInt16 + CHANNELS = 2 + + RECORD_SECONDS= self.loop_time + print("record") + WAVE_OUTPUT_FILENAME = self.name_input.get() + "_" + "track" + str(self.j+1) + ".wav" + print(WAVE_OUTPUT_FILENAME) + p = pyaudio.PyAudio() + stream = p.open(format=FORMAT, + channels=CHANNELS, + rate=self.RATE, + input=True, + input_device_index= self.audio_device, + frames_per_buffer=CHUNK + ) + + print("* recording") + + frames = [] + self.start_MIDI() + for i in range(0, int(self.RATE / CHUNK * RECORD_SECONDS)): + data = stream.read(CHUNK) + frames.append(data) + + #print("Done recording") + + stream.stop_stream() + stream.close() + p.terminate() + if self.mode_select.get() == 2: + wf = wave.open(self.projectpath + '/' + str(self.pattern_nr) + '/' + WAVE_OUTPUT_FILENAME, 'wb') + else: + wf = wave.open(self.projectpath + '/' + WAVE_OUTPUT_FILENAME, 'wb') + + wf.setnchannels(CHANNELS) + wf.setsampwidth(p.get_sample_size(FORMAT)) + wf.setframerate(self.RATE) + wf.writeframes(b''.join(frames)) + wf.close() + self.j = self.j + 1 + if self.j == 8: + self.j= 0 + self.displaymsg.set("End of Recording") + + def sequenceMaster(self): + self.cancel = 0 + self.getMIDIDevice() + time.sleep(1) + self.getAudioDevice() + self.displaymsg.set("Sequence started") + try: + self.openMidi() + if self.mode_select.get() == 2: + self.makeDirNr(self.pattern_nr) + + for i in range (0,8): + pattern_limit = self.patterns_input.get() + if self.cancel == 1 or self.pattern_nr == pattern_limit: + break + #print("sequence started",i) + self.muteAll() + + time.sleep(0.1) + self.setSolo(i) + #starting Midi during wave record for timing + self.start_Rec() + self.stop_MIDI() + time.sleep(1) + self.unmuteAll() + mode = self.mode_select.get() + + if i == 7 and mode == 2: + #print(mode_select) + time.sleep(5) + self.nextPattern() + self.pattern_nr += 1 + if self.pattern_nr == 9 : + self.pattern_nr = 0 + self.sequenceMaster() + except: + self.displaymsg.set("OP-Z Sequence error try restarting the OP-Z or press CANCEL Button") + + def cancelRec(self): + self.j = 0 + self.cancel = 1 + self.closeMidi() -def muteAll(): - global mute_list - global outport - checkbutton_name = 0 - print(mute_list) - for j in range (0,7): - mute_list[j] = 1 - - for i in range (1,7): - checkbutton_name = 'modifier{}_value'.format(i) #'k{}'.format(i) - #print(checkbutton_name) - mute_list[i+7] = eval(checkbutton_name).get() - - for k in range (0,13): - msg = mido.Message('control_change',control= 53, channel= k, value= mute_list[k]) - outport.send(msg) - print("Muted Channels",mute_list) - -def setSolo(chn): - global outport - msg = mido.Message('control_change',control= 53, channel= chn, value=0) - outport.send(msg) - -def start_MIDI(): - global outport - msg = mido.Message('start') - outport.send(msg) - displaymsg.set("Playback started") - -def stop_MIDI(): - global outport - msg = mido.Message('stop') - outport.send(msg) - displaymsg.set("Playback stopped") - -def unmuteAll(): - global outport - for i in range (0,15): - msg = mido.Message('control_change',control= 53, channel= i, value=0) - outport.send(msg) - -def nextPattern(): - global outport - msg = mido.Message('control_change', control = 103, value = 16) - outport.send(msg) - displaymsg.set("Next Pattern") - -def nextSong(): - pass - -def closeMidi(): - global outport - outport.close() - displaymsg.set("MIDI closed") - -def setPath(): - global path - folder = name_input.get() - path = fd.askdirectory() - displaymsg.set("Directory set!") - makeDir() - -def makeDir(): - global folder - global projectpath - folder = name_input.get() - projectpath = path + '/' + folder - try: - os.mkdir(projectpath) - except: - displaymsg.set("Directory Error. Please enter different Name.") - -def makeDirNr(pattern_nr): - global projectpath - #Pfad wird addiert deswegen zusätzliche verzeichnisse - #projectpath = projectpath + '/' + str(pattern_nr) - try: - os.mkdir(projectpath + '/' + str(pattern_nr)) - except: - displaymsg.set("Directory Error") - #print(projectpath) - -def start_Rec(): - displaymsg.set("Recording...") - global path - global time - global j - global pro - global pattern_nr - global audio_device - global RATE - - CHUNK = 128 - FORMAT = pyaudio.paInt16 - CHANNELS = 2 - #RATE = 44100 - RECORD_SECONDS = loop_time - WAVE_OUTPUT_FILENAME = name_input.get()+ "_" + "track" + str(j+1) + ".wav" - - p = pyaudio.PyAudio() - stream = p.open(format=FORMAT, - channels=CHANNELS, - rate=RATE, - input=True, - input_device_index= audio_device, - frames_per_buffer=CHUNK - - ) - - #print("* recording") - - frames = [] - start_MIDI() - for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)): - data = stream.read(CHUNK) - frames.append(data) - - #print("Done recording") - - stream.stop_stream() - stream.close() - p.terminate() - if mode_select.get() == 2: - wf = wave.open(projectpath + '/' + str(pattern_nr) + '/' + WAVE_OUTPUT_FILENAME, 'wb') - else: - wf = wave.open(projectpath + '/' + WAVE_OUTPUT_FILENAME, 'wb') - - wf.setnchannels(CHANNELS) - wf.setsampwidth(p.get_sample_size(FORMAT)) - wf.setframerate(RATE) - wf.writeframes(b''.join(frames)) - wf.close() - j = j + 1 - if j == 8: - j= 0 - displaymsg.set("End of Recording") - -def sequenceMaster(): - - global cancel - global pattern_nr - cancel = 0 - #print("test") - - getMIDIDevice() - time.sleep(1) - getAudioDevice() - - displaymsg.set("Sequence started") - - try: - openMidi() - - if mode_select.get() == 2: - makeDirNr(pattern_nr) - - for i in range (0,8): # - pattern_limit = patterns_input.get() - if cancel == 1 or pattern_nr == pattern_limit: - break - #print("sequence started",i) - muteAll() - time.sleep(0.1) - setSolo(i) - #starting Midi during wave record for timing - start_Rec() - #print(i) - stop_MIDI() - time.sleep(1) - unmuteAll() - mode = mode_select.get() - - if i == 7 and mode == 2: - #print(mode_select) - time.sleep(5) - nextPattern() - pattern_nr += 1 - if pattern_nr == 9 : - pattern_nr = 0 - sequenceMaster() - except: - displaymsg.set("OP-Z Sequence error try restarting the OP-Z or press CANCEL Button") - -def cancelRec(): - global cancel - global outport - global j - j = 0 - cancel = 1 - closeMidi() - -#GUI Main -buttonsize_x = 7 -buttonsize_y = 2 -mode_select = 0 - -root = Tk() -root.title('underbridge for OP-Z') -root.resizable(width=False, height=False) #565A5E -root.tk_setPalette(background='#565A5E', foreground='black',activeBackground='#283867', activeForeground='black' ) - -upperframe= LabelFrame(root, text= "Parameter",padx= 10, pady =2, fg = 'white') -upperframe.grid(row = 0, column = 0, padx =2, pady =2,) - -lowerframe= Frame(root,padx= 10, pady =5) -lowerframe.grid(row = 2, column = 0, padx =2, pady =2) - -modifiers = LabelFrame(root, text= "Exclude Modifiers",padx= 10, pady =2, fg = 'white') -modifiers.grid(row = 1, column = 0, padx =2, pady =2) - -footer= Frame(root,padx= 15, pady =2) -footer. grid(row = 3, column = 0, padx =2, pady =2) - -mode_select = IntVar() -displaymsg = StringVar() -modifier1_value = IntVar() -modifier2_value = IntVar() -modifier3_value = IntVar() -modifier4_value = IntVar() -modifier5_value = IntVar() -modifier6_value = IntVar() - -#root.geometry('550x150+0+0') - -Get_BPM = Button(upperframe, text="Get BPM",width = buttonsize_x, height = buttonsize_y, fg = 'lightgrey', command = lambda:getBPM()) - -#ALL = Radiobutton(lowerframe, text= 'ALL', value = 1 , variable = mode_select, width = buttonsize_x, height = buttonsize_y , indicatoron = 0, bg= '#1b7d24' ) -Song = Radiobutton(lowerframe, text= 'Project', value = 2 , variable = mode_select, width = buttonsize_x, height = buttonsize_y , indicatoron = 0, bg= '#1b7d24' ) -Pattern = Radiobutton(lowerframe, text= 'Pattern', value = 3 , variable = mode_select, width = buttonsize_x, height = buttonsize_y, indicatoron = 0,bg= '#1b7d24' ) -Pattern.select() - -bar_input = Scale(upperframe, from_ = 1, to = 4, orient = HORIZONTAL, label="Nr. Bars", sliderlength= 10, length= 75, fg = 'white') -#bar_text = Label(upperframe,text="Nr. of Bars", width = 8, height = 1) - -patterns_input = Scale(upperframe, from_ = 1, to = 10, orient = HORIZONTAL, label="Patterns",sliderlength= 10, length= 75, fg = 'white') -patterns_input.set(value=10) - -bpm_input = Entry(upperframe, width =10, text="BPM",bg= 'lightgrey', relief= FLAT) -#bpm_text = Label(upperframe,text="BPM", width = 8, height = 1) -bpm_input.insert(0, "BPM") - -#project_input = Entry(upperframe, width =10, text="Project",bg= 'white') -#bpm_text = Label(upperframe,text="BPM", width = 8, height = 1) -#project_input.insert(0, "Project Nr.") - -add_sec = Scale(upperframe, from_ = 0, to = 10, orient = HORIZONTAL, label="extra Sec", sliderlength= 10, length= 75, fg = 'white') -#add_text = Label(upperframe,text="Sec offset", width = 8, height = 1) - -name_input = Entry(upperframe, width =10, text="Name",bg = 'lightgrey', relief= FLAT) -name_input.insert(0, "Name") -#name_text = Label(upperframe,text="Prj Name", width = 8, height = 1) - -modifier1 = Checkbutton(modifiers, text="Send 1", variable=modifier1_value) -modifier1.grid(row = 0, column = 0, padx =5, pady =2) - -modifier2 = Checkbutton(modifiers,text="Send 2", variable=modifier2_value) -modifier2.grid(row = 0, column = 1, padx =5, pady =2) - -modifier3 = Checkbutton(modifiers,text="Tape",variable=modifier3_value ) -modifier3.grid(row = 0, column = 2, padx =5, pady =2) - -modifier4 = Checkbutton(modifiers,text="Master", variable= modifier4_value) -modifier4.grid(row = 0, column = 3, padx =5, pady =2) - -modifier5 = Checkbutton(modifiers,text="Perform", variable= modifier5_value) -modifier5.grid(row = 0, column = 4, padx =5, pady =2) - -modifier6 = Checkbutton(modifiers,text="Module", variable= modifier6_value) -modifier6.grid(row = 0, column = 5, padx =5, pady =2) - -set_param = Button(lowerframe, text="Set Prmtr",width = buttonsize_x, height = buttonsize_y, fg = 'white',bg= '#0095FF', command = lambda:setParam()) -set_path = Button(lowerframe, text="Directory",width = buttonsize_x, height = buttonsize_y,fg = 'white',bg= '#0095FF', command = lambda:setPath()) -start_recording = Button(lowerframe, text="RECORD",width = buttonsize_x, height = buttonsize_y,fg = 'white', bg = '#FF2200', command = lambda:threading.Thread(target = sequenceMaster).start()) - -tutorial = Label(footer,text="Enter Parameter, then press set Param, choose directory and start recording", height = 2, bg ='grey',fg= 'white', relief = FLAT) -display = Label(lowerframe,textvariable= displaymsg,width = 60, height = buttonsize_y -1, bg ='lightgrey', relief = FLAT) - -cancel = Button(lowerframe,text = "CANCEL" , width = buttonsize_x, height = buttonsize_y, bg ='#FFCC00', fg= 'white', command = lambda: cancelRec()) -cancel.grid(row = 0, column = 6, padx =2, pady =2) - -donate = Label(footer, text= "donate <3 @ https://link.raise-uav.com", height = 1) -donate.grid(row = 3, column = 4, padx =2, pady =10, columnspan=2) -#Get_BPM.grid(row = 1, column = 0, padx =2, pady =2) - -#ALL.grid() -Song.grid(row = 0, column = 1, padx =5, pady =2) -Pattern.grid(row = 0, column = 2, padx =5, pady =2) - -name_input.grid(row = 0, column = 0, padx =5, pady =0) -#name_text.grid(row = 1, column = 2, padx =0, pady =0) - -bpm_input.grid(row = 0, column = 1, padx =5, pady =0) -#bpm_text.grid(row = 0, column = 0, padx =0, pady =0) - -#project_input.grid(row = 0, column = 2, padx =5, pady =0) - -bar_input.grid(row = 0, column = 3, padx =5, pady =2) -#bar_text.grid(row = 1, column = 2, padx =0, pady =0) - -patterns_input.grid(row = 0, column = 4, padx =5, pady =2) - -add_sec.grid(row = 0, column = 5, padx =5, pady =2) -#add_text.grid(row = 1, column = 0, padx =0, pady =0) - -set_param.grid(row = 0, column = 3, padx =5, pady =2) -set_path.grid(row = 0, column = 4, padx =5, pady =2) -start_recording.grid(row = 0, column = 5, padx =5, pady =2) - -tutorial.grid(row = 1, column = 0, padx =5, pady =5, columnspan=5) -display.grid(row = 1, column = 0, padx =2, pady =10, columnspan= 7) - -root.mainloop() \ No newline at end of file +underbridge = Midirecorder() \ No newline at end of file