-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.py
207 lines (178 loc) · 7.32 KB
/
window.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
import time
from typing import List, Dict
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib, GdkX11
import edit
import rows
import functions
import import_all
from model import *
from constants import *
from ndexceptions import *
class AppWindow(Gtk.ApplicationWindow):
def __init__(self, app):
# (app :: NordDrum1Manager) -> MemoryWindow
# DATA
# Note that app.root is the data root.
self.app = app # not 100% sure this is necessary.
self.all_instrument_buttons = []
Gtk.ApplicationWindow.__init__(self,
title="Nord Drum Curator",
application=app)
self.set_default_size(1000, 800)
self.set_border_width(4)
wholeGrid = Gtk.VBox()
wholeGrid.set_size_request(1000, 800)
self.add(wholeGrid)
# Menubar
# This creates "insensitive" and unconnected menu items.
menubar = Gtk.MenuBar.new()
wholeGrid.add(menubar)
self.menuDict = {}
for key, value in MENU_DICT.items():
container = Gtk.Menu.new()
self.menuDict[key] = Gtk.MenuItem.new_with_label(key)
menubar.append(self.menuDict[key])
self.menuDict[key].set_submenu(container)
for i in value:
if i == "SEPARATOR":
container.append(Gtk.SeparatorMenuItem.new())
else:
self.menuDict[i] = Gtk.MenuItem.new_with_label(i)
self.menuDict[i].set_sensitive(False)
container.append(self.menuDict[i])
self.connectMenuItems()
# Panes
paned = Gtk.HPaned()
wholeGrid.add(paned)
# Programs on right.
swRight = Gtk.ScrolledWindow()
swRight.set_shadow_type(Gtk.ShadowType.IN)
self.progListBox = Gtk.ListBox()
self.progListBox.set_selection_mode(Gtk.SelectionMode.SINGLE)
# extend the all instr button list
self.progListBox.connect("row-selected", self.programRowSelected)
self.buildProgramRows()
swRight.add(self.progListBox)
paned.add2(swRight)
# Memory in left.
swLeft = Gtk.ScrolledWindow()
swLeft.set_shadow_type(Gtk.ShadowType.IN)
swLeft.set_size_request(400, 800)
self.memListBox = rows.MemoryListBox()
self.memListBox.set_selection_mode(Gtk.SelectionMode.SINGLE)
swLeft.add(self.memListBox)
paned.add1(swLeft)
self.buildMemoryRows()
def getSelectedProgram(self) -> NDProg:
return self.progListBox.get_selected_row().program
# Menu actions
def connectMenuItems(self):
e = self.menuDict["Edit program..."]
e.connect("activate", self.launchEditDialog)
save = self.menuDict["Save"]
save.set_sensitive(True)
save.connect("activate", self.saveRoot)
ex = self.menuDict["Exit"]
ex.set_sensitive(True)
ex.connect("activate", self.ex)
pull = self.menuDict["Pull all..."]
pull.set_sensitive(True)
pull.connect("activate", self.pull_all)
push = self.menuDict["Push to ND"]
push.set_sensitive(True)
push.connect("activate", self.push_to_nd)
def launchEditDialog(self, menu):
p = self.progListBox.get_selected_row()
diag = edit.EditProgramDialog(p)
diag.set_transient_for(self)
diag.connect("destroy", self.redraw)
diag.show_all()
def saveRoot(self, menu):
self.app.root.save()
def ex(self, menu):
self.destroy()
def pull_all(self, menu):
iw = import_all.ImportAllWindow(self.app.root,
self.memListBox,
self.progListBox,
self.app.port)
iw.set_transient_for(self)
iw.show_all()
def programRowSelected(self, box, row):
if row:
self.menuDict["Edit program..."].set_sensitive(True)
else:
self.menuDict["Edit program..."].set_sensitive(False)
def push_to_nd(self, menu):
messages = []
for i in range(99):
f = self.app.root.programFromSlot(i).file
message = functions.oneMessageToAll(functions.read_sysex(f), i)
messages.append(message)
functions.send_all(self.app.port, messages)
self.app.root.cache_status = 99 * ["checked"]
self.memListBox.updateAll()
self.app.port = mido.open_ioport(functions.getMidiPort())
# Other window methods
def redraw(self, w):
# (w :: Gtk.Window)
self.memListBox.updateAll()
def connectProgramInstrumentButtons(self,
pr: rows.ProgramRow):
for i in range(len(pr.channel_buttons)):
b = pr.channel_buttons[i]
b.connect("clicked", self.previewProgramSound, 3 - i)
pr.testButton.connect("clicked",
self.activateProgramInstruments,
pr)
self.all_instrument_buttons.append(b)
def connectMemoryInstrumentButtons(self,
mr: rows.MemoryRow):
for i in range(len(mr.channel_buttons)):
b = mr.channel_buttons[i]
b.connect("clicked", self.previewProgramSound, 3 - i)
mr.testButton.connect("clicked",
self.activateMemoryInstruments,
mr)
self.all_instrument_buttons.append(b)
def activateProgramInstruments(self,
button: Gtk.Button,
pr: rows.ProgramRow):
syx = functions.read_sysex(pr.program.file)
self.app.port.send(syx)
self.deactivateAllInstruments()
for b in pr.channel_buttons:
b.set_sensitive(True)
def activateMemoryInstruments(self,
button: Gtk.Button,
mr: rows.MemoryRow):
value = self.app.root.memory[mr.slot]
program = self.app.root.findProgram(value)
syx = functions.read_sysex(program.file)
self.app.port.send(syx)
self.deactivateAllInstruments()
for b in mr.channel_buttons:
b.set_sensitive(True)
# Building program and memory rows.
def buildProgramRows(self):
progs = self.app.root.programs
for p in progs:
self.progListBox.add(rows.ProgramRow(p))
self.progListBox.foreach(self.connectProgramInstrumentButtons)
def buildMemoryRows(self):
slots = self.app.root.memory
for i in range(0, len(slots)):
self.memListBox.add(rows.MemoryRow(i,self.app.root))
self.memListBox.foreach(self.connectMemoryInstrumentButtons)
# Button handlers.
def findProgram(self, prog_id: int) -> NDProg:
return functions.findProgram(prog_id, self.app.root.programs)
def previewProgramSound(self,
button: Gtk.Button,
channel_index: int):
functions.playSound(self.app.port, channel_index)
def deactivateAllInstruments(self):
for b in self.all_instrument_buttons:
b.set_sensitive(False)