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 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 __init__(self, parent, label, init, rate, name, colour, tooltip, stack=False, output=True): self.type = "toggle" self.name = name self.rate = rate self.output = output if label != '': if stack: self.label = Label(parent, label, colour=colour[0], size=(210, 20)) else: self.label = Label(parent, label, colour=colour[0], size=(100, 20)) CeciliaLib.setToolTip(self.label, TT_TOGGLE) self.toggle = Toggle(parent, init, outFunction=self.onToggle, colour=colour[1])
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, choiceFunc, order): Plugin.__init__(self, parent, choiceFunc, order) self.pluginName = 'None' self.sizer = wx.FlexGridSizer(1, 4, 0, 0) revMenuBox = wx.BoxSizer(wx.VERTICAL) self.knob1 = PluginKnob(self, 0, 1, 0, size=(43, 70), label='None') self.knob1.setEnable(False) self.sizer.Add(self.knob1) self.knob2 = PluginKnob(self, 0, 1, 0, size=(43, 70), label='None') self.knob2.setEnable(False) self.sizer.Add(self.knob2) self.knob3 = PluginKnob(self, 0, 1, 0, size=(43, 70), label='None') self.knob3.setEnable(False) self.sizer.Add(self.knob3) self.createHeadBox() revMenuBox.Add(self.headBox, 0, wx.TOP, 0) self.choice = CustomMenu(self, choice=PLUGINS_CHOICE, init='None', size=(93, 18), colour=PLUGINPOPUP_BACK_COLOUR, outFunction=self.replacePlugin) CeciliaLib.setToolTip(self.choice, TT_POST_ITEMS) revMenuBox.Add(self.choice, 0, wx.TOP, 2) plugChoicePreset = wx.StaticText(self, -1, 'Type:') plugChoicePreset.SetFont(wx.Font(CONTROLSLIDER_FONT, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) plugChoicePreset.SetForegroundColour(TEXT_LABELFORWIDGET_COLOUR) revMenuBox.Add(plugChoicePreset, 0, wx.TOP, 6) self.preset = CustomMenu(self, choice=['None'], init='None', size=(93, 18), colour=CONTROLLABEL_BACK_COLOUR) self.preset.setEnable(False) revMenuBox.Add(self.preset, 0, wx.TOP, 2) self.sizer.Add(revMenuBox, 0, wx.LEFT, 5) self.SetSizer(self.sizer)
def __init__(self, parent, label, name, values, init, colour, tooltip): self.name = name self.up = 1 popupLabel = label.capitalize() + ' Voices' self.popup = CECPopup(parent, popupLabel, values, init, "i", self.name + 'num', colour, tooltip=False, output=False) chordLabel = label.capitalize() + ' Chords' self.chord = CECPopup(parent, chordLabel, sorted(POLY_CHORDS.keys()), '00 - None', "i", self.name, colour, tooltip=False, output=False) CeciliaLib.setToolTip(self.popup.label, TT_POLY_LABEL) CeciliaLib.setToolTip(self.chord.label, TT_POLY_CHORD)
def __init__(self, parent, label, name, colour, tooltip): self.type = "button" self.name = name self.label = Label(parent, label, colour=colour[0]) self.button = Button(parent, outFunction=self.onButton, colour=(colour[1], colour[0])) CeciliaLib.setToolTip(self.label, TT_BUTTON)
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 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 openRecent(self, event): menu = self.GetMenuBar() id = event.GetId() file = menu.FindItemById(id).GetLabel().replace("\n", "").strip() if os.path.isfile(file): CeciliaLib.openCeciliaFile(self, file) else: CeciliaLib.showErrorDialog("Error while trying to open a file!", "No such file : %s" % file[:-1]) self.newRecent(file, remove=True)
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 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 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 onOpenBuiltin(self, event): menu = self.GetMenuBar() id = event.GetId() file = menu.FindItemById(id) filename = file.GetLabel() filedict = self.GetMenuBar().files for key in filedict.keys(): if filename in filedict[key]: dirname = key break name = os.path.join(CeciliaLib.ensureNFD(MODULES_PATH), dirname, filename) CeciliaLib.openCeciliaFile(self, name, True)
def __init__(self, parent, label, init, rate, name, popup, colour, tooltip): self.type = "gen" self.name = name self.rate = rate self.popup = popup self.label = Label(parent, label, colour=colour[0]) self.entry = ListEntry(parent, ", ".join([str(x) for x in init]), colour=colour[1], outFunction=self.onEntry) CeciliaLib.setToolTip(self.label, TT_GEN)
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 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 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 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 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 onStart(): ceciliaMainFrame = CeciliaMainFrame.CeciliaMainFrame(None, -1) CeciliaLib.setVar("mainFrame", ceciliaMainFrame) file = "" if len(sys.argv) > 1: file = sys.argv[1] if os.path.isfile(file): ceciliaMainFrame.onOpen(file) 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 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 __init__(self, parent, y_pos): wx.Frame.__init__(self, parent, -1, "", pos=(-1, y_pos), style = wx.FRAME_SHAPED | wx.SIMPLE_BORDER | \ wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP ) self.Bind(wx.EVT_PAINT, self.OnPaint) self.bmp = wx.Bitmap(os.path.join(RESOURCES_PATH, "Cecilia_splash.png"), wx.BITMAP_TYPE_PNG) w, h = self.bmp.GetWidth(), self.bmp.GetHeight() self.SetClientSize((w, h)) if wx.Platform == "__WXGTK__": self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape) else: self.SetWindowShape() dc = wx.ClientDC(self) dc.DrawBitmap(self.bmp, 0,0,True) self.fc = wx.FutureCall(3000, self.OnClose) self.Center(wx.HORIZONTAL) if CeciliaLib.getPlatform() == 'win32': self.Center(wx.VERTICAL) self.Show(True)
def newRecent(self, file, remove=False): if ".cecilia5" in file: return file = CeciliaLib.ensureNFD(file) filename = os.path.join(TMP_PATH, '.recent.txt') try: f = open(filename, "r") lines = [CeciliaLib.ensureNFD(line[:-1]) for line in f.readlines()] f.close() except: lines = [] update = False if not remove: if file not in lines and 'Resources/modules/' not in file: lines.insert(0, file) update = True else: if file in lines: lines.remove(file) update = True if update: f = open(filename, "w") if len(lines) > 10: lines = lines[0:10] for line in lines: f.write(line + '\n') f.close() subId2 = ID_OPEN_RECENT recentFiles = [] f = open(filename, "r") for line in f.readlines(): recentFiles.append(line) f.close() if recentFiles: for item in self.menubar.openRecentMenu.GetMenuItems(): self.menubar.openRecentMenu.Delete(item) for file in recentFiles: try: self.menubar.openRecentMenu.Append(subId2, file) subId2 += 1 except: pass
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 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 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 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 __init__(self, parent, choiceFunc, order): Plugin.__init__(self, parent, choiceFunc, order) self.pluginName = '3 Bands EQ' self.knobNameTemplates = ['plugin_%d_eq3b_low', 'plugin_%d_eq3b_mid', 'plugin_%d_eq3b_high'] self.sizer = wx.FlexGridSizer(1, 4, 0, 0) revMenuBox = wx.BoxSizer(wx.VERTICAL) self.knob1 = PluginKnob(self, -60, 18, 0, size=(43, 70), log=False, outFunction=self.onChangeKnob1, label='Low') self.knob1.setName(self.knobNameTemplates[0] % self.order) self.knob1.setFloatPrecision(2) self.sizer.Add(self.knob1) self.knob2 = PluginKnob(self, -60, 18, 0, size=(43, 70), log=False, outFunction=self.onChangeKnob2, label='Mid') self.knob2.setName(self.knobNameTemplates[1] % self.order) self.knob2.setFloatPrecision(2) self.sizer.Add(self.knob2) self.knob3 = PluginKnob(self, -60, 18, 0, size=(43, 70), log=False, outFunction=self.onChangeKnob3, label='High') self.knob3.setName(self.knobNameTemplates[2] % self.order) self.knob3.setFloatPrecision(2) self.sizer.Add(self.knob3) self.setKnobLabels() self.createHeadBox() revMenuBox.Add(self.headBox, 0, wx.TOP, 0) self.choice = CustomMenu(self, choice=PLUGINS_CHOICE, init='3 Bands EQ', size=(93, 18), colour=PLUGINPOPUP_BACK_COLOUR, outFunction=self.replacePlugin) CeciliaLib.setToolTip(self.choice, TT_POST_ITEMS) revMenuBox.Add(self.choice, 0, wx.TOP, 2) plugChoicePreset = wx.StaticText(self, -1, 'Type:') plugChoicePreset.SetFont(wx.Font(CONTROLSLIDER_FONT, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) plugChoicePreset.SetForegroundColour(TEXT_LABELFORWIDGET_COLOUR) revMenuBox.Add(plugChoicePreset, 0, wx.TOP, 6) self.preset = CustomMenu(self, choice=['Bypass', 'Active'], init='Active', size=(93, 18), colour=CONTROLLABEL_BACK_COLOUR, outFunction=self.onChangePreset) self.presetName = 'plugin_%d_eq3b_preset' % self.order revMenuBox.Add(self.preset, 0, wx.TOP, 2) self.sizer.Add(revMenuBox, 0, wx.LEFT, 5) self.SetSizer(self.sizer)
def MacReopenApp(self): try: CeciliaLib.getVar("mainFrame").Raise() except: pass
ceciliaMainFrame.onOpen(os.path.join(MODULES_PATH, category, file), True) if __name__ == '__main__': reload(sys) sys.setdefaultencoding('utf-8') if not os.path.isdir(TMP_PATH): os.mkdir(TMP_PATH) if not os.path.isfile(os.path.join(TMP_PATH,'.recent.txt')): f = open(os.path.join(TMP_PATH,'.recent.txt'), "w") f.close() if not os.path.isdir(AUTOMATION_SAVE_PATH): os.mkdir(AUTOMATION_SAVE_PATH) 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
def MacOpenFiles(self, filenames): if type(filenames) == ListType: filenames = filenames[0] if CeciliaLib.getVar("mainFrame") is not None: CeciliaLib.getVar("mainFrame").onOpen(filenames)