Skip to content

Commit

Permalink
Removed no more needed unicode-related code.
Browse files Browse the repository at this point in the history
  • Loading branch information
belangeo committed Apr 16, 2018
1 parent ec582e7 commit 6d158b4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Resources/audio.py
Expand Up @@ -1078,7 +1078,7 @@ def checkForCustomModules():
line = line.strip()
if line:
sline = line.split("=")
path = vars.vars["ensureNFD"](sline[1].strip())
path = sline[1].strip()
if path != "":
if os.path.isdir(path):
files = [f for f in os.listdir(path) if f.endswith(".py")]
Expand Down
14 changes: 6 additions & 8 deletions Resources/panels.py
Expand Up @@ -355,7 +355,6 @@ def __init__(self, parent, colour=BACKGROUND_COLOUR):
if vars.vars["AUDIO_HOST"] != "Jack":
preferedDriver = vars.vars["OUTPUT_DRIVER"]
self.driverList, self.driverIndexes = get_output_devices()
self.driverList = [vars.vars["ensureNFD"](driver) for driver in self.driverList]
self.defaultDriver = get_default_output()
self.popupDriver = wx.Choice(self, id=-1, choices=self.driverList, size=popsize)
if preferedDriver and preferedDriver in self.driverList:
Expand All @@ -376,7 +375,6 @@ def __init__(self, parent, colour=BACKGROUND_COLOUR):
self.interfaceText = wx.StaticText(self, id=-1, label="Midi interface")
self.mainBox.Add(self.interfaceText, 0, wx.TOP | wx.LEFT, 4)
self.interfaceList, self.interfaceIndexes = get_midi_input_devices()
self.interfaceList = [vars.vars["ensureNFD"](interface) for interface in self.interfaceList]
if self.interfaceList != []:
self.interfaceList.append("Virtual Keyboard")
self.defaultInterface = get_midi_default_input()
Expand Down Expand Up @@ -874,7 +872,7 @@ def createAdsrKnobs(self):
def createSlider(self, label, value, minValue, maxValue, integer, log, callback, i=-1):
if vars.constants["PLATFORM"] == "darwin": height = 14
else: height = 13
text = wx.StaticText(self, id=-1, label=vars.vars["toSysEncoding"](label), size=(200,height))
text = wx.StaticText(self, id=-1, label=label, size=(200,height))
self.labels.append(text)
if vars.constants["PLATFORM"] != "win32":
font, psize = text.GetFont(), text.GetFont().GetPointSize()
Expand Down Expand Up @@ -957,7 +955,7 @@ def __init__(self, parent, name, title, synth, p1, p2, p3):
self.info.Bind(wx.EVT_LEAVE_WINDOW, self.leaveInfo)
self.info.Bind(wx.EVT_LEFT_DOWN, self.MouseDownInfo)
self.info.SetToolTip(wx.ToolTip("Show module's infos"))
self.title = wx.StaticText(self.headPanel, id=-1, label=vars.vars["toSysEncoding"](title))
self.title = wx.StaticText(self.headPanel, id=-1, label=title)
self.corner = GenStaticText(self.headPanel, -1, label="m/s")
self.corner.SetToolTip(wx.ToolTip("Mute / Solo. Click to mute, Shift+Click to solo"))
self.corner.Bind(wx.EVT_LEFT_DOWN, self.MouseDownCorner)
Expand Down Expand Up @@ -1076,9 +1074,9 @@ def MouseDownInfo(self, evt):
size = (850, 600)
else:
size = (850, 600)
lines = [vars.vars["ensureNFD"](line) for line in self.synth.__doc__.splitlines(True)]
lines = self.synth.__doc__.splitlines(True)
win = HelpFrame(self.GetTopLevelParent(), -1, title="Module info", size=size,
subtitle=vars.vars["ensureNFD"]("Info about %s module." % self.name), lines=lines)
subtitle="Info about %s module." % self.name, lines=lines)
win.CenterOnParent()
win.Show(True)
else:
Expand Down Expand Up @@ -1338,7 +1336,7 @@ def __init__(self, parent, name, title, synth, p1, p2, p3, p4, which):
self.close.Bind(wx.EVT_LEAVE_WINDOW, self.leaveX)
self.close.Bind(wx.EVT_LEFT_DOWN, self.MouseDown)
self.close.SetToolTip(wx.ToolTip("Close window"))
self.title = GenStaticText(self.headPanel, -1, label=vars.vars["toSysEncoding"](title))
self.title = GenStaticText(self.headPanel, -1, label=title)
self.title.SetToolTip(wx.ToolTip("Move window"))
self.titleSizer.AddMany([(self.close, 0, wx.LEFT|wx.TOP, 3), (self.title, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.TOP, 3)])
self.headPanel.SetSizerAndFit(self.titleSizer)
Expand Down Expand Up @@ -1375,7 +1373,7 @@ def changeP2(self, x):
else:
self.synth._params[self.which].lfo.setType(x)
wave = {0: "Ramp", 1: "Sawtooth", 2: "Square", 3: "Triangle", 4: "Pulse", 5: "Bipolar Pulse", 6: "Sample and Hold", 7: "Modulated Sine"}[x]
self.labels[2].SetLabel(vars.vars["ensureNFD"]("Waveform - %s" % wave))
self.labels[2].SetLabel("Waveform - %s" % wave)

