-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
executable file
·77 lines (65 loc) · 1.82 KB
/
server.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
#!/usr/bin/env python3
import eventlet, sys
eventlet.monkey_patch()
'''
TODO:
Finish MIDI configuration:
* Click on logo configures MIDI interface, channel
* Fix Measure Buttons/graphic
* Click on icon changes the MIDI note for that subdivision
'''
from flask import Flask, render_template, request, abort
from flask_socketio import SocketIO, send, emit
import mido, logging, json
from settings import Settings
from ticker import Ticker
app = Flask(__name__)
socketio = SocketIO(app)
defaults = Settings()
ticker = Ticker()
ticker.start()
@app.before_first_request
def check_socketio_server():
if not socketio.server:
abort(500, 'SocketIO server is not loaded')
@socketio.on('error')
def handle_render_error(data):
abort(500, 'Client side error: ' + {data})
@app.route('/')
def index():
return render_template('index.html', parameters=defaults.to_json())
@socketio.on('update_from_gui')
def on_update(parameters):
global ticker
ticker.update(parameters)
# TBD - save settings
@socketio.on('connect')
def on_connect():
global ticker
global defaults
ticker.update(defaults)
@app.route('/file-dialog', methods=['GET', 'POST'])
def file_dialog():
if request.method == 'POST':
selected_files = request.form.getlist('files')
return render_template('file-dialog.html')
@socketio.on('transport')
def on_transport(source):
global ticker
if source == 'id_load':
emit('open_file_dialog')
ticker.transport_action(source)
@socketio.on('disconnect')
def on_disconnect():
global ticker
print('disconnect')
ticker.update(None)
@socketio.on('log')
def on_log(msg):
print('log: ' + str(msg))
if __name__ == "__main__":
try:
socketio.run(app, host='0.0.0.0', port=5000)
except:
print('Server launch error')
sys.exit(-1)