Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
5969f29
Added websocket handler and its bad integration
sefimochkin Apr 29, 2018
ee6b07d
Updated the files from production, rewrote input and output correctly.
sefimochkin Apr 29, 2018
301d842
Merge remote-tracking branch 'remotes/origin/master' into web_tornado…
sefimochkin May 1, 2018
9884c41
Cleaned up imports and merged with master
sefimochkin May 1, 2018
fb8c42c
Added tornado server application, cleaned up code for travis
sefimochkin May 1, 2018
ff750cf
More cleaning up code for travis
sefimochkin May 1, 2018
c17c0a5
Even MORE cleaning up for travis
sefimochkin May 1, 2018
e118f3a
add prediction for deadline, but now queue is not empty
AnnaKlimchuk May 3, 2018
170708a
Moving average downbeats
sefimochkin May 5, 2018
7680b1c
Setting up Sasha's recordings and few fixes
sefimochkin May 7, 2018
d9ab5f3
Cleaning up for Travis
sefimochkin May 7, 2018
d8f7c4e
Small fix and travis clean-up
sefimochkin May 7, 2018
c23f93f
Merge remote-tracking branch 'remotes/origin/master' into web_tornado…
sefimochkin May 8, 2018
3f6e63e
Changes for server
sefimochkin May 8, 2018
feb4686
Working streaming!
sefimochkin May 8, 2018
2eedc5b
Working input streaming!
sefimochkin May 8, 2018
d6d3b09
Working input streaming!
sefimochkin May 8, 2018
e50dac3
Added all site stuff
sefimochkin May 8, 2018
7fbd961
Added all site stuff
sefimochkin May 8, 2018
c041c81
Working output streaming! But bugged.
sefimochkin May 12, 2018
2fb9b23
Working output streaming! Bugged!
sefimochkin May 12, 2018
c284b9c
model
shirlyuba May 14, 2018
53e1a43
model
shirlyuba May 14, 2018
ce1cabd
Merge remote-tracking branch 'origin/ACCOMPANIST-143_NN_out_dataset' …
shirlyuba May 14, 2018
f8c5152
change size of chords, add vocabulary of chords
shirlyuba May 14, 2018
731f741
Fixed output streaming, but seams are still easy to hear
sefimochkin May 14, 2018
b2b1a89
Added backwards compatibility. Now Accompanist can be run in two mode…
sefimochkin May 14, 2018
87e4633
Added backwards compatibility. Now Accompanist can be run in two mode…
sefimochkin May 14, 2018
a6922ac
Added measuring of web delay
sefimochkin May 14, 2018
93c23d4
Added measuring of web delay
sefimochkin May 15, 2018
4cd0c68
Added measuring of web delay
sefimochkin May 15, 2018
65bdb58
Updated requirements and moved soundfont
sefimochkin May 15, 2018
f87a99a
Moving soundfont
sefimochkin May 15, 2018
2946a36
fixes for travis
sefimochkin May 15, 2018
e6b5ac5
updated version
shirlyuba May 15, 2018
afa05a6
version with empty chord
shirlyuba May 15, 2018
0a4cbc4
updated vocabulary
shirlyuba May 15, 2018
416ad3e
last version
shirlyuba May 15, 2018
ccbbf3a
for Lyuba code
AnnaKlimchuk May 16, 2018
4c4d1b0
Merge branch 'ACCOMPANIST-141_WebAudioAPI' into web_tornado_server
sefimochkin May 17, 2018
7ac7383
Merge remote-tracking branch 'remotes/origin/ACCOMPANIST-141_WebAudio…
sefimochkin May 17, 2018
8e093f6
Merge with Sasha's branch
sefimochkin May 17, 2018
8366d62
Merge with downbeat
sefimochkin May 17, 2018
06601e5
pep fixes
sefimochkin May 17, 2018
706f1d6
pep fixes
sefimochkin May 17, 2018
c957993
latest version
shirlyuba May 18, 2018
30c3a45
Fixed for Docker
Wiki-fan May 19, 2018
1ca76bd
Merge remote-tracking branch 'remotes/origin/ACCOMPANIST-154_site_on_…
Wiki-fan May 19, 2018
3dbec8e
Fixed build
Wiki-fan May 19, 2018
06d8f57
Paths fixed
Wiki-fan May 19, 2018
0809ff8
updating model and vocab
AnnaKlimchuk May 20, 2018
3655ff3
Fix closing of processes
sefimochkin May 20, 2018
8e81aa8
Change name of process in listener
sefimochkin May 20, 2018
4e6eabc
Debug fixes
sefimochkin May 20, 2018
ef59ac1
few unique chords
shirlyuba May 20, 2018
b22f713
update models
nzinov May 21, 2018
57f875a
Merge branch 'ACCOMPANIST-143_NN_out_dataset' into ACCOMPANIST-146-pr…
nzinov May 21, 2018
a4de4fc
fix chord prediction
nzinov May 21, 2018
b98d056
counting accuracy
shirlyuba May 21, 2018
28cdf4b
Merge remote-tracking branch 'origin/ACCOMPANIST-146-prediction_for_d…
nzinov May 21, 2018
7c0685c
Merge remote-tracking branch 'origin/ACCOMPANIST-143_NN_out_dataset' …
nzinov May 21, 2018
8ea57b6
fix after merge
nzinov May 21, 2018
ccb91aa
Results page post form
Wiki-fan May 22, 2018
e5837b2
Fixed ws errors
MiptAlex179 May 22, 2018
b1e1a3d
removed .idea
MiptAlex179 May 22, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions accompaniator_web/base_app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@


