def onEntry(self, value): if type(value) != list: value = self.convertToList(value) if CeciliaLib.getVar("currentModule") is not None and self.rate == "k": getattr(CeciliaLib.getVar("currentModule"), self.name)(value) if self.popup is not None: self.popup[0].setValue(self.popup[1], True)
def onRememberInputSound(self, event): if event.GetInt() == 1: CeciliaLib.getVar("interface").menubar.editMenu.FindItemById(ID_REMEMBER).Check(True) CeciliaLib.setVar("rememberedSound", True) else: CeciliaLib.getVar("interface").menubar.editMenu.FindItemById(ID_REMEMBER).Check(False) CeciliaLib.setVar("rememberedSound", False)
def createGrapher(self, evt=None): buildGrapher(self.grapher) for slider in CeciliaLib.getVar("userSliders"): slider.refresh() if CeciliaLib.getVar("presetToLoad") is not None: CeciliaLib.loadPresetFromDict(CeciliaLib.getVar("presetToLoad")) CeciliaLib.setVar("presetToLoad", None)
def openSpectrumWindow(self): if CeciliaLib.getVar('spectrumFrame') is None: f = SpectrumFrame(CeciliaLib.getVar("interface")) f.setAnalyzer(CeciliaLib.getVar("audioServer").spectrum) f.Center() f.Show() CeciliaLib.setVar('spectrumFrame', f)
def __init__(self, parent, id=-1, title='', mainFrame=None, pos=wx.DefaultPosition, size=wx.DefaultSize, style=style): wx.Frame.__init__(self, parent, id, title, pos, size, style) self.SetBackgroundColour(BACKGROUND_COLOUR) self.ceciliaMainFrame = mainFrame self.menubar = InterfaceMenuBar(self, self.ceciliaMainFrame) self.SetMenuBar(self.menubar) self.box = wx.GridBagSizer(0, 0) self.controlBox = wx.BoxSizer(wx.VERTICAL) self.controlPanel = Control.CECControl(self, -1) togglePopupPanel, objs, tpsize = self.createTogglePopupPanel() slidersPanel, slPanelSize = self.createSlidersPanel() self.grapher = getGrapher(self) CeciliaLib.setVar("grapher", self.grapher) presetPanel = Preset.CECPreset(self) CeciliaLib.setVar("presetPanel", presetPanel) self.controlBox.Add(self.controlPanel, 1, wx.EXPAND | wx.RIGHT, -1) self.controlBox.Add(presetPanel, 0, wx.EXPAND | wx.TOP | wx.RIGHT, -1) self.controlBox.Add(togglePopupPanel, 0, wx.EXPAND | wx.TOP | wx.RIGHT, -1) self.box.Add(self.controlBox, (0, 0), span=(2, 1), flag=wx.EXPAND) self.box.Add(self.grapher, (0, 1), flag=wx.EXPAND) self.box.Add(slidersPanel, (1, 1), flag=wx.EXPAND | wx.TOP, border=-1) self.box.AddGrowableCol(1, 1) self.box.AddGrowableRow(0, 1) pos = CeciliaLib.getVar("interfacePosition") size = CeciliaLib.getVar("interfaceSize") pos, size = self.positionToClientArea(pos, size) self.SetSizer(self.box) self.SetSize(size) self.Bind(wx.EVT_CLOSE, self.onClose) if pos is None: self.Center() else: self.SetPosition(pos) self.Show() self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.createGrapher, self.timer) self.timer.StartOnce(100)
def onPlayStop(self, value): if value: CeciliaLib.getControlPanel().nonZeroTime = 0 CeciliaLib.setVar("toDac", True) CeciliaLib.getVar("grapher").toolbar.loadingMsg.SetForegroundColour("#FFFFFF") CeciliaLib.getVar("grapher").toolbar.loadingMsg.Refresh() CeciliaLib.getControlPanel().transportButtons.setPlay(True) wx.CallLater(50, CeciliaLib.startCeciliaSound, True) else: CeciliaLib.stopCeciliaSound()
def onClose(self, event): CeciliaLib.setVar("interfaceSize", self.GetSize()) CeciliaLib.setVar("interfacePosition", self.GetPosition()) CeciliaLib.resetWidgetVariables() try: self.Destroy() except: pass CeciliaLib.getVar("mainFrame").SetFocus() CeciliaLib.getVar("mainFrame").Hide()
def setPlay(self, x): if x: self.mode = 2 data = CeciliaLib.getVar("grapher").plotter.data for line in data: if line.getName() == self.name: line.setShow(1) CeciliaLib.getVar("grapher").plotter.draw() else: self.mode = 0 self.Refresh()
def marioSwitch(self, evt): if evt.GetInt() == 1: self.FindItemById(ID_MARIO).Check(1) for slider in CeciliaLib.getVar("userSliders"): slider.slider.useMario = True slider.slider.Refresh() else: self.FindItemById(ID_MARIO).Check(0) for slider in CeciliaLib.getVar("userSliders"): slider.slider.useMario = False slider.slider.Refresh()
def createFileExportPanel(self, panel): fileExportPanel = wx.Panel(panel) fileExportPanel.SetBackgroundColour(BACKGROUND_COLOUR) box = wx.BoxSizer(wx.VERTICAL) # File Format textFileFormat = wx.StaticText(fileExportPanel, 0, 'File Format :') textFileFormat.SetForegroundColour(PREFS_FOREGROUND) textFileFormat.SetFont(self.font) self.choiceFileFormat = CustomMenu( fileExportPanel, choice=sorted(AUDIO_FILE_FORMATS.keys()), init=CeciliaLib.getVar("audioFileType"), size=(150, 20), outFunction=self.changeFileType) # Bit depth textBD = wx.StaticText(fileExportPanel, 0, 'Bit Depth :') textBD.SetForegroundColour(PREFS_FOREGROUND) textBD.SetFont(self.font) self.choiceBD = CustomMenu(fileExportPanel, choice=sorted(BIT_DEPTHS.keys()), size=(150, 20), outFunction=self.changeSampSize) for item in BIT_DEPTHS.items(): if item[1] == CeciliaLib.getVar("sampSize"): self.choiceBD.setStringSelection(item[0]) formatbox = wx.BoxSizer(wx.HORIZONTAL) formatbox.Add(textFileFormat, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 5) formatbox.AddStretchSpacer(1) formatbox.Add(self.choiceFileFormat, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, PADDING) depthbox = wx.BoxSizer(wx.HORIZONTAL) depthbox.Add(textBD, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 5) depthbox.AddStretchSpacer(1) depthbox.Add(self.choiceBD, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, PADDING) box.Add( Separator(fileExportPanel, size=(350, 1), colour=BACKGROUND_COLOUR)) box.Add(formatbox, 0, wx.EXPAND | wx.BOTTOM, 7) box.Add(depthbox, 0, wx.EXPAND | wx.BOTTOM, 7) fileExportPanel.SetSizerAndFit(box) return fileExportPanel
def MouseRightDown(self, evt): if self._enable: rec = wx.Rect(5, 13, 45, 45) pos = evt.GetPosition() if rec.Contains(pos): if evt.ShiftDown(): self.setMidiCtl(None) else: if CeciliaLib.getVar("useMidi"): CeciliaLib.getVar("audioServer").midiLearn(self) self.inMidiLearnMode() else: CeciliaLib.showErrorDialog("Midi not initialized!", "There is no Midi interface connected!") evt.Skip()
def applyBatchProcessingFolder(self, value): folderName = value if folderName == "": return old_file_type = CeciliaLib.getVar("audioFileType") cfileins = CeciliaLib.getControlPanel().getCfileinList() num_snds = len(cfileins[0].fileMenu.choice) dlg = wx.ProgressDialog("Batch processing on sound folder", "", maximum=num_snds, parent=self, style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_SMOOTH) dlg.SetMinSize((600, -1)) dlg.SetClientSize((600, 100)) count = 0 totaltime = CeciliaLib.getVar("totalTime") for snd in cfileins[0].fileMenu.choice: cfileins[0].onSelectSound(-1, snd) if CeciliaLib.getVar("useSoundDur"): cfileins[0].setTotalTime() path, dump = os.path.split(cfileins[0].filePath) name, ext = os.path.splitext(snd) lext = ext.lower() if lext in [".wav", ".wave"]: CeciliaLib.setVar('audioFileType', "wav") elif lext in [".aif", ".aiff", ".aifc"]: CeciliaLib.setVar('audioFileType', "aif") elif lext in [".ogg"]: CeciliaLib.setVar('audioFileType', "ogg") elif lext in [".flac"]: CeciliaLib.setVar('audioFileType', "flac") elif lext in [".au"]: CeciliaLib.setVar('audioFileType', "au") elif lext in [".sd2"]: CeciliaLib.setVar('audioFileType', "sd2") elif lext in [".caf"]: CeciliaLib.setVar('audioFileType', "caf") if not os.path.isdir(os.path.join(path, folderName)): os.mkdir(os.path.join(path, folderName)) filename = os.path.join(path, folderName, "%s-%s%s" % (name, folderName, ext)) count += 1 (keepGoing, skip) = dlg.Update(count, "Exporting %s" % filename) CeciliaLib.getControlPanel().onBatchProcessing(filename) while (CeciliaLib.getVar("audioServer").isAudioServerRunning()): time.sleep(.1) if CeciliaLib.getVar("useSoundDur"): CeciliaLib.getControlPanel().setTotalTime(totaltime) CeciliaLib.getControlPanel().updateDurationSlider() dlg.Destroy() CeciliaLib.setVar('audioFileType', old_file_type)
def setAutomationData(self, data): # convert values on scaling temp = [] log = self.getLog() minval = self.getMinValue() maxval = self.getMaxValue() automationlength = self.getAutomationLength() frac = automationlength / CeciliaLib.getVar("totalTime") virtuallength = len(data) / frac data.extend([data[-1]] * int(((1 - frac) * virtuallength))) totallength = float(len(data)) oldpos = 0 oldval = data[0] if log: maxOnMin = maxval / minval torec = math.log10(oldval / minval) / math.log10(maxOnMin) else: maxMinusMin = maxval - minval torec = (oldval - minval) / maxMinusMin temp.append([0.0, torec]) for i, val in enumerate(data): length = (i - oldpos) / totallength pos = oldpos / totallength + length if log: torec = math.log10(val / minval) / math.log10(maxOnMin) else: torec = (val - minval) / maxMinusMin temp.append([pos, torec]) oldval = val oldpos = i self.automationData = temp
def onSavePreset(self): dlg = wx.TextEntryDialog(self, 'Enter preset name:', 'Saving Preset', self.currentPreset) if dlg.ShowModal() == wx.ID_OK: newPreset = CeciliaLib.ensureNFD(dlg.GetValue()) else: newPreset = '' dlg.Destroy() if newPreset == '': CeciliaLib.showErrorDialog('Failed saving preset', 'You must give a name to your preset!') return if newPreset == 'init': CeciliaLib.showErrorDialog('Failed saving preset', '"init" is reserved. You must give another name to your preset!') return ok = True if newPreset in CeciliaLib.getVar("presets").keys(): dlg2 = wx.MessageDialog(self, 'The preset you entered already exists. Are you sure you want to overwrite it?', 'Existing preset!', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_INFORMATION) if dlg2.ShowModal() == wx.ID_NO: ok = False dlg2.Destroy() if ok: self.currentPreset = newPreset CeciliaLib.savePresetToDict(self.currentPreset) self.presetChoice.setChoice(self.orderingPresetNames(), False) self.presetChoice.setStringSelection(self.currentPreset) CeciliaLib.saveCeciliaFile(self, showDialog=False)
def createTogglePopupPanel(self): panel = wx.Panel(self, -1, style=wx.BORDER_SIMPLE) panel.SetBackgroundColour(BACKGROUND_COLOUR) widgets = CeciliaLib.getVar("interfaceWidgets") box, objs = buildTogglePopupBox(panel, widgets) panel.SetSizerAndFit(box) CeciliaLib.setVar("userTogglePopups", objs) size = panel.GetSize() return panel, objs, size
def createSlidersPanel(self): panel = wx.Panel(self, -1, style=wx.BORDER_SIMPLE) panel.SetBackgroundColour(BACKGROUND_COLOUR) widgets = CeciliaLib.getVar("interfaceWidgets") box, sl = buildHorizontalSlidersBox(panel, widgets) CeciliaLib.setVar("userSliders", sl) panel.SetSizerAndFit(box) size = panel.GetSize() return panel, size
def positionToClientArea(self, pos, size): position = None screen = 0 if pos is not None: for i in range(CeciliaLib.getVar("numDisplays")): off = CeciliaLib.getVar("displayOffset")[i] dispsize = CeciliaLib.getVar("displaySize")[i] Xbounds = [off[0], dispsize[0] + off[0]] Ybounds = [off[1], dispsize[1] + off[1]] if pos[0] >= Xbounds[0] and pos[0] <= Xbounds[1] and \ pos[1] >= Ybounds[0] and pos[1] <= Ybounds[1]: position = pos screen = i break dispsize = CeciliaLib.getVar("displaySize")[screen] if size[0] <= dispsize[0] and size[1] <= dispsize[1]: newsize = size else: newsize = (dispsize[0] - 50, dispsize[1] - 50) return position, newsize
def onStart(): ceciliaMainFrame = CeciliaMainFrame.CeciliaMainFrame(None, -1) CeciliaLib.setVar("mainFrame", ceciliaMainFrame) app.SetTopWindow(ceciliaMainFrame) file = "" if len(sys.argv) > 1: file = sys.argv[1] if os.path.isfile(file): ceciliaMainFrame.onOpen(file) elif CeciliaLib.getVar("lastCeciliaFile") != '' and os.path.isfile(CeciliaLib.getVar("lastCeciliaFile")): ceciliaMainFrame.onOpen(CeciliaLib.getVar("lastCeciliaFile"), MODULES_PATH in CeciliaLib.getVar("lastCeciliaFile")) else: categories = [folder for folder in os.listdir(MODULES_PATH) if not folder.startswith(".")] category = random.choice(categories) files = [f for f in os.listdir(os.path.join(MODULES_PATH, category)) if f.endswith(FILE_EXTENSION)] file = random.choice(files) ceciliaMainFrame.onOpen(os.path.join(MODULES_PATH, category, file), True)
def onQuit(self, event): ok = True msg = "Do you want to save the current state of the module?" dlg = wx.MessageDialog(self, msg, "Quit Cecilia5...", style=wx.YES_NO | wx.CANCEL | wx.STAY_ON_TOP) ret = dlg.ShowModal() if ret == wx.ID_YES: CeciliaLib.saveCeciliaFile(self, showDialog=False) elif ret == wx.ID_CANCEL: ok = False dlg.Destroy() if not ok: return if not CeciliaLib.closeCeciliaFile(self): return try: self.prefs.onClose(event) except: pass if CeciliaLib.getVar("audioServer").isAudioServerRunning(): CeciliaLib.getVar("audioServer").stop() time.sleep(.2) if CeciliaLib.getVar('spectrumFrame') is not None: try: CeciliaLib.getVar('spectrumFrame')._destroy(None) except: pass finally: CeciliaLib.setVar('spectrumFrame', None) self.api_doc_frame.Destroy() self.mod_doc_frame.Destroy() self.closeInterface() CeciliaLib.writeVarToDisk() self.Destroy()
def updateTitle(self, isModified=False): title = os.path.split(CeciliaLib.getVar("currentCeciliaFile", unicode=True))[1] if CeciliaLib.getVar("interface"): if not isModified: CeciliaLib.getVar("interface").updateTitle('Interface - ' + title) else: CeciliaLib.getVar("interface").updateTitle('*** Interface - ' + title + ' ***')
def onOpenPrefModule(self, event): menu = self.GetMenuBar() id = event.GetId() file = menu.FindItemById(id) filename = file.GetLabel() filedir = file.GetMenu().GetTitle() prefPath = CeciliaLib.getVar("prefferedPath") prefPaths = prefPath.split(';') prefBaseNames = [os.path.basename(path) for path in prefPaths] dirname = prefPaths[prefBaseNames.index(filedir)] if dirname: name = os.path.join(dirname, filename) CeciliaLib.openCeciliaFile(self, name)
def applyBatchProcessingPreset(self, value): folderName = value if folderName == "": return cfileins = CeciliaLib.getControlPanel().getCfileinList() presets = CeciliaLib.getVar("presetPanel").getPresets() if "init" in presets: presets.remove("init") if "last save" in presets: presets.remove("last save") num_presets = len(presets) dlg = wx.ProgressDialog("Batch processing on preset sequence", "", maximum=num_presets, parent=self, style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_SMOOTH) dlg.SetMinSize((600, -1)) dlg.SetClientSize((600, 100)) if len(cfileins) > 0: filepath = cfileins[0].filePath count = 0 for preset in presets: CeciliaLib.loadPresetFromDict(preset) if len(cfileins) == 0: path = os.path.join(os.path.expanduser("~"), "Desktop") name = "batch" ext = "." + CeciliaLib.getVar("audioFileType") else: cfileins[0].onLoadFile(filepath) path, fname = os.path.split(cfileins[0].filePath) name, ext = os.path.splitext(fname) if not os.path.isdir(os.path.join(path, folderName)): os.mkdir(os.path.join(path, folderName)) filename = os.path.join(path, folderName, "%s-%s%s" % (name, preset, ext)) count += 1 (keepGoing, skip) = dlg.Update(count, "Exporting %s" % filename) CeciliaLib.getControlPanel().onBatchProcessing(filename) while (CeciliaLib.getVar("audioServer").isAudioServerRunning()): time.sleep(.1) dlg.Destroy()
def onDeletePreset(self): if self.currentPreset in CeciliaLib.getVar("presets"): dlg = wx.MessageDialog(self, 'Preset %s will be deleted. Are you sure?' % self.currentPreset, 'Warning!', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_INFORMATION) if dlg.ShowModal() == wx.ID_NO: ok = False else: ok = True dlg.Destroy() if ok: CeciliaLib.deletePreset(self.currentPreset) self.presetChoice.setChoice(self.orderingPresetNames(), False) self.presetChoice.setStringSelection("") CeciliaLib.saveCeciliaFile(self, showDialog=False)
def onPresetSelect(self, idxPreset, newPreset): if newPreset in CeciliaLib.getVar("presets"): CeciliaLib.loadPresetFromDict(newPreset) for preset in CeciliaLib.getVar("presets"): if preset != newPreset: CeciliaLib.getVar("presets")[preset]['active'] = False CeciliaLib.getVar("presets")[newPreset]['active'] = True self.currentPreset = newPreset elif newPreset == 'init': CeciliaLib.loadPresetFromDict("init") for preset in CeciliaLib.getVar("presets"): CeciliaLib.getVar("presets")[preset]['active'] = False self.currentPreset = "init"
def getPage(self, word): if word == self.oldPage: self.fromToolbar = False return page_count = self.GetPageCount() for i in range(page_count): text = self.GetPageText(i) if text == word: self.oldPage = word if not self.fromToolbar: self.sequence = self.sequence[0:self.seq_index + 1] self.sequence.append(i) self.seq_index = len(self.sequence) - 1 self.history_check() self.parent.setTitle(text) self.SetSelection(i) panel = self.GetPage(self.GetSelection()) if not panel.isLoad: panel.isLoad = True panel.win = stc.StyledTextCtrl(panel, -1, size=panel.GetSize(), style=wx.BORDER_SUNKEN) panel.win.SetUseHorizontalScrollBar(False) panel.win.LoadFile(os.path.join(CeciliaLib.ensureNFD(DOC_PATH), word)) panel.win.SetMarginWidth(1, 0) if self.searchKey is not None: words = complete_words_from_str(panel.win.GetText(), self.searchKey) _ed_set_style(panel.win, words) else: _ed_set_style(panel.win) panel.win.SetSelectionEnd(0) def OnPanelSize(evt, win=panel.win): win.SetPosition((0, 0)) win.SetSize(evt.GetSize()) panel.Bind(wx.EVT_SIZE, OnPanelSize) self.fromToolbar = False return try: win = self.makePanel(CeciliaLib.getVar("currentCeciliaFile")) self.AddPage(win, word) self.getPage(word) except: pass
def addPrefPath(self): currentPath = CeciliaLib.getVar("prefferedPath") path = '' dlg = wx.DirDialog(self, message="Choose a folder...", defaultPath=CeciliaLib.ensureNFD( os.path.expanduser('~'))) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() dlg.Destroy() if path and currentPath != '': path = currentPath + ';' + path elif not path: return CeciliaLib.setVar("prefferedPath", path) self.textPrefPath.SetValue(path)
def onChangePreset(self, x, label=None): if CeciliaLib.getVar("currentModule") is not None: CeciliaLib.getVar("audioServer").setPluginPreset(self.vpos, x, label)
def onChangeKnob3(self, x): if self.knob3.getState()[1] in [0, 1]: if CeciliaLib.getVar("currentModule") is not None: CeciliaLib.getVar("audioServer").setPluginValue(self.vpos, 2, x)
audioServer = audio.AudioServer() CeciliaLib.setVar("audioServer", audioServer) try: CeciliaLib.queryAudioMidiDrivers() except: pass app = CeciliaApp(redirect=False) wx.Log.SetLogLevel(0) wx.SetDefaultPyEncoding('utf-8') try: display = wx.Display() numDisp = display.GetCount() if CeciliaLib.getVar("DEBUG"): print 'Numbers of displays:', numDisp displays = [] displayOffset = [] displaySize = [] for i in range(numDisp): displays.append(wx.Display(i)) offset = displays[i].GetGeometry()[:2] size = displays[i].GetGeometry()[2:] if CeciliaLib.getVar("DEBUG"): print 'display %d:' % i print ' pos =', offset print ' size =', size print displayOffset.append(offset) displaySize.append(size)
def MacOpenFiles(self, filenames): if type(filenames) == ListType: filenames = filenames[0] if CeciliaLib.getVar("mainFrame") is not None: CeciliaLib.getVar("mainFrame").onOpen(filenames)
def getWithMidi(self): if self.getMidiCtl() is not None and CeciliaLib.getVar("useMidi"): return True else: return False
def MacReopenApp(self): try: CeciliaLib.getVar("mainFrame").Raise() except: pass
def onShortPlayStop(self, event): if CeciliaLib.getVar("audioServer").isAudioServerRunning(): self.onPlayStop(0) else: self.onPlayStop(1)