dmt

source code for the kunsthal art installation
git clone git://parazyd.org/dmt.git
Log | Files | Refs | README | LICENSE

commit 848e7e15d53d5f30af32d6b8e7ab2714b391457f
parent 4a7c61ed2f03b0dde6117af7ef9f0d7e77e0fc99
Author: parazyd <parazyd@dyne.org>
Date:   Wed, 29 Nov 2017 10:52:29 +0100

update http-listener with latest changes

Diffstat:
Mhttp-api/README.md | 2+-
Mhttp-api/config.py | 14++++++++++++--
Mhttp-api/http_listener.py | 35+++++++++++++++++++++++++++++------
3 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/http-api/README.md b/http-api/README.md @@ -16,7 +16,7 @@ Dependencies ------------ ``` -python3-flask +python3-flask python3-mido python3-rtmidi ``` diff --git a/http-api/config.py b/http-api/config.py @@ -11,7 +11,17 @@ HTTP API handler configuration cardno = '1' # Mic capture line (for amixer) -mic_cap = "numid=4,iface=MIXER,name='Mic Playback Volume'" +#mic_cap = "numid=4,iface=MIXER,name='Mic Playback Volume'" # chinese card +#mic_cap = "numid=4,iface=MIXER,name='Mic Playback Volume'" # sennheiser card +mic_cap = "numid=6,iface=MIXER,name='Capture Volume'" # thinkpad x201 # Mic playback line (for amixer) -mic_play = "numid=8,iface=MIXER,name='Mic Capture Volume'" +#mic_play = "numid=8,iface=MIXER,name='Mic Capture Volume'" # chinese card +#mic_play = "numid=12,iface=MIXER,name='Mic Capture Volume'" # sennheiser card +mic_play = "numid=6,iface=MIXER,name='Capture Volume'" # thinkpad x201 + +# The device we want to use for MIDI. Found using: mido.get_input_names() +#device_name = 'USB MS1x1 MIDI Interface:USB MS1x1 MIDI Interface MIDI 1 24:0' + +import mido +device_name = mido.get_input_names()[1] diff --git a/http-api/http_listener.py b/http-api/http_listener.py @@ -4,10 +4,11 @@ HTTP API handler for the Caller Station """ -from subprocess import Popen +#from subprocess import Popen from flask import Flask +import mido -from config import (cardno, mic_cap, mic_play) +from config import (cardno, mic_cap, mic_play, device_name) APP = Flask(__name__) @@ -27,8 +28,19 @@ def callanswered(): """ print('Call answered') - Popen(['amixer', '-c', cardno, 'cset', mic_play, '100']) - Popen(['amixer', '-c', cardno, 'cset', mic_cap, '0']) + #Popen(['amixer', '-c', cardno, 'cset', mic_play, '100']) + #Popen(['amixer', '-c', cardno, 'cset', mic_cap, '0']) + + msgdict = { + 'type': 'note_on', + 'time': 0, + 'note': 61, + 'velocity': 127, + 'channel': 0, + } + msg = mido.Message.from_dict(msgdict) + with mido.open_output(device_name) as midi_out: + midi_out.send(msg) return 'Call answered\n' @@ -40,8 +52,19 @@ def callended(): """ print('Call ended') - Popen(['amixer', '-c', cardno, 'cset', mic_play, '0']) - Popen(['amixer', '-c', cardno, 'cset', mic_cap, '100']) + #Popen(['amixer', '-c', cardno, 'cset', mic_play, '0']) + #Popen(['amixer', '-c', cardno, 'cset', mic_cap, '100']) + + msgdict = { + 'type': 'note_on', + 'time': 0, + 'note': 62, + 'velocity': 127, + 'channel': 0, + } + msg = mido.Message.from_dict(msgdict) + with mido.open_output(device_name) as midi_out: + midi_out.send(msg) return 'Call ended\n'