From 9a9e7d15d91bc9f7325b4709ce3d041331713f10 Mon Sep 17 00:00:00 2001 From: next2w Date: Mon, 3 Oct 2022 19:44:50 -0400 Subject: Fix a crap ton of bugs --- backend/app.py | 41 +++++++++++++++-------------------------- src/App.js | 2 +- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/backend/app.py b/backend/app.py index 97f9491..b0c6ade 100644 --- a/backend/app.py +++ b/backend/app.py @@ -6,42 +6,31 @@ import subprocess app = Flask(__name__) -threadFlag = True -def playFunction(freq): - global threadFlag - p = subprocess.Popen(["beep", "-f", freq, "-l", "100000"]) - while not threadFlag: - pass - #print("beep -f %f" % (freq)) - os.kill(p.pid, 15) - -thread2 = 0 +curf = 0 +p = 0 + tc = 0 @app.before_first_request def activate_job(): global tc tc = 0 -@app.route('/startfreq/') -def freq(freq): - global threadFlag - global thread2 - threadFlag = False - print(freq) - thread2 = Thread(target=playFunction, args=(freq,)) - thread2.start() +@app.route('/startfreq/') +def startfreq(f): + global curf + global p + print(f) + curf = f + p = subprocess.Popen(["beep", "-f", f, "-l", "100000"]).pid return("200") -@app.route('/stopfreq/') -def freq2(freq2): - global threadFlag - global thread2 - threadFlag = True +@app.route('/stopfreq/') +def stopfreq(f): + print(f, curf) + if f == curf: + os.kill(p, 15) return("200") if __name__ == "__main__": app.run(debug=True, host='0.0.0.0') - - - diff --git a/src/App.js b/src/App.js index 8190cb1..7cf9d75 100644 --- a/src/App.js +++ b/src/App.js @@ -5,7 +5,7 @@ import 'react-piano/dist/styles.css'; function App() { - const firstNote = MidiNumbers.fromNote('c3'); + const firstNote = MidiNumbers.fromNote('a2'); const lastNote = MidiNumbers.fromNote('f5'); const keyboardShortcuts = KeyboardShortcuts.create({ firstNote: firstNote, -- cgit v1.2.3-70-g09d2