class FeedbackForm(forms.ModelForm):
song_name = forms.CharField()
rating = forms.Select()
song_name = forms.CharField(widget=forms.HiddenInput(), required=False)
mark = forms.IntegerField(widget=forms.HiddenInput(), required=False, initial=-1)

class Meta:
model = Feedback
fields = ('song_name', 'rating',)
fields = ('song_name', 'mark',)
18 changes: 18 additions & 0 deletions accompaniator_web/base_app/migrations/0003_auto_20180522_0732.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0.2 on 2018-05-22 07:32

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('base_app', '0002_feedback_song_name'),
]

operations = [
migrations.RenameField(
model_name='feedback',
old_name='rating',
new_name='mark',
),
]
2 changes: 1 addition & 1 deletion accompaniator_web/base_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
class Feedback(models.Model):
song_name = models.CharField(max_length=32)
session_key = models.CharField(max_length=32)
rating = models.SmallIntegerField()
mark = models.SmallIntegerField()
3 changes: 2 additions & 1 deletion accompaniator_web/base_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ def results(request):

if request.method == 'POST':
form = FeedbackForm(request.POST, request.FILES)
print(form)
if form.is_valid():
instance = form.save(commit=False)
instance.session_key = session_key
instance.save()
return HttpResponseRedirect('/results')
return HttpResponseRedirect('/home')

else:
print(form.errors)
Expand Down
15 changes: 12 additions & 3 deletions accompaniator_web/static/js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var state = "init";
var delay = [];
var send_queve = [];
var text_ws;
var server_name = 'ws://demos.kaazing.com/echo';
var server_name = 'ws://localhost:8110/ws'; // 'ws://demos.kaazing.com/echo'; for testing
TextWS();

function startUserMedia(stream) {
Expand All @@ -40,9 +40,12 @@ function TextWS() {
text_ws.onmessage = function (ev) {
msg = ev.data;
console.log(msg)
if (typeof(msg) == "string") {
if (msg[0] != "R") {
text_ws.send(msg);
}
else{
Push(msg);
}
};
text_ws.onclose = function () {
TextWS();
Expand All @@ -51,6 +54,7 @@ function TextWS() {


function Push(blob) {
if (blob)
var url = URL.createObjectURL(blob);
var au = document.createElement('audio');

Expand Down Expand Up @@ -203,6 +207,7 @@ function Stop() {
state = 'record';
}, 1000);
ws.close();
text_ws.close();
}


Expand All @@ -213,7 +218,11 @@ function Recording() {
var s = ev.data;
_now = new Date().getTime();
//console.log("Delay is", _now - delay.pop(), "ms.");
Push(s);
if (s[0] == "R") {
Push(s);
}else{
text_ws.send(s);
}
};
queve = [];
frames = [];
Expand Down
2 changes: 1 addition & 1 deletion accompaniator_web/static/js/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ function star(num, star) {
for (var i = num + 1; i <= 5; i++) {
document.getElementById("star" + i).innerHTML = '<img src="../../static/img/star_dark.png" width="70px" height="70px">';
}
document.getElementById("mark").innerHTML = num;
document.getElementById("id_mark").value = num;
}
25 changes: 13 additions & 12 deletions accompaniator_web/templates/base_app/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,35 @@
<h1>Оцените нас</h1>
</div>
</div>
<div class="row">
<p><span id="mark" style="display: none">00:00</span></p>
</div>
<div class="row">


<div class="col-sm-6 col-sm-offset-2">
<ul class="myinline">
{% for i in stars_range %}
<ul class="myinline">
{% for i in stars_range %}
<li><a id="star{{ i }}" href="javascript:void(0);"
onclick="star({{ i }}, this)">
<img src="{% static 'img/star_dark.png' %}" width="70px" height="70px"></a></li>

{% endfor %}

</ul>
<br/>
<br/>
</div>
</div>

<div class="row">
<p><span id="mark1" style="display: none">00:00</span></p>
</div>
<div class="row">
<form action="{% url 'results' %}" id='post_results' method="post">
{% csrf_token %}
{{ feedback_form }}
<!-- <input type="hidden" id="mark" value="-1"/>-->
</form>
<div class="col-sm-1 col-sm-offset-4">
<a href="{% url 'home' %}">
<button type="button" class="btn btn-primary">По новой</button>
</a>

<button type="button" class="btn btn-primary"
onclick="document.getElementById('post_results').submit()">По новой
</button>

</div>
</div>

Expand Down
96 changes: 96 additions & 0 deletions accompaniator_web/tornado_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# import sys
# sys.path.append("../")
import numpy as np
import io
import scipy.io.wavfile

import tornado.websocket
from tornado import ioloop
from tornado.web import url

from production import accompanist
from multiprocessing import Queue, Process

from datetime import datetime
import time

buffer_size = 256
time_between_delay_measurings_in_secs = 1.5


def send_time_stamps(websocket):
while websocket.running is True:
now = datetime.now()
output = now.strftime("%Y-%m-%d %H:%M:%S")
try:
websocket.write_message(output, binary=False)
except tornado.iostream.StreamClosedError or tornado.websocket.WebSocketClosedError:
break
time.sleep(time_between_delay_measurings_in_secs)


class WebSocketHandler(tornado.websocket.WebSocketHandler):

def check_origin(self, origin):
return True

def initialize(self):
self.in_queue = Queue()
self.accompanist = None
self.last_sent_time_stamp = None
self.running = False

def open(self):
self.accompanist = accompanist.Accompanist()
self.accompanist.set_websocket(self)
self.accompanist.set_queue_in(self.in_queue)

self.accompanist.run()

self.running = True
self.time_send_process = Process(target=send_time_stamps, args=(self,))
self.time_send_process.start()

def on_message(self, message):
if 'RIFF' in str(message):
s = io.BytesIO(message)
_, samplesints = scipy.io.wavfile.read(s)
samples = samplesints.astype(np.float32, order='C') / 32768.0
for i in range(0, len(samples) // buffer_size - 1):
self.in_queue.put(samples[i * buffer_size:(i + 1) * buffer_size])

else: # it's a time string!
time_stamp = datetime.strptime(message, "%Y-%m-%d %H:%M:%S")
delay = (datetime.now() - time_stamp).total_seconds()
self.accompanist.set_web_delay(delay)

def on_close(self):
print("stopping")
self.running = False
self.time_send_process.join()
self.accompanist.stop()
print("stopped")

def send_audio(self, message):
print("delay ok!")
output = io.BytesIO()
scipy.io.wavfile.write(output, 44100, message)
try:
self.write_message(output.getvalue(), binary=True)
except tornado.iostream.StreamClosedError or tornado.websocket.WebSocketClosedError:
print("Caught this fucker")

def send_time(self):
pass


def main():
app = tornado.web.Application([url(r"/ws", WebSocketHandler)])
return app


if __name__ == "__main__":
app = main()
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(8110, address='0.0.0.0')
ioloop.IOLoop.instance().start()
1 change: 1 addition & 0 deletions docker/accompaniator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ ADD . /build/

RUN mv asound.conf /etc/asound.conf
RUN cat ./.bashrc >> ~/.bashrc
RUN mv piano_and_ultrasound.sf2 /piano_and_ultrasound.sf2
Binary file added docker/accompaniator/piano_and_ultrasound.sf2
Binary file not shown.
4 changes: 3 additions & 1 deletion docker/accompaniator/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ coverage
tqdm

# Web stuff
django
django
tornado
six
13 changes: 12 additions & 1 deletion docker/accompaniator/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ else
fi

cd accompaniator
git checkout ACCOMPANIST-154_site_on_django
git checkout web_tornado_server
cd accompaniator_web

# Start django
Expand All @@ -24,4 +24,15 @@ else
echo "Django ran successfully"
fi

# Start tornado
cd ..
nohup python -m accompaniator_web.tornado_server &
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start tornado: $status"
exit $status
else
echo "Tornado ran successfully"
fi

bash
5 changes: 3 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ services:
- /tmp/.X11-unix:/tmp/.X11-unix
- /run/dbus/:/run/dbus/:rw
- /dev/shm:/dev/shm
ports:
- 8000:8000

accompaniator-dev:
tty: true
image: accompaniator-dev
build: accompaniator-dev
devices:
Expand All @@ -25,6 +24,7 @@ services:
- /dev/shm:/dev/shm
- ./../:/build/accompaniator
ports:
- 8110:8110
- 8000:8000

accompaniator-prod:
Expand All @@ -37,6 +37,7 @@ services:
- /run/dbus/:/run/dbus/:rw
- /dev/shm:/dev/shm
ports:
- 8110:8110
- 8000:8000

accompaniator-test:
Expand Down
Binary file added ml/NN_model.h5
Binary file not shown.
Loading