def changeP3(self, x):
if self.which == 0:
Expand Down
15 changes: 7 additions & 8 deletions Resources/preferences.py
Expand Up @@ -129,7 +129,6 @@ def getDriver(self, evt):
driverList, driverIndexes = get_midi_input_devices()
driverList.append("Virtual Keyboard")
msg = "Choose a Midi interface..."
driverList = [vars.vars["ensureNFD"](driver) for driver in driverList]
widget = wx.FindWindowByName(name)
dlg = wx.SingleChoiceDialog(self, message=msg, caption="Driver Selector",
choices=driverList, style=wx.CHOICEDLG_STYLE)
Expand Down Expand Up @@ -179,14 +178,14 @@ def checkForPreferencesFile(self):
if line:
sline = line.split("=")
if sline[0].strip() == "AUDIO_HOST" and vars.constants["PLATFORM"] == "darwin" and not vars.constants["OSX_BUILD_WITH_JACK_SUPPORT"] and sline[1].strip() in ["Jack", "Coreaudio"]:
self.prefs[sline[0].strip()] = vars.vars["ensureNFD"]("Portaudio")
self.prefs[sline[0].strip()] = "Portaudio"
else:
self.prefs[sline[0].strip()] = vars.vars["ensureNFD"](sline[1].strip())
self.prefs[sline[0].strip()] = sline[1].strip()

def onSave(self, event):
preffile = os.path.join(os.path.expanduser("~"), ".zynerc")
with codecs.open(preffile, "w", encoding="utf-8") as f:
f.write(u"### Zyne version %s preferences ###\n" % vars.constants["VERSION"])
f.write("### Zyne version %s preferences ###\n" % vars.constants["VERSION"])
for name in vars.constants["VARIABLE_NAMES"]:
widget = wx.FindWindowByName(name)
if isinstance(widget, wx.ComboBox):
Expand All @@ -195,13 +194,13 @@ def onSave(self, event):
else:
value = widget.GetValue()
try:
f.write(u"%s = %s\n" % (name, value))
f.write("%s = %s\n" % (name, value))
except UnicodeEncodeError:
try:
f.write(u"%s = " % name + vars.vars["ensureNFD"](value) + u"\n")
f.write("%s = " % name + value + "\n")
except:
f.write(u'%s = ""\n' % name)
f.write(u"LAST_SAVED = %s\n" % vars.vars["LAST_SAVED"])
f.write('%s = ""\n' % name)
f.write("LAST_SAVED = %s\n" % vars.vars["LAST_SAVED"])
self.EndModal(0)


