def load2(self, r_file=None): global f f = file(r_file, 'r') self.recentList.remove(f.name) self.recentList.append(f.name) self.rfUpdate() self.update("load") self.pkill() if self.debug: barf("SAV", "Loaded %s" % path.split(f.name)[1], True, False) if self.setAutoplay.isChecked(): self.play() else: self.update("load")
def run(self): global p try: p.kill() except Exception: pass args = [binary, f.name] for arg in arglist: args.append(arg) #barf('ACT', 'Thread starting the task..') try: if system() == "Linux": Popen(['./tools/mute.sh', '-u', binary], shell=False, stdout=devnull, stderr=devnull, startupinfo=startupinfo) p = Popen(args, shell=False, stdout=devnull, stderr=devnull, startupinfo=startupinfo) self.message.emit("play") p.communicate() self.message.emit("stop") except Exception as e: barf('ERR', 'ERROR! ' + str(e))
def load(self): global f lastdir = str(self.progset.value("file/lastdir", "")) fname, _ = QFileDialog.getOpenFileName(None, 'Open File', lastdir, "MIDI Audio File (*.mid *.MID)") if fname != "": f = file(fname, 'r') if not f.name in self.recentList: self.recentList.append(f.name) else: self.recentList.remove(f.name) self.recentList.append(f.name) self.progset.setValue("file/lastdir", path.split(f.name)[0]) self.rfUpdate() self.update("load") self.pkill() if self.debug: barf("SAV", "Loaded %s" % path.split(f.name)[1], True, False) if self.setAutoplay.isChecked(): self.play() else: self.update("load")
def run(self): global p2 try: p2.kill() except Exception: pass args = [binary, f.name] newfile = path.splitext(path.split(f.name)[1])[0] + ".wav" if not '-nl' in arglist: args.append('-nl') args.append('-w') for arg in arglist: args.append(arg) #barf('ACT', 'Thread starting the task..') try: if system() == "Linux": Popen(['./tools/mute.sh', binary], shell=False, stdout=devnull, stderr=devnull, startupinfo=startupinfo) p2 = Popen(args, shell=False, stdout=devnull, stderr=devnull, startupinfo=startupinfo) self.message.emit("saving") p2.communicate() try: if not path.exists('saved/'): makedirs('saved/') copy2('adlmidi.wav', 'saved/') rename('saved/adlmidi.wav', 'saved/' + newfile) remove('adlmidi.wav') self.message.emit("saved") except Exception as e: barf('ERR', 'ERROR! ' + str(e)) except Exception as e: barf('ERR', 'ERROR! ' + str(e))
def quit(self): self.stop() #self.pkill() self.saveSettings() barf("DBG", "Quitting", True, False) exit(0)
def closeEvent(self, event): self.stop() #self.pkill() self.saveSettings() barf("DBG", "Quitting", True, False)
def updateMax4ops(self): self.fourOps.setMaximum(self.numCards.value()*6) self.fourOps.setValue(self.numCards.value()*6) barf("DBG", "Updating Maximum of 4ops Chs to %s" % (self.numCards.value()*6), True, False)
def winsetup(self): self.setWindowIcon(QIcon('img/note.png')) openFile = QAction(self.openicon, 'Open', self) openFile.setShortcut('Ctrl+O') openFile.triggered.connect(self.load) saveFile = QAction(self.saveicon, 'Save', self) saveFile.setShortcut('Ctrl+S') saveFile.triggered.connect(self.save) playFile = QAction(self.playicon, 'Play', self) playFile.setShortcut('Ctrl+P') playFile.triggered.connect(self.play) pausePlayb = QAction(self.pauseicon, 'Pause', self) pausePlayb.setShortcut('Ctrl+R') pausePlayb.triggered.connect(self.pause) stopPlay = QAction(self.stopicon, 'Stop', self) stopPlay.setShortcut('Ctrl+Z') stopPlay.triggered.connect(self.stop) exitAction = QAction(self.quiticon, 'Quit', self) exitAction.setShortcut('Ctrl+X') exitAction.triggered.connect(self.quit) aboutdlg = QAction(self.abouticon, 'About', self) aboutdlg.setShortcut('Ctrl+A') aboutdlg.triggered.connect(self.about) showSett = QAction(self.setticon, 'Settings', self) showSett.triggered.connect(self.settings) menubar = self.menuBar() fileMenu = menubar.addMenu('&File') configMenu = menubar.addMenu('&Options') configMenu.setStyleSheet("border: 1px solid black;") self.setLooped = QAction('Loop', configMenu, checkable=True) if self.progset.value("sound/Looped") == 'true': self.setLooped.setChecked(True) else: self.setLooped.setChecked(False) self.setLooped.setShortcut('Ctrl+L') self.setAutoplay = QAction('Autoplay', configMenu, checkable=True) if self.progset.value("sound/Autoplay") == 'true': self.setAutoplay.setChecked(True) else: self.setAutoplay.setChecked(False) self.setAutoplay.setShortcut('Ctrl+K') configMenu.addAction(self.setAutoplay) configMenu.addAction(self.setLooped) fileMenu.setStyleSheet("border: 1px solid black;") fileMenu.addAction(openFile) fileMenu.addAction(saveFile) fileMenu.addSeparator() self.recentMenu = fileMenu.addMenu('Recent') self.rfUpdate() fileMenu.addSeparator() fileMenu.addAction(showSett) fileMenu.addSeparator() fileMenu.addAction(exitAction) helpMenu = menubar.addMenu('&Help') helpMenu.setStyleSheet("border: 1px solid black;") helpMenu.addAction(aboutdlg) self.numCards = QSpinBox() numCards_text = QLabel(" OPL : ") self.numCards.setRange(1, 100) self.numCards.setValue(int(self.progset.value("sound/numCards", 3))) self.numCards.valueChanged.connect(self.updateMax4ops) self.fourOps = QSpinBox() fourOps_text = QLabel(" 4op Ch : ") self.fourOps.setRange(0, self.numCards.value()*6) self.fourOps.setValue(int(self.progset.value("sound/fourOps", self.numCards.value()*6))) self.twoOps = QSpinBox() twoOps_text = QLabel(" 2op Ch : ") self.twoOps.setValue((self.numCards.value()*12 - self.fourOps.value())) self.twoOps.setRange(self.twoOps.value(), self.twoOps.value()) toolbar = self.addToolBar('Media') toolbar.addAction(playFile) toolbar.addAction(pausePlayb) toolbar.addAction(stopPlay) toolbar.setMovable(False) toolbar.addSeparator() toolbar.addWidget(numCards_text) toolbar.addWidget(self.numCards) toolbar.addSeparator() toolbar.addWidget(fourOps_text) toolbar.addWidget(self.fourOps) #toolbar.addSeparator() #toolbar.addWidget(twoOps_text) #toolbar.addWidget(self.twoOps) self.statusBar() self.setFixedSize(380, 90) self.center() self.setWindowTitle('ADLMIDI pyGUI') self.show() if self.debug: barf("MSG", "Loaded Main Window", True, False) self.update("ready") self.threads = [] self.addWorker(AdlMidi(1)) self.addWorker(AdlMidiSave(2))
devnull = None from subprocess import STARTUPINFO, STARTF_USESHOWWINDOW startupinfo = STARTUPINFO() startupinfo.dwFlags |= STARTF_USESHOWWINDOW elif system() == "Linux": binary = "./adlmidi" devnull = open("/dev/null","w") startupinfo = None #Is PySide installed, and if not, exit with error message try: from PySide.QtGui import QAction, QIcon, QWidget, QMessageBox, QDesktopWidget, QFileDialog, QMainWindow, QLabel, QComboBox, QVBoxLayout, QHBoxLayout, QDialog, QTableWidget, QTableWidgetItem, QCheckBox, QAbstractButton, QDialogButtonBox, QSpinBox, QPushButton from PySide.QtCore import QSettings, QThread, Signal, Slot except: if system() == "Windows": barf("ERR", "ADLMIDI pyGUI requires the PySide package to run.", False, False) barf("MSG", "You can install it for Windows with 'pip install -U PySide'.", False, False) elif system() == "Linux": barf("ERR", "ADLMIDI pyGUI requires the python-pyside package to run.", False, False) barf("MSG", "You can install it for Linux with 'apt-get install python-pyside'.", False, False) else: barf("ERR", "ADLMIDI pyGUI requires the PySide package to run.", False, False) barf("MSG", "Availabilty of the PySide package for your platform is not guaranteed.", False, False) exit(1) # Whee, let's define some variables f = None p = None Paused = False arglist = []