-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmicronux.py
executable file
·142 lines (110 loc) · 3.46 KB
/
micronux.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
#! /usr/bin/python3
#
# Micronux
#
# A program editor for the Micron synth
import sys
from micronux import gui, importer, exporter, midi, terminal
class mx:
startup_program = terminal.startup(sys.argv)
allSettings = importer.open_file(startup_program)
ui = gui.micronux_ui(mx.allSettings)
ui.map_widgets(mx.allSettings, startup=True)
ui.win.show()
ui.lcd_message('startup')
# Open file
def open_file():
fname, _ = gui.QtWidgets.QFileDialog.getOpenFileName(
ui.win,
'Open file',
'./programs/',
"Sysex or Text Files (*.syx *.txt)")
if fname:
setup = importer.open_file(fname)
if setup:
mx.allSettings = setup
ui.map_widgets(mx.allSettings)
exporter.clear_changes(ui)
ui.lcd_message('open_success')
else:
ui.lcd_message('open_error')
ui.win.ctrl_auto_send.setChecked(False)
ui.win.ctrl_open.clicked.connect(open_file)
# Save file
def save_file():
saved = False
prog_name = mx.allSettings['name'].value
fname, _ = gui.QtWidgets.QFileDialog.getSaveFileName(
ui.win,
'Save file', './programs/'+prog_name+'.txt',
".syx or .txt (*.syx *.txt)")
if fname:
txt = exporter.build_txt_file(mx.allSettings)
if fname.endswith('.txt'):
txt_file = open(fname, 'w')
if txt_file:
txt_file.write(txt)
txt_file.close()
saved = True
elif fname.endswith('.syx'):
syx = terminal.txt_to_syx(txt)
syx_file = open(fname, 'wb')
if syx_file:
syx_file.write(syx)
syx_file.close()
saved = True
if saved:
mx.allSettings = importer.open_file(fname)
exporter.clear_changes(ui)
ui.lcd_message('save_success')
else:
ui.lcd_message('save_error')
ui.win.ctrl_save.clicked.connect(save_file)
# Receive sysex
def pass_to_receive():
ui.lcd_message('receiving')
ui.pop_up()
ui.win.lcdScreen.raise_()
gui.QTimer.singleShot(0, receive_sysex)
def receive_sysex():
port = ui.win.ctrl_midi_port.currentText()
if midi.interface(port, 'receive'):
setup = importer.open_file(midi.receive_cache)
if setup:
mx.allSettings = setup
ui.map_widgets(mx.allSettings)
exporter.clear_changes(ui)
ui.lcd_message('receive_success')
else:
ui.lcd_message('receive_error')
ui.pop_down()
ui.win.ctrl_receive.clicked.connect(pass_to_receive)
# Send sysex
def send_sysex():
txt = exporter.build_txt_file(mx.allSettings)
syx = terminal.txt_to_syx(txt)
port = ui.win.ctrl_midi_port.currentText()
if midi.interface(port, 'send', syx):
ui.lcd_message('send_success')
return True
else:
ui.lcd_message('send_error')
ui.win.ctrl_send.clicked.connect(send_sysex)
# Auto-send
def set_auto_send():
exporter.auto = ui.win.ctrl_auto_send.isChecked()
if exporter.auto:
ui.win.ctrl_send.setText('auto')
ui.win.ctrl_send.setEnabled(False)
exporter.auto_send(ui)
else:
ui.win.ctrl_send.setText('send')
ui.win.ctrl_send.setEnabled(True)
ui.win.ctrl_auto_send.clicked.connect(set_auto_send)
# Revert changes
def revert():
exporter.revert_changes(ui, mx.allSettings)
ui.win.ctrl_revert.clicked.connect(revert)
# Rename program
ui.win.name.clicked.connect(ui.rename_dialogue)
sys.exit(ui.app.exec_())