2 changes: 1 addition & 1 deletion Resources/splash.py
Expand Up @@ -77,7 +77,7 @@ def OnPaint(self, evt):
else:
font.SetPointSize(ptsize+1)
dc.SetFont(font)
dc.DrawLabel(u"Olivier Bélanger", wx.Rect(0, 305, 400, 15), wx.ALIGN_CENTER)
dc.DrawLabel("Olivier Bélanger", wx.Rect(0, 305, 400, 15), wx.ALIGN_CENTER)
dc.DrawLabel("ajaxsoundstudio, %s" % vars.constants["YEAR"], wx.Rect(0, 340, 400, 15), wx.ALIGN_CENTER)
dc.DrawLabel("v. %s" % vars.constants["VERSION"], wx.Rect(0, 360, 400, 15), wx.ALIGN_CENTER)

Expand Down
43 changes: 4 additions & 39 deletions Resources/variables.py
Expand Up @@ -10,8 +10,8 @@
constants["YEAR"] = "2018"
constants["PLATFORM"] = sys.platform
constants["OSX_BUILD_WITH_JACK_SUPPORT"] = False
constants["DEFAULT_ENCODING"] = sys.getdefaultencoding()
constants["SYSTEM_ENCODING"] = sys.getfilesystemencoding()
#constants["DEFAULT_ENCODING"] = sys.getdefaultencoding()
#constants["SYSTEM_ENCODING"] = sys.getfilesystemencoding()

if '/Zyne.app' in os.getcwd():
constants["RESOURCES_PATH"] = os.getcwd()
Expand Down Expand Up @@ -87,41 +87,6 @@
vars["VIRTUAL"] = False
vars["MIDI_ACTIVE"] = 0

def ensureNFD(unistr):
if constants["PLATFORM"] == "win32" or constants["PLATFORM"].startswith("linux"):
encodings = [constants["DEFAULT_ENCODING"], constants["SYSTEM_ENCODING"],
'cp1252', 'iso-8859-1', 'utf-16']
format = 'NFC'
else:
encodings = [constants["DEFAULT_ENCODING"], constants["SYSTEM_ENCODING"],
'macroman', 'iso-8859-1', 'utf-16']
format = 'NFD'
if type(unistr) != unicode_t:
for encoding in encodings:
try:
unistr = unistr.decode(encoding)
break
except UnicodeDecodeError:
continue
except:
unistr = "UnableToDecodeString"
print("Unicode encoding not in a recognized format...")
break
return unicodedata.normalize(format, unistr)

def toSysEncoding(unistr):
try:
if constants["PLATFORM"] == "win32":
unistr = unistr.encode(constants["SYSTEM_ENCODING"])
else:
unistr = unicode(unistr)
except:
pass
return unistr

vars["ensureNFD"] = ensureNFD
vars["toSysEncoding"] = toSysEncoding

def checkForPreferencesFile():
preffile = os.path.join(os.path.expanduser("~"), ".zynerc")
if os.path.isfile(preffile):
Expand All @@ -141,14 +106,14 @@ def checkForPreferencesFile():
line = line.strip()
if line:
sline = line.split("=")
prefs[sline[0].strip()] = ensureNFD(sline[1].strip())
prefs[sline[0].strip()] = sline[1].strip()
for key in prefs.keys():
if key in ["SR", "POLY", "BITS"]:
vars[key] = int(prefs[key])
elif key in ["SLIDERPORT"]:
vars[key] = float(prefs[key])
elif key == "AUDIO_HOST" and constants["PLATFORM"] == "darwin" and not constants["OSX_BUILD_WITH_JACK_SUPPORT"] and prefs[key] in ["Jack", "Coreaudio"]:
vars[key] = ensureNFD("Portaudio")
vars[key] = "Portaudio"
else:
vars[key] = prefs[key]

Expand Down
13 changes: 6 additions & 7 deletions Zyne.py
@@ -1,6 +1,5 @@
#!/usr/bin/env python
import wx, os, sys
#from pyo import *
import Resources.audio as audio
import Resources.tutorial as tutorial
import Resources.variables as vars
Expand Down Expand Up @@ -44,7 +43,7 @@ def __init__(self, *args, **kw):
self.rtc.EndFontSize()
self.rtc.EndBold()
self.rtc.Newline()
lines = [vars.vars["ensureNFD"](line) for line in tutorial.__doc__.splitlines(True)]
lines = tutorial.__doc__.splitlines(True)
section_count = 1
for line in lines:
if line.count("----") == 2:
Expand Down Expand Up @@ -126,7 +125,7 @@ def __init__(self, parent, title="Export Samples...", pos=wx.DefaultPosition, si
self.filename.SetFocus()

class ZyneFrame(wx.Frame):
def __init__(self, parent=None, title=u"Zyne Synth - Untitled", size=(966, 660)):
def __init__(self, parent=None, title="Zyne Synth - Untitled", size=(966, 660)):
wx.Frame.__init__(self, parent, id=-1, title=title, size=size)
self.SetAcceleratorTable(wx.AcceleratorTable([(wx.ACCEL_NORMAL, ord("\t"), vars.constants["ID"]["Select"]),
(wx.ACCEL_SHIFT, ord("\t"), vars.constants["ID"]["DeSelect"])]))
Expand Down Expand Up @@ -356,7 +355,7 @@ def buildAddModuleMenu(self):
if vars.vars["EXTERNAL_MODULES"] != {}:
moduleNames = sorted(vars.vars["EXTERNAL_MODULES"].keys())
for i, name in enumerate(moduleNames):
self.addMenu.Append(id, 'Add %s module' % vars.vars["toSysEncoding"](name), kind=wx.ITEM_NORMAL)
self.addMenu.Append(id, 'Add %s module' % name, kind=wx.ITEM_NORMAL)
self.Bind(wx.EVT_MENU, self.onAddModule, id=id)
self.moduleNames.append(name)
MODULES.update(vars.vars["EXTERNAL_MODULES"].items())
Expand Down Expand Up @@ -547,7 +546,7 @@ def onExport(self, evt):
rootpath = os.path.join(os.path.expanduser("~"), "Desktop", "zyne_export")
if not os.path.isdir(rootpath):
os.mkdir(rootpath)
filename = vars.vars["ensureNFD"](dlg.filename.GetValue())
filename = dlg.filename.GetValue()
subrootpath = os.path.join(rootpath, filename)
if not os.path.isdir(subrootpath):
os.mkdir(subrootpath)
Expand Down Expand Up @@ -587,7 +586,7 @@ def onExport(self, evt):
self.setModulesAndParams(modules, params, lfo_params, ctl_params, True)
self.serverPanel.setPostProcSettings(postProcSettings)
name = "%03d_%s.%s" % (i, filename, ext)
path = vars.vars["toSysEncoding"](os.path.join(subrootpath, name))
path = os.path.join(subrootpath, name)
count += 1
(keepGoing, skip) = dlg2.Update(count, "Exporting %s" % name)
self.serverPanel.setRecordOptions(dur=duration, filename=path)
Expand All @@ -601,7 +600,7 @@ def onExport(self, evt):
self.serverPanel.setPostProcSettings(postProcSettings)
self.modules[j].setMute(2)
name = "%03d_%s_track_%02d_%s.%s" % (i, filename, j, self.modules[j].name, ext)
path = vars.vars["toSysEncoding"](os.path.join(subrootpath, name))
path = os.path.join(subrootpath, name)
count += 1
(keepGoing, skip) = dlg2.Update(count, "Exporting %s" % name)
self.serverPanel.setRecordOptions(dur=duration, filename=path)
Expand Down

0 comments on commit 6d158b4

Please sign in to comment.