def renderFolders(path, upload_download): actualFilePointer = 1 currentCursor = 1 shortArray = [] selectedDisplay = [] fb = fileBrowser(path) sampler = currentStorageStatus["sampler"] synth = currentStorageStatus["synth"] drum = currentStorageStatus["drum"] drum, synth, sampler = 42, 100, 42 if "synth" in fb.structCurrentPath() or "Synth" in fb.structCurrentPath(): # Display synth and Sample Available availableSlots = synth + sampler else: availableSlots = drum # RenderFolders while True: image = Image.new('1', (128, 64)) image.paste( Image.open(workDir + "/Assets/Img/FileBrowser.png").convert("1")) draw = ImageDraw.Draw(image) draw.text((2, -1), os.path.basename(fb.structCurrentPath()[:-1]), fill='black', font=getFont()) if "synth" in fb.structCurrentPath( ) or "Synth" in fb.structCurrentPath(): # Display synth and Sample Available draw.text((108, -2), str(availableSlots), fill='white', font=getFont()) else: # Display available drums draw.text((108, -2), str(availableSlots), fill='white', font=getFont()) shortArray = shiftArray(fb.getDirList(), shortArray, 0) clearDisplay() # Empty Folder if not shortArray: draw.text((30, 40), "[Empty]", fill='white', font=getFont()) displayImage(image) time.sleep(2) return counter = 1 for i in shortArray: # Check if current item is selected selected = True if i in selectedDisplay else False # Render the AIF data from cursor landed item if "aif" in i and counter == currentCursor: try: synType, FX, LFO = analyzeAIF(fb.structCurrentPath() + "/" + i) except: # AIF meta data not retrievable synType, FX, LFO = "N/A", "N/A", "N/A" pass # Render Patch Type draw.text((90, 16), str(synType), fill='white', font=getFont()) draw.text((90, 35), str(FX), fill='white', font=getFont()) draw.text((90, 53), str(LFO), fill='white', font=getFont()) # Remove extension for display and dash out long file names i = i.replace(".aif", "") if len(i) > 10: i = i[:10] + ".." # Iterate through selected queue and invert the color if selected: draw.rectangle(((9, counter * 10), (84, counter * 10 + 10)), 'white') draw.text((10, counter * 10), str(i), fill='black', font=getFont()) else: draw.text((10, counter * 10), str(i), fill='white', font=getFont()) # Render next item from current Directory counter += 1 # Render cursor draw.text((0, currentCursor * 10), ">", fill='white', font=getFont()) # Render Scroll Bar scrollBarXLocation = 86 # List Shorter than screen size, fill the whole scroll bar if len(fb.getDirList()) <= 5: draw.line((scrollBarXLocation, 10, scrollBarXLocation, 64), fill="white", width=1) else: scrollBarLength = int(getScrollBarSize(fb.getDirList())) offset = getOffset(fb.getDirList(), actualFilePointer - 1, scrollBarLength) draw.line((scrollBarXLocation, 10 + offset, scrollBarXLocation, 10 + scrollBarLength + offset), fill="white", width=1) # Update Image to the display displayImage(image) key = getKeyStroke() if key == "UP": if currentCursor - 1 < 1: temp = shortArray shortArray = shiftArray(fb.getDirList(), shortArray, -1) if temp != shortArray: actualFilePointer -= 1 else: currentCursor -= 1 actualFilePointer -= 1 if key == "DOWN": if currentCursor + 1 > len(shortArray): temp = shortArray shortArray = shiftArray(fb.getDirList(), shortArray, 1) if temp != shortArray: actualFilePointer += 1 else: currentCursor += 1 actualFilePointer += 1 if key == "LEFT": if len(fb.histQueue) == 1: # No more Page to return to, exit the page return else: currentCursor = 1 actualFilePointer = 1 availableSlots += len(fb.getCopyQueue()) fb.clearCopyQueue() fb.prevPage() if key == "RIGHT": if len(fb.getCopyQueue()) == 0 and "aif" not in fb.getDirList()[ actualFilePointer - 1]: fb.selectNewPath(fb.getDirList()[actualFilePointer - 1]) currentCursor = 1 actualFilePointer = 1 if key == "CENTER": # Start Multi-select. (Select and deselect, and add the selected ones to copy queue) currentFile = fb.getDirList()[actualFilePointer - 1] selectedFolderPath = fb.structCurrentPath() + currentFile # Add to copy if currentFile not in selectedDisplay: # Decrement Available Patches if os.path.isdir(selectedFolderPath): selectedDisplay.append(currentFile) for i in getDirFileList(selectedFolderPath): fb.addToCopyQueue(i) availableSlots -= 1 else: fb.addToCopyQueue(currentFile) selectedDisplay.append(currentFile) availableSlots -= 1 else: # Remove form copy if os.path.isdir(selectedFolderPath): selectedDisplay.remove(currentFile) for i in getDirFileList(selectedFolderPath): fb.removeFromCopyQueue(i) availableSlots += 1 else: fb.removeFromCopyQueue(currentFile) selectedDisplay.remove(currentFile) availableSlots += 1 if key == "A": print("") # return if key == "B": ##This part need redo currentFile = fb.getDirList()[actualFilePointer - 1] selectedFolderPath = fb.structCurrentPath() + currentFile rtn = "" if len(fb.getCopyQueue()) == 0 or len(selectedDisplay) == 1: if os.path.isdir(selectedFolderPath): for i in getDirFileList(selectedFolderPath): fb.addToCopyQueue(i) fileCount = len(fb.getCopyQueue()) # availableSlots += len(fb.getCopyQueue()) rtn = RenderOptionsMenu([ upload_download + " " + str(fileCount) + " Patches", "Delete " + str(fileCount) + "Patches" ]) else: fb.addToCopyQueue(currentFile) # availableSlots += 1 rtn = RenderOptionsMenu( [upload_download, "Rename", "Delete"]) else: fileCount = len(fb.getCopyQueue()) rtn = RenderOptionsMenu([ upload_download + " " + str(fileCount) + " Patches", "Delete " + str(fileCount) + "Patches" ]) if rtn == "RETURN": availableSlots += fileCount if "Upload" in rtn: # List allowed print("Upload", fb.getCopyQueue()) pass elif "Delete" in rtn: # List allowed print("Delete", fb.getCopyQueue()) pass elif "Rename" in rtn: # Only one item is allowed print("Rename", fb.getCopyQueue()) pass # if rtn == "RETURN": currentCursor = 1 actualFilePointer = 1 fb.clearCopyQueue() selectedDisplay = []
def actionRouter(self, event): # =============Projects Actions =========== if event == "act_Backup_Project_From_OP_1": if check_OP_1_Connection() and config["OP_1_Mounted_Dir"] != "": displayPng(workDir + "/Assets/Img/BackupProject.png") time.sleep(0.1) try: tape = OP1Backup() tape.copyToLocal() displayPng(workDir + "/Assets/Img/Done.png") time.sleep(0.1) getAnyKeyEvent() except: print("File Transfer Error") # self.renderPage(-1, 1) if event == "act_Load_Project_From_Local_only_tracks": if check_OP_1_Connection() and config["OP_1_Mounted_Dir"] != "": displayPng(workDir + "/Assets/Img/BackupProject.png") time.sleep(0.1) try: tape = OP1Backup() tape.copyOnlyTapesToLocal() displayPng(workDir + "/Assets/Img/Done.png") time.sleep(0.1) getAnyKeyEvent() except: print("File Transfer Error") self.renderPage(-1, 1) if event == "act_Load_Project_From_Local": # rtn = "RETURN" while True: temp = RenderOptionsMenu(getDirFileList(savePaths["Local_Projects"]), "Projects") if temp == "RETURN": break else: rtn = RenderOptionsMenu(["Upload", "Rename", "Delete"]) if rtn == "Upload": if check_OP_1_Connection() and config["OP_1_Mounted_Dir"] != "": displayPng(workDir + "/Assets/Img/UploadingProject.png") time.sleep(0.1) try: tape = OP1Backup() tape.loadProjectToOP1(os.path.join(savePaths["Local_Projects"], temp)) except: print("File Transfer Error") elif rtn == "Rename": renderRename(os.path.join(savePaths["Local_Projects"], temp)) elif rtn == "Delete": deleteHelper([os.path.join(savePaths["Local_Projects"], temp)]) elif rtn == "RETURN": pass # ===========Patches Actions=========== if event == "OP1_Synth_Patches": if check_OP_1_Connection() and config["OP_1_Mounted_Dir"] != "": renderFolders(config["OP_1_Mounted_Dir"] + "/synth", "Backup", savePaths["Local_Synth"]) if event == "OP1_Drum_Patches": if check_OP_1_Connection() and config["OP_1_Mounted_Dir"] != "": renderFolders(config["OP_1_Mounted_Dir"] + "/drum", "Backup", savePaths["Local_Drum"]) if event == "UploadSynthPatches": renderFolders(savePaths["Local_Synth"], "Upload", config["OP_1_Mounted_Dir"] + "/synth") if event == "UploadDrumPatches": renderFolders(savePaths["Local_Drum"], "Upload", config["OP_1_Mounted_Dir"] + "/drum") if event == "act_5_Backup_All_Patches": if check_OP_1_Connection() and config["OP_1_Mounted_Dir"] != "": image = Image.new('1', (128, 64)) image.paste(Image.open(workDir + "/Assets/Img/DownloadPatches.png").convert("1")) displayImage(image) time.sleep(0.1) try: bk = OP1Backup() bk.backupOP1Patches() displayPng(workDir + "/Assets/Img/Done.png") time.sleep(0.1) getAnyKeyEvent() except: print("File Transfer Error") # =================== OP-Z Action Routes ==================== if event == "act_Freeze_State_OPZ": if check_OP_Z_Connection() and config["OP_Z_Mounted_Dir"] != "": displayPng(workDir + "/Assets/Img/BackupProject.png") time.sleep(0.1) try: state = OP1Backup() if state.backupOPZState(): displayPng(workDir + "/Assets/Img/Done.png") time.sleep(0.1) getAnyKeyEvent() except: print("File Transfer Error") # self.renderPage(-1, 1) if event == "act_Recall_State_To_OPZ": # rtn = "RETURN" while True: temp = RenderOptionsMenu(getDirFileList(savePaths["OP_Z_Local_Backup_States_Path"]), "Recall State") if temp == "RETURN": break else: rtn = RenderOptionsMenu(["Upload", "Rename", "Delete"]) if rtn == "Upload": if check_OP_Z_Connection(): displayPng(workDir + "/Assets/Img/UploadingProject.png") time.sleep(0.1) try: state = OP1Backup() print("Recall File: ", os.path.join(savePaths["OP_Z_Local_Backup_States_Path"], temp)) state.loadStateToOPZ(os.path.join(savePaths["OP_Z_Local_Backup_States_Path"], temp)) displayPng(workDir + "/Assets/Img/Done.png") time.sleep(0.1) getAnyKeyEvent() except: print("File Transfer Error") elif rtn == "Rename": renderRename(os.path.join(savePaths["OP_Z_Local_Backup_States_Path"], temp)) elif rtn == "Delete": deleteHelper([os.path.join(savePaths["OP_Z_Local_Backup_States_Path"], temp)]) elif rtn == "RETURN": pass # self.renderPage(-1, 1) if event == "OPZ_Patches": if check_OP_Z_Connection() and config["OP_Z_Mounted_Dir"] != "": renderOPZFolder(config["OP_Z_Mounted_Dir"] + "/samplepacks", "Choose From OP-1 Lib") if event == "MIDI_Host": midi = MidiTool() midi.usbMIDIOut() if event == "OP1FUN_BrowsePacks" or event == "OP1FUN_DownloadAllPacks": Connecting = Image.new('1', (128, 64)) draw = ImageDraw.Draw(Connecting) draw.text((0, 30), "Connecting to Wifi..", font=getFont(), fill='white') # draw.text((5, 35), "WIFI..", font=getFont(), fill='white') displayImage(Connecting) if not internetIsOn(): displayPng(workDir + "/Assets/Img/NoWifi.png") getAnyKeyEvent() noWifiMesg = Image.new('1', (128, 64)) draw = ImageDraw.Draw(noWifiMesg) draw.rectangle([(0, 0), (128, 10)], 'white') draw.text((30, 0), "No Internet", font=getFont(), fill='black') draw.text((5, 15), "Connect to Wifi AP", font=getFont(), fill='white') draw.text((5, 40), "Then assign", font=getFont(), fill='white') draw.text((5, 50), "Available Wifi", font=getFont(), fill='white') displayImage(noWifiMesg) getAnyKeyEvent() else: Connecting = Image.new('1', (128, 64)) draw = ImageDraw.Draw(Connecting) draw.text((0, 30), "Logging into op1.fun", font=getFont(), fill='white') displayImage(Connecting) op = op1funRequests() userAccount = op.getUserAccount() if "" in userAccount: Connecting = Image.new('1', (128, 64)) draw = ImageDraw.Draw(Connecting) draw.text((5, 30), "No Login Info!", font=getFont(), fill='white') displayImage(Connecting) else: packlst = op.getPackList() if event == "OP1FUN_DownloadAllPacks" and packlst: op1FunDownlaodQue(op, packlst, savePaths["Local_Patches"]) elif event == "OP1FUN_BrowsePacks" and packlst: rtn = "" while "RETURN" not in rtn: rtn = RenderOptionsMenu([i[0] for i in packlst], "User:"******"RETURN" not in rtn: actRtn = RenderOptionsMenu(["Download To Local", "Download To OP1"], "Pack: " + rtn) download = [] for i in packlst: name, link = i if name == rtn: download.append((name, link)) if "Download To Local" == actRtn: op1FunDownlaodQue(op, download, savePaths["Local_Patches"]) if "Download To OP1" == actRtn: if check_OP_1_Connection(): op1FunDownlaodQue(op, download, config["OP_1_Mounted_Dir"]) else: break # ===================== Server ================== if event == "Check_IP": import logging logging.basicConfig(level=logging.DEBUG, filename="/home/pi/OP1_File_Organizer/logfile.txt", filemode="a+", format="%(asctime)-15s %(levelname)-8s %(message)s") logging.info("In Check IP") username = "******" IP = "" try: # SSH = SSH_Service() # logging.info("After SSH initialized : ", SSH) # IP = SSH.get_ip_address() IP = get_ip_address() logging.info("Getting the IP Address: ", IP) username = os.getlogin() logging.info("Getting the User Name: ", username) # print(SSH.get_ip_address()) # print(SSH.get_current_connected()) # SSH.start_SSH_Service() IP = IP.replace(".", " . ") IPDisplay = Image.new('1', (128, 64)) draw = ImageDraw.Draw(IPDisplay) draw.rectangle([(0, 0), (128, 10)], 'white') draw.text((50, 0), "SSH IP", font=getFont(), fill='black') draw.text((5, 15), "User : "******"IP : " + IP, font=getFont(), fill='white') draw.text((5, 50), "Password : sys paswd", font=getFont(), fill='white') displayImage(IPDisplay) getAnyKeyEvent() except: IPDisplay = Image.new('1', (128, 64)) draw = ImageDraw.Draw(IPDisplay) draw.rectangle([(0, 0), (128, 10)], 'white') draw.text((50, 0), "SSH IP", font=getFont(), fill='black') draw.text((5, 15), "User : "******"IP : " + IP, font=getFont(), fill='white') draw.text((5, 50), "Password : sys paswd", font=getFont(), fill='white') displayImage(IPDisplay) getAnyKeyEvent() # Display = Image.new('1', (128, 64)) # draw = ImageDraw.Draw(Display) # draw.rectangle([(0, 0), (128, 10)], 'white') # draw.text((5, 25), "Wifi is not ready." + IP, font=getFont(), fill='white') # draw.text((5, 35), "Please try later....." + IP, font=getFont(), fill='white') # displayImage(Display) # getAnyKeyEvent() if event == "Server IP": try: SSH = SSH_Service() IP = SSH.get_ip_address() IPDisplay = Image.new('1', (128, 64)) draw = ImageDraw.Draw(IPDisplay) draw.rectangle([(0, 0), (128, 10)], 'white') draw.text((30, 0), "Browser App", font=getFont(), fill='black') draw.text((0, 15), "Connect To Wifi", font=getFont(), fill='white') draw.text((0, 25), "Open Browser, Then", font=getFont(), fill='white') draw.text((0, 35), "-------------------------------------------------------", font=getSmallFont(), fill='white') draw.text((0, 40), "http://" + IP + ":", font=getFont(), fill='white') draw.text((10, 53), "/5000/files", font=getFont(), fill='white') displayImage(IPDisplay) getAnyKeyEvent() except: pass # ===========Eject Actions=========== if event == "act_ESC_Eject": try: unmounting = Image.new('1', (128, 64)) draw = ImageDraw.Draw(unmounting) draw.text((0, 25), "Ejecting....", font=getFont(), fill='white') displayImage(unmounting) if unmount_OP_1(): time.sleep(1) # unmounted = Image.new('1', (128, 64)) # draw = ImageDraw.Draw(unmounted) # draw.text((0, 25), "Ejected", font=getFont(), fill='white') # displayImage(unmounted) # time.sleep(1) except: pass # ========= POWER OFF ==================== if event == "act_POWER_OFF": image = Image.new('1', (128, 64)) image.paste(Image.open(workDir + "/Assets/Img/PowerOff.png").convert("1")) displayImage(image) time.sleep(1.0) # call("sudo shutdown -h now", shell=True) call("sudo poweroff", shell=True) if event == "checkStorage": image = Image.new('1', (128, 64)) image.paste(Image.open(workDir + "/Assets/Img/Storage_64.png").convert("1")) draw = ImageDraw.Draw(image) if check_OP_1_Connection() and config["OP_1_Mounted_Dir"] != "": sampler, synth, drum = update_Current_Storage_Status() else: sampler, synth, drum = 42, 100, 42 Disk = str(subprocess.check_output("df -h | awk '$NF==\"/\"{printf \"%d/%dGB %s\", $3,$2,$5}'", shell=True)) Disk = Disk.replace("b\'", "") Disk = Disk.replace("\'", "") draw.text((50, 13), str(Disk), font=getFont(), fill="white") # Disk Storage Render draw.text((28, 48), str(config["Max_Synth_Sampler_patches"] - sampler), font=getFont(), fill="white") draw.text((70, 48), str(config["Max_Synth_Synthesis_patches"] - synth), font=getFont(), fill="white") draw.text((112, 48), str(config["Max_Drum_Patches"] - drum), font=getFont(), fill="white") displayImage(image) getAnyKeyEvent() # Press any key to proceed self.renderPage(-1, 1)
def __init__(self, Dir): self.histQueue = [Dir] self.currentDirLst = sorted(getDirFileList(Dir)) self.currentDirPath = Dir self.prevDir = "" self.copyQueue = []
def actionRouter(self, event): # =============Projects Actions =========== if event == "act_Backup_Project_From_OP_1": if check_OP_1_Connection() and config["OP_1_Mounted_Dir"] != "": displayPng(workDir + "/Assets/Img/BackupProject.png") time.sleep(0.1) try: tape = TapeBackup() tape.copyToLocal() displayPng(workDir + "/Assets/Img/Done.png") time.sleep(0.1) getAnyKeyEvent() except: print("File Transfer Error") self.renderErrorMessagePage("File Transfer Error") self.renderPage(-1, 1) if event == "act_Load_Project_From_Local": # rtn = "RETURN" while True: temp = RenderOptionsMenu( getDirFileList(savePaths["Local_Projects"]), "Projects") if temp == "RETURN": break else: # while rtn == "RETURN": rtn = RenderOptionsMenu(["Upload", "Rename", "Delete"]) # temp = RenderOptionsMenu(getDirFileList(savePaths["Local_Projects"]), "Projects") if rtn == "Upload": pass elif rtn == "Rename": renderRename( os.path.join(savePaths["Local_Projects"], temp)) elif rtn == "Delete": deleteHelper( [os.path.join(savePaths["Local_Projects"], temp)]) elif rtn == "RETURN": pass self.renderPage(-1, 1) # ===========Patches Actions=========== if event == "OP1_Synth_Patches": if check_OP_1_Connection() and config["OP_1_Mounted_Dir"] != "": renderFolders(config["OP_1_Mounted_Dir"] + "/synth", "Backup", savePaths["Local_Synth"]) self.renderPage(-1, 1) if event == "OP1_Drum_Patches": if check_OP_1_Connection() and config["OP_1_Mounted_Dir"] != "": renderFolders(config["OP_1_Mounted_Dir"] + "/drum", "Backup", savePaths["Local_Drum"]) self.renderPage(-1, 1) if event == "UploadSynthPatches": renderFolders(savePaths["Local_Synth"], "Upload", config["OP_1_Mounted_Dir"] + "/synth") self.renderPage(-1, 1) if event == "UploadDrumPatches": renderFolders(savePaths["Local_Drum"], "Upload", config["OP_1_Mounted_Dir"] + "/drum") self.renderPage(-1, 1) if event == "act_5_Backup_All_Patches": image = Image.new('1', (128, 64)) image.paste( Image.open(workDir + "/Assets/Img/BackupProject.png").convert("1")) displayImage(image) time.sleep(0.1) self.renderPage(-1, 1) if event == "USB_MIDI_In_Test": startMidi() self.renderPage(-1, 1) if event == "USB_MIDI_Out_Test": usbMIDIOut() self.renderPage(-1, 1) # ===========Eject Actions=========== if event == "act_ESC_Eject_OP_1": try: if unmount_OP_1(): print("Ejected") except: print("Error") self.renderPage(-1, 1) # ============= MOUNT OPTION ============== if event == "act_ESC_Mount_OP_1": try: if do_mount(): print("Mounted") except: print("Error") self.renderPage(-1, 1) # ========= POWER OFF ==================== if event == "act_POWER_OFF": image = Image.new('1', (128, 64)) image.paste( Image.open(workDir + "/Assets/Img/PowerOff.png").convert("1")) displayImage(image) time.sleep(1.0) call("sudo shutdown -h now", shell=True) if event == "checkStorage": if check_OP_1_Connection() and config["OP_1_Mounted_Dir"] != "": image = Image.new('1', (128, 64)) image.paste( Image.open(workDir + "/Assets/Img/Storage_64.png").convert("1")) draw = ImageDraw.Draw(image) sampler, synth, drum = update_Current_Storage_Status() Disk = subprocess.check_output( "df -h | awk '$NF==\"/\"{printf \"%d/%dGB %s\", $3,$2,$5}'", shell=True) draw.text((50, 13), Disk, font=getFont(), fill="white") # Disk Storage Render draw.text((28, 48), str(config["Max_Synth_Sampler_patches"] - sampler), font=getFont(), fill="white") draw.text((70, 48), str(config["Max_Synth_Synthesis_patches"] - synth), font=getFont(), fill="white") draw.text((112, 48), str(config["Max_Drum_Patches"] - drum), font=getFont(), fill="white") displayImage(image) getAnyKeyEvent() # Press any key to proceed else: print("Not Connected") self.renderPage(-1, 1)