You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.6 KiB
Python

2 years ago
from flask import Flask, render_template, request, redirect, url_for
from werkzeug.utils import secure_filename
import yaml
from yaml.loader import SafeLoader
import os
2 years ago
app = Flask(__name__)
2 years ago
def create_instrument(name, description, params, panel):
slug = secure_filename(name)
os.mkdir(f'instruments/{slug}')
os.mkdir(f'instruments/{slug}/patches')
os.mkdir(f'instruments/{slug}/samples')
instrument = {
"name": name,
"slug": slug,
"description": description,
"params": params
}
with open(f'instruments/{slug}/model.yml', 'w') as f:
yaml.dump(instrument, f)
panel.save(f'instruments/{slug}/panel.svg')
2 years ago
@app.route("/")
def home():
return render_template('home.html')
@app.route("/workbook")
def workbook():
2 years ago
instruments = []
for filename in os.listdir('instruments'):
with open(f'instruments/{filename}/model.yml') as f:
instrument = yaml.load(f, Loader=SafeLoader)
instruments.append(instrument)
return render_template('workbook.html', instruments=instruments)
2 years ago
@app.route("/workbook/<instrument>")
def patches(instrument):
2 years ago
patches = []
for filename in os.listdir(f'instruments/{instrument}/patches'):
with open(f'instruments/{instrument}/patches/{filename}') as f:
patch = yaml.load(f, Loader=SafeLoader)
patches.append(patch)
return render_template('patches.html', instrument=instrument, patches=patches)
@app.route("/workbook/add", methods=['GET', 'POST'])
def add_instrument():
if request.method == 'POST':
name = request.form.get('name')
description = request.form.get('description')
params = request.form.get('params').split(',')
panel = request.files['panel']
create_instrument(name, description, params, panel)
return redirect(url_for('workbook'))
return render_template('add_instrument.html')
@app.route("/workbook/<instrument>/add", methods=['GET', 'POST'])
def add_patch(instrument):
if request.method == 'POST':
patch = request.form.to_dict()
with open(f'instruments/{instrument}/patches/{secure_filename(patch["name"])}.yml', 'w') as f:
yaml.dump(patch, f)
return redirect(url_for('patches', instrument=instrument))
with open(f'instruments/{instrument}/model.yml') as f:
instrument = yaml.load(f, Loader=SafeLoader)
return render_template('add_patch.html', instrument=instrument)
2 years ago
2 years ago
@app.route("/workbook/<instrument>/<name>")
def patch(instrument, name):
return render_template('patch.html', instrument=instrument, name=name)
2 years ago
app.run(port=3000, debug=True)