database params and sockets

db
km0 2 years ago
parent 5d9c36ba5d
commit 898436252a

@ -5,6 +5,7 @@ DROP TABLE IF EXISTS instrument_param;
DROP TABLE IF EXISTS instrument_socket; DROP TABLE IF EXISTS instrument_socket;
DROP TABLE IF EXISTS patches; DROP TABLE IF EXISTS patches;
DROP TABLE IF EXISTS patch_param; DROP TABLE IF EXISTS patch_param;
DROP TABLE IF EXISTS patch_socket;
DROP TABLE IF EXISTS snippets; DROP TABLE IF EXISTS snippets;
CREATE TABLE instruments ( CREATE TABLE instruments (
@ -25,15 +26,17 @@ CREATE TABLE sockets (
); );
CREATE TABLE instrument_param ( CREATE TABLE instrument_param (
instrument_id INTEGER NOT NULL, instrument TEXT NOT NULL,
param_name 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 ( CREATE TABLE instrument_socket (
instrument_id INTEGER NOT NULL, instrument TEXT NOT NULL,
socket_name 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 ( CREATE TABLE patches (
@ -54,6 +57,13 @@ CREATE TABLE patch_param (
PRIMARY KEY (patch_id, param_name) 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 ( CREATE TABLE snippets (
filename TEXT NOT NULL, filename TEXT NOT NULL,
instrument TEXT NOT NULL, instrument TEXT NOT NULL,

@ -1,4 +1,4 @@
main { .grid {
display: grid; display: grid;
grid-template-columns: 1fr 1fr 1fr; grid-template-columns: 1fr 1fr 1fr;
gap: 16px; gap: 16px;
@ -17,7 +17,7 @@ textarea {
font-family: sans-serif; font-family: sans-serif;
} }
form > * + * { .meta > * + * {
margin-top: 16px; margin-top: 16px;
} }
@ -37,6 +37,10 @@ input[type="submit"]:hover {
border: 1px solid currentColor; border: 1px solid currentColor;
} }
.meta {
grid-column: 1 / span 1;
}
.preview { .preview {
position: absolute; position: absolute;
top: 8px; top: 8px;

@ -82,7 +82,7 @@ main {
.meta { .meta {
display: inline-block; display: inline-block;
border: 2px solid currentColor; border: 1px solid currentColor;
padding: 16px; padding: 16px;
margin: 32px 0; margin: 32px 0;
max-width: 40ch; max-width: 40ch;
@ -91,4 +91,14 @@ main {
.meta .date { .meta .date {
margin-top: 8px; margin-top: 8px;
opacity: 0.5; opacity: 0.5;
} }
.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;
}

@ -287,6 +287,14 @@ class Panel {
if (socket && socket.classList.contains("socket")) { if (socket && socket.classList.contains("socket")) {
this.cable.end = socket.getAttribute("name"); 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 // TODO: log cable
} else { } else {
this.cable.path.remove(); this.cable.path.remove();

@ -27,8 +27,8 @@
<span class="path-slash"> / </span> <span class="path-slash"> / </span>
<h2 class="title">Add</h2> <h2 class="title">Add</h2>
</header> </header>
<main> <main class="grid">
<form method="POST" enctype="multipart/form-data"> <form class="meta" method="POST" enctype="multipart/form-data">
<input type="text" name="name" placeholder="1. Name" /> <input type="text" name="name" placeholder="1. Name" />
<textarea <textarea
name="description" name="description"

@ -31,29 +31,32 @@
{{instrument['name']}} {{instrument['name']}}
</a> </a>
<span class="path-slash"> / </span> <span class="path-slash"> / </span>
<h2 class="title">Add</h2> <h2 class="title">Add Patch</h2>
</header> </header>
<main> <main>
<form method="POST" enctype="multipart/form-data"> <form class="grid" method="POST" enctype="multipart/form-data">
<input type="text" name="name" placeholder="Name" /> <div class="meta">
<textarea <input type="text" name="name" placeholder="Name" />
name="description" <textarea
cols="30" name="description"
rows="10" cols="30"
placeholder="description" rows="10"
></textarea> placeholder="description"
<input type="date" name="date" /> ></textarea>
<input type="date" name="date" />
<input type="hidden" name="cables" />
<input type="hidden" name="cables" />
<input type="text" name="input" placeholder="Input" />
<input type="text" name="output" placeholder="Output" /> <input type="text" name="input" placeholder="Input" />
<input type="text" name="routing" placeholder="Routing" /> <input type="text" name="output" placeholder="Output" />
<input type="text" name="routing" placeholder="Routing" />
<input type="submit" value="Add" />
<input type="submit" value="Add" />
</div>
<div id="panel-container">{{panel|safe}}</div>
</form> </form>
<div id="panel-container">{{panel|safe}}</div>
</main> </main>
</body> </body>
</html> </html>

@ -118,6 +118,19 @@
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>
<pre class="patch-text">
{{patch['name']}}
{{patch['description']}}
A patch for {{instrument['name']}}
{% for param in params %}{{param['param_name']}}: {{param['value']}} <br>{% endfor %}
{% for socket in sockets %}{{socket['socket_name']}} -> {{socket['value']}}<br>{% endfor %}
</pre>
</main> </main>
@ -127,5 +140,8 @@
{% endfor %} {% endfor %}
></div> ></div>
</body> </body>
</html> </html>

@ -61,7 +61,7 @@ def create_instrument(name, description, params, sockets, panel):
"INSERT OR IGNORE INTO params (param_name) VALUES (?)",(param,) "INSERT OR IGNORE INTO params (param_name) VALUES (?)",(param,)
) )
cur.execute( 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: for socket in sockets:
@ -70,7 +70,7 @@ def create_instrument(name, description, params, sockets, panel):
) )
cur.execute( 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() connection.commit()
@ -147,33 +147,45 @@ def add_patch(instrument):
patch_id = cursor.lastrowid patch_id = cursor.lastrowid
patch.pop('name','') instrument_params = cursor.execute('SELECT param_name FROM instrument_param WHERE instrument = ?', (instrument,)).fetchall()
patch.pop('slug','') instrument_sockets = cursor.execute('SELECT socket_name FROM instrument_socket WHERE instrument = ?', (instrument,)).fetchall()
patch.pop('description','')
patch.pop('cables','') instrument_params = [row[0] for row in instrument_params]
instrument_sockets = [row[0] for row in instrument_sockets]
for param, value in patch.items():
cursor.execute('INSERT INTO patch_param (patch_id, param_name, value) VALUES (?,?,?)', for key, value in patch.items():
(patch_id, param, value)) 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.commit()
connection.close() connection.close()
return redirect(url_for('patches', instrument=instrument)) return redirect(url_for('patches', instrument=instrument))
with open(f'static/panels/{instrument}.svg', 'r') as f: with open(f'static/panels/{instrument}.svg', 'r') as f:
panel = f.read() panel = f.read()
instrument = cursor.execute('SELECT * FROM instruments WHERE slug = ?', (instrument,)).fetchone() instrument = cursor.execute('SELECT * FROM instruments WHERE slug = ?', (instrument,)).fetchone()
connection.close() connection.close()
return render_template('add_patch.html', instrument=instrument, panel = panel) return render_template('add_patch.html', instrument=instrument, panel = panel)
@app.route("/instruments/<instrument>/<name>", methods=['GET', 'POST']) @app.route("/instruments/<instrument>/<name>", methods=['GET', 'POST'])
def patch(instrument, name): def patch(instrument, name):
if request.method == 'POST': if request.method == 'POST':
@ -203,13 +215,16 @@ def patch(instrument, name):
snippets = cursor.execute('SELECT * FROM snippets WHERE instrument = ? AND patch_name = ?', snippets = cursor.execute('SELECT * FROM snippets WHERE instrument = ? AND patch_name = ?',
(instrument, name)).fetchall() (instrument, name)).fetchall()
patch = cursor.execute('SELECT * FROM patches WHERE instrument = ? AND slug = ?', patch = cursor.execute('SELECT * FROM patches WHERE instrument = ? AND slug = ?',
(instrument, name)).fetchone() (instrument, name)).fetchone()
params = cursor.execute('SELECT * FROM patch_param WHERE patch_id = ?', params = cursor.execute('SELECT * FROM patch_param WHERE patch_id = ?',
(patch['id'],)).fetchall() (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 = cursor.execute('SELECT * FROM instruments WHERE slug = ?',
(instrument,)).fetchone() (instrument,)).fetchone()
@ -218,7 +233,7 @@ def patch(instrument, name):
connection.close() 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)

Loading…
Cancel
Save