-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFluxusBros-Interface.py
293 lines (275 loc) · 12.4 KB
/
FluxusBros-Interface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/usr/bin/python
from os import popen
import os.path
import wx
from wx import xrc
import re
import rtmidi
from MidiConnectionsRtMidi import Connections
from MessageDispatch import *
from ClockGui import ClockControl
from MediaGui import MediaPanel
from ControlsGui import ControlsPanel
from TableGui import TablePanel
from SequencerGui import SequencerPanel
from MappingGui import MappingFrame
from configobj import ConfigObj
from CustomWidgets import wxFader
from CustomWidgets import wxKnob
from CustomWidgets import wxPiano
from CustomWidgetsXRC import wxFaderCtrlXmlHandler
from CustomWidgetsXRC import wxKnobCtrlXmlHandler
from CustomWidgetsXRC import wxPianoCtrlXmlHandler
from CustomWidgetsXRC import wxMediaVisualCtrlXmlHandler
APP_SIZE_X = 900
APP_SIZE_Y = 400
FluxusInClient = "FluxusMidi Input Client"
FluxusInPort = "FluxusMidi Input Client:0"
MicroKontrol_Out_Client = "microKontrol"
MicroKontrol_Out_Port = "microKONTROL:1"
Bitstream_Out_Port = "Bitstream 3X:0"
VirtualKeyboard_Port = "Virtual Keyboard:0"
Kmidimon_Port = "KMidimon:0"
NanoKontrolPort = "nanoKONTROL:0"
LMMSPort = "LMMS:1"
INMIDIPORT = [MicroKontrol_Out_Port , Bitstream_Out_Port , VirtualKeyboard_Port , NanoKontrolPort]
OUTMIDIPORT = [FluxusInPort , Kmidimon_Port, LMMSPort]
DEFAULT_PLAYERS = ["Korg" , "VMXVJ" , "BitStream"]
DEFAULT_PROFILE = ["Layer 1"]
global FLUXUSBROS_DIRECTORY
FLUXUSBROS_DIRECTORY = "~/Sources/git/FluxusBros"
global FLUXUSBROS_INTERFACE_DIRECTORY
FLUXUSBROS_INTERFACE_DIRECTORY = "~/Sources/git/FluxusBros-Interface"
class MyFrame(wx.Frame):
def __init__(self, parent, ID, title):
self.cfg = ConfigObj("./config.cfg")
self.Dispatch = MessageDispatchRules(self)
self.InitFrame(parent, ID, title)
EVT_WIDGET_MESSAGE_RECORD(self, self.Dispatch.AddInMessage)
EVT_WIDGET_MESSAGE_UNRECORD(self, self.Dispatch.DelInMessage)
EVT_WIDGET_MESSAGE_GET(self, self.Dispatch.GetInMessage)
EVT_WIDGET_MESSAGE_UPDATE(self, self.Dispatch.InternalMessage)
EVT_EXTERNAL_MIDI_IN_MESSAGE(self, self.Dispatch.ExternalMidiInMessage)
EVT_EXTERNAL_MIDI_OUT_MESSAGE(self, self.MidiOutputRefresh)
EVT_WIDGET_SEQUENCER_RECORD(self, self.Dispatch.AddSequencer)
EVT_WIDGET_SEQUENCER_MESSAGE_RECORD(self, self.Dispatch.AddSequence)
EVT_WIDGET_SEQUENCER_MESSAGE_UNRECORD(self, self.Dispatch.DelSequence)
self.InitConfig(parent, ID, title)
def InitFrame(self, parent, ID, title):
global FLUXUSBROS_DIRECTORY
global FLUXUSBROS_INTERFACE_DIRECTORY
try:
print("Config File")
w , h = self.cfg['App'].as_int('width'), self.cfg['App'].as_int('height')
FLUXUSBROS_DIRECTORY = self.cfg['App']['FluxusBros_Directory']
FLUXUSBROS_INTERFACE_DIRECTORY = self.cfg['App']['FluxusBros_Interface_Directory']
except:
print("Defaults")
w, h = (APP_SIZE_X, APP_SIZE_Y)
self.cfg['App'] = {}
self.cfg['App']['width'] = w
self.cfg['App']['height'] = h
self.cfg['App']['FluxusBros_Directory'] = FLUXUSBROS_DIRECTORY
self.cfg['App']['FluxusBros_Interface_Directory'] = FLUXUSBROS_INTERFACE_DIRECTORY
self.cfg.write()
FLUXUSBROS_DIRECTORY = self.cfg['App']['FluxusBros_Directory']
FLUXUSBROS_INTERFACE_DIRECTORY = self.cfg['App']['FluxusBros_Interface_Directory']
wx.Frame.__init__(self, parent, ID, title, wx.DefaultPosition, wx.Size(w, h))
def InitConfig(self, parent, ID, title):
try:
inmidiport = self.cfg['MidiPort'].as_list('InPort')
outmidiport = self.cfg['MidiPort'].as_list('OutPort')
except:
inmidiport = INMIDIPORT
outmidiport = OUTMIDIPORT
self.cfg['MidiPort']={}
self.cfg['MidiPort']['InPort'] = inmidiport
self.cfg['MidiPort']['OutPort'] = outmidiport
self.cfg.write()
self.InitMidi(inmidiport, outmidiport)
try:
self.Players = self.cfg.as_list('Players')
except:
self.Players = DEFAULT_PLAYERS
self.cfg['Players'] = self.Players
self.cfg.write()
try:
self.DefaultPlayer = self.cfg['DefaultPlayer']
except:
self.DefaultPlayer = self.cfg.as_list('Players')[1]
self.cfg['DefaultPlayer'] = self.DefaultPlayer
self.cfg.write()
try:
self.Player = self.cfg[self.DefaultPlayer]
except:
self.cfg[self.DefaultPlayer] = {}
self.cfg.write()
self.Player = self.cfg[self.DefaultPlayer]
self.SetPlayerName(self.DefaultPlayer)
try:
self.Layers = self.cfg[self.DefaultPlayer]['Layers'].keys()
self.DefaultLayer = self.cfg[self.DefaultPlayer]['DefaultLayer']
self.Layer = self.cfg[self.DefaultPlayer]['Layers'][self.DefaultLayer]
except:
self.cfg[self.DefaultPlayer]['Layers'] = {}
self.cfg[self.DefaultPlayer]['Layers']['Layer 1'] = {}
self.cfg[self.DefaultPlayer]['DefaultLayer'] = self.cfg[self.DefaultPlayer]['Layers'].keys()[0]
self.cfg.write()
self.Layers = self.cfg[self.DefaultPlayer]['Layers'].keys()
self.DefaultLayer = self.cfg[self.DefaultPlayer]['DefaultLayer']
self.Layer = self.cfg[self.DefaultPlayer]['Layers'][self.DefaultLayer]
self.SetLayerName(self.DefaultLayer)
try:
Medias = self.Layer['Media']
except:
self.Layer['Media'] = {}
self.cfg.write()
Medias = self.Layer['Media']
self.InitPanels()
def InitMidi(self, inmidi=[], outmidi=[]):
self.MidiConnect = Connections(self.MidiInputRefresh, inmidi, outmidi)
def MidiInputRefresh(self, midi_data):
wx.PostEvent(self, ExternalMidiInMessage(midi_data))
def MidiOutputRefresh(self, event):
self.MidiConnect.sendMessage(event.GetMidiMessage())
def InitPanels(self):
vbox = wx.BoxSizer(wx.VERTICAL)
toolbar = self.InitToolBar()
vbox.Add(toolbar, 0, wx.EXPAND)
hbox = wx.BoxSizer(wx.HORIZONTAL)
#~ self.Media = MediaPanel(self)
self.Table = self.LoadTable(self.GetPlayerName(), self.GetLayerName())
#~ print("debug")
#~ print self.Layers
#~ print self.Layer
#~ print self.GetLayerName()
#~ print self.GetPlayerName() + '-' + self.GetLayerName()
self.Sequencer = SequencerPanel(self)
#~ hbox.Add(self.Media, proportion = 0)
self.TableBox = wx.BoxSizer(wx.VERTICAL)
#~ TableBox.Add(self.Controls, proportion = 1, flag=wx.EXPAND)
self.TableBox.Add(self.Table, proportion = 2, flag=wx.EXPAND)
hbox.Add(self.TableBox, 2, wx.EXPAND)
hbox.Add(self.Sequencer, proportion = 1, flag=wx.EXPAND)
vbox.Add(hbox, proportion=-1, flag=wx.EXPAND)
self.SetSizer(vbox)
#~ EVT_WIDGET_SEQUENCER_MESSAGE_RECORD(self, self.Sequencer.InitSequence)
#~ EVT_WIDGET_SEQUENCER_MESSAGE_UNRECORD(self, self.Sequencer.DelSequence)
def LoadTable(self, player, layer):
xrc_path = player + '-' + layer + '.xrc'
if os.path.exists(xrc_path):
res = xrc.XmlResource(xrc_path)
res.InsertHandler(wxKnobCtrlXmlHandler())
res.InsertHandler(wxFaderCtrlXmlHandler())
res.InsertHandler(wxPianoCtrlXmlHandler())
res.InsertHandler(wxMediaVisualCtrlXmlHandler())
Table = res.LoadPanel(self, 'TablePanel')
return Table
else:
DefaultPanel = wx.Panel(self)
hbox = wx.BoxSizer(wx.VERTICAL)
DefaultPanelMsg1 = wx.StaticText(DefaultPanel, -1, "Missing XRC Xml Ressource File : ")
DefaultPanelMsg2 = wx.TextCtrl(DefaultPanel, -1, xrc_path, style=wx.TE_READONLY)
hbox.Add(DefaultPanelMsg1,proportion=0)
hbox.Add(DefaultPanelMsg2, 0, wx.EXPAND)
DefaultPanel.SetSizer(hbox)
return DefaultPanel
def InitToolBar(self):
toolbar = wx.ToolBar(self, -1)
TOOL_ID = wx.NewId()
# Players List
TOOL_ID_PLAYER_COMBO = wx.NewId()
self.PlayerCombo = wx.ComboBox(toolbar, TOOL_ID_PLAYER_COMBO, choices = self.Players)
self.PlayerCombo.SetStringSelection(self.GetPlayerName())
toolbar.AddControl(self.PlayerCombo)
wx.EVT_COMBOBOX(self, TOOL_ID_PLAYER_COMBO, self.SetPlayer)
# Layers List
TOOL_ID_COMBO_LAYERS = wx.NewId()
self.LayerCombo = wx.ComboBox(toolbar, TOOL_ID_COMBO_LAYERS, choices = self.Layers)
self.LayerCombo.SetStringSelection(self.DefaultLayer)
toolbar.AddControl(self.LayerCombo)
wx.EVT_COMBOBOX(self, TOOL_ID_COMBO_LAYERS, self.SetLayer)
#Midi Clock Control
Clock = ClockControl(toolbar, wx.NewId())
toolbar.AddControl(Clock)
toolbar.AddSeparator()
# Mapping Modul
bmp = wx.ArtProvider.GetBitmap(wx.ART_LIST_VIEW, wx.ART_OTHER, (16, 16))
MAPPINGMODUL_ID = wx.NewId()
self.MappingModulDialogState = False
MappingModul = toolbar.AddLabelTool(MAPPINGMODUL_ID, 'Mapping', bmp, kind=wx.ITEM_NORMAL, shortHelp='Mapping Module')
self.Bind(wx.EVT_MENU, self.MappingModulDialog, id=MAPPINGMODUL_ID)
toolbar.AddSeparator()
# Preference Settings
bmp = wx.ArtProvider.GetBitmap(wx.ART_EXECUTABLE_FILE, wx.ART_OTHER, (16, 16))
ToolbarPreferences = toolbar.AddLabelTool(-1, 'Preferences', bmp, shortHelp='Preferences')
#~ self.Bind(wx.EVT_MENU, self.onPrint, printTool)
toolbar.Realize()
return toolbar
def MappingModulDialog(self, event):
if self.MappingModulDialogState is False:
self.MappingModulDialogState = True
MAPPINGFRAME_ID = wx.NewId()
MapFrame = MappingFrame(self, MAPPINGFRAME_ID, "Mapping Module", wx.DefaultPosition, (700,700))
MapFrame.Bind(wx.EVT_CLOSE, self.MappingModulDialogEnd, id=MAPPINGFRAME_ID)
MapFrame.Show()
def MappingModulDialogEnd(self, event):
self.MappingModulDialogState = False
event.GetEventObject().Destroy()
def SetComboLayers(self):
self.LayerCombo.Clear()
self.SetLayers()
self.LayerCombo.Append(self.Layer)
self.LayerCombo.SetSelection(0)
self.SetLayer(0)
def SetLayers(self):
try:
self.Layers = self.cfg[self.GetPlayerName()]['Layers'].keys()
self.DefaultLayer = self.cfg[self.GetPlayerName()]['DefaultLayer']
self.Layer = self.DefaultLayer
except:
self.cfg[self.GetPlayerName()]['Layers'] = {}
self.cfg[self.GetPlayerName()]['Layers']['Layer 1'] = {}
self.cfg[self.GetPlayerName()]['DefaultLayer'] = self.cfg[self.GetPlayerName()]['Layers'].keys()[0]
self.cfg.write()
self.Layers = self.cfg[self.GetPlayerName()]['Layers'].keys()
self.DefaultLayer = self.cfg[self.GetPlayerName()]['DefaultLayer']
print self.DefaultLayer
self.Layer = self.DefaultLayer
def SetPlayer(self, event):
print("New Player : %s" % event.GetEventObject().GetValue())
self.SetPlayerName(event.GetEventObject().GetValue())
try:
self.Player = self.cfg[self.GetPlayerName()]
except:
self.cfg[self.GetPlayerName()] = {}
self.cfg.write()
self.Player = self.cfg[self.GetPlayerName()]
self.SetComboLayers()
#~ self.SetLayer(0)
def GetPlayer(self):
return self.Player
def SetPlayerName(self, name):
self.PlayerName = name
def GetPlayerName(self):
return self.PlayerName
def SetLayer(self, event):
self.SetLayerName(self.LayerCombo.GetValue())
NewTable = self.LoadTable(self.GetPlayerName(), self.GetLayerName())
self.TableBox.Replace(self.Table, NewTable)
self.TableBox.Layout()
self.Table.DestroyChildren()
self.Table.Destroy()
self.Table = NewTable
def SetLayerName(self, name):
self.LayerName = name
def GetLayerName(self):
return self.LayerName
class MyApp(wx.App):
def OnInit(self, *args, **kwargs):
self.MainFrame = MyFrame(None, -1, "FluxusBros Interface")
self.MainFrame.Show(True)
self.SetTopWindow(self.MainFrame)
return True
app = MyApp(0)
app.MainLoop()