diff --git a/schema.sql b/schema.sql index 4bb5f58..43b9be0 100644 --- a/schema.sql +++ b/schema.sql @@ -5,6 +5,7 @@ DROP TABLE IF EXISTS instrument_param; DROP TABLE IF EXISTS instrument_socket; DROP TABLE IF EXISTS patches; DROP TABLE IF EXISTS patch_param; +DROP TABLE IF EXISTS patch_socket; DROP TABLE IF EXISTS snippets; CREATE TABLE instruments ( @@ -25,15 +26,17 @@ CREATE TABLE sockets ( ); CREATE TABLE instrument_param ( - instrument_id INTEGER NOT NULL, + instrument TEXT NOT NULL, param_name TEXT NOT NULL, - PRIMARY KEY (instrument_id, param_name) + FOREIGN KEY (instrument) REFERENCES instruments(slug), + PRIMARY KEY (instrument, param_name) ); CREATE TABLE instrument_socket ( - instrument_id INTEGER NOT NULL, + instrument TEXT NOT NULL, socket_name TEXT NOT NULL, - PRIMARY KEY (instrument_id, socket_name) + FOREIGN KEY (instrument) REFERENCES instruments(slug), + PRIMARY KEY (instrument, socket_name) ); CREATE TABLE patches ( @@ -54,6 +57,13 @@ CREATE TABLE patch_param ( PRIMARY KEY (patch_id, param_name) ); +CREATE TABLE patch_socket ( + patch_id INTEGER NOT NULL, + socket_name TEXT NOT NULL, + value TEXT NOT NULL, + PRIMARY KEY (patch_id, socket_name) +); + CREATE TABLE snippets ( filename TEXT NOT NULL, instrument TEXT NOT NULL, diff --git a/static/css/add.css b/static/css/add.css index f065b9f..4a8c2c9 100644 --- a/static/css/add.css +++ b/static/css/add.css @@ -1,4 +1,4 @@ -main { +.grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; @@ -17,7 +17,7 @@ textarea { font-family: sans-serif; } -form > * + * { +.meta > * + * { margin-top: 16px; } @@ -37,6 +37,10 @@ input[type="submit"]:hover { border: 1px solid currentColor; } +.meta { + grid-column: 1 / span 1; +} + .preview { position: absolute; top: 8px; diff --git a/static/css/patch.css b/static/css/patch.css index 7be2e8f..91b9fcd 100644 --- a/static/css/patch.css +++ b/static/css/patch.css @@ -82,7 +82,7 @@ main { .meta { display: inline-block; - border: 2px solid currentColor; + border: 1px solid currentColor; padding: 16px; margin: 32px 0; max-width: 40ch; @@ -91,4 +91,14 @@ main { .meta .date { margin-top: 8px; opacity: 0.5; -} \ No newline at end of file +} + +.patch-text { + padding: 8px; + display: inline-block; + white-space: pre-wrap; + line-height: 1; + font-size: 18px; + background-color: rgba(200, 200, 200, 0.5); + max-width: 60ch; +} diff --git a/static/js/panel.js b/static/js/panel.js index c36d18a..2623659 100644 --- a/static/js/panel.js +++ b/static/js/panel.js @@ -287,6 +287,14 @@ class Panel { if (socket && socket.classList.contains("socket")) { this.cable.end = socket.getAttribute("name"); + let startSocket = document.querySelector(`.socket[name="${this.cable.start}"]`); + + let values = (startSocket.getAttribute("value") || "") + .split(",") + .map((entry) => entry.trim()); + values.push(this.cable.end); + startSocket.setAttribute("value", values.filter((value) => value != "").join()); + // TODO: log cable } else { this.cable.path.remove(); diff --git a/templates/add_instrument.html b/templates/add_instrument.html index 7012527..1df10b0 100644 --- a/templates/add_instrument.html +++ b/templates/add_instrument.html @@ -27,8 +27,8 @@ /

Add

-
-
+
+ - - - - - - - - - + +
+ + + + + + + + + + + +
+ +
{{panel|safe}}
-
{{panel|safe}}
diff --git a/templates/patch.html b/templates/patch.html index 77621ed..c7af26a 100644 --- a/templates/patch.html +++ b/templates/patch.html @@ -118,6 +118,19 @@ {% endfor %} + +
+{{patch['name']}}
+
+{{patch['description']}}
+
+A patch for {{instrument['name']}}
+
+{% for param in params %}{{param['param_name']}}: {{param['value']}} 
{% endfor %} + +{% for socket in sockets %}{{socket['socket_name']}} -> {{socket['value']}}
{% endfor %} +
+
@@ -127,5 +140,8 @@ {% endfor %} > + + + diff --git a/workbook.py b/workbook.py index 28b6c59..a636a61 100644 --- a/workbook.py +++ b/workbook.py @@ -61,7 +61,7 @@ def create_instrument(name, description, params, sockets, panel): "INSERT OR IGNORE INTO params (param_name) VALUES (?)",(param,) ) cur.execute( - "INSERT INTO instrument_param (instrument_id, param_name) VALUES (?, ?)", (instrument_id, param ) + "INSERT INTO instrument_param (instrument, param_name) VALUES (?, ?)", (slug, param ) ) for socket in sockets: @@ -70,7 +70,7 @@ def create_instrument(name, description, params, sockets, panel): ) cur.execute( - "INSERT INTO instrument_socket (instrument_id, socket_name) VALUES (?, ?)", (instrument_id, socket ) + "INSERT INTO instrument_socket (instrument, socket_name) VALUES (?, ?)", (slug, socket ) ) connection.commit() @@ -147,33 +147,45 @@ def add_patch(instrument): patch_id = cursor.lastrowid - patch.pop('name','') - patch.pop('slug','') - patch.pop('description','') - patch.pop('cables','') - - for param, value in patch.items(): - cursor.execute('INSERT INTO patch_param (patch_id, param_name, value) VALUES (?,?,?)', - (patch_id, param, value)) - + instrument_params = cursor.execute('SELECT param_name FROM instrument_param WHERE instrument = ?', (instrument,)).fetchall() + instrument_sockets = cursor.execute('SELECT socket_name FROM instrument_socket WHERE instrument = ?', (instrument,)).fetchall() + + instrument_params = [row[0] for row in instrument_params] + instrument_sockets = [row[0] for row in instrument_sockets] + + for key, value in patch.items(): + destination = None + if key in instrument_params: + destination = 'param' + elif key in instrument_sockets: + destination = 'socket' + + if destination is not None: + print(f'Insert {key} into {destination}') + cursor.execute(f'INSERT INTO patch_{destination} (patch_id, {destination}_name, value) VALUES (?,?,?)', + (patch_id, key, value)) + connection.commit() connection.close() return redirect(url_for('patches', instrument=instrument)) + + + + with open(f'static/panels/{instrument}.svg', 'r') as f: panel = f.read() instrument = cursor.execute('SELECT * FROM instruments WHERE slug = ?', (instrument,)).fetchone() + connection.close() return render_template('add_patch.html', instrument=instrument, panel = panel) @app.route("/instruments//", methods=['GET', 'POST']) def patch(instrument, name): - - if request.method == 'POST': @@ -203,13 +215,16 @@ def patch(instrument, name): snippets = cursor.execute('SELECT * FROM snippets WHERE instrument = ? AND patch_name = ?', (instrument, name)).fetchall() - + patch = cursor.execute('SELECT * FROM patches WHERE instrument = ? AND slug = ?', (instrument, name)).fetchone() params = cursor.execute('SELECT * FROM patch_param WHERE patch_id = ?', (patch['id'],)).fetchall() + sockets = cursor.execute('SELECT * FROM patch_socket WHERE patch_id = ?', + (patch['id'],)).fetchall() + instrument = cursor.execute('SELECT * FROM instruments WHERE slug = ?', (instrument,)).fetchone() @@ -218,7 +233,7 @@ def patch(instrument, name): connection.close() - return render_template('patch.html', instrument=instrument, patch=patch, params=params, panel=panel, snippets=snippets) + return render_template('patch.html', instrument=instrument, patch=patch, params=params, sockets=sockets, panel=panel, snippets=snippets)