dmt

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

http_listener.py (1528B)


      1 #!/usr/bin/env python3
      2 # See LICENSE file for copyright and license details.
      3 """
      4 HTTP API handler for the Caller Station
      5 """
      6 
      7 #from subprocess import Popen
      8 from flask import Flask
      9 import mido
     10 
     11 from config import (cardno, mic_cap, mic_play, device_name)
     12 
     13 APP = Flask(__name__)
     14 
     15 
     16 @APP.route('/')
     17 def main():
     18     """
     19     Main routine (noop)
     20     """
     21     return '\n'
     22 
     23 
     24 @APP.route('/callanswered')
     25 def callanswered():
     26     """
     27     Handler for the answered phone call.
     28     """
     29     print('Call answered')
     30 
     31     #Popen(['amixer', '-c', cardno, 'cset', mic_play, '100'])
     32     #Popen(['amixer', '-c', cardno, 'cset', mic_cap, '0'])
     33 
     34     msgdict = {
     35         'type': 'note_on',
     36         'time': 0,
     37         'note': 61,
     38         'velocity': 127,
     39         'channel': 0,
     40     }
     41     msg = mido.Message.from_dict(msgdict)
     42     with mido.open_output(device_name) as midi_out:
     43         midi_out.send(msg)
     44 
     45     return 'Call answered\n'
     46 
     47 
     48 @APP.route('/callended')
     49 def callended():
     50     """
     51     Handler for the ended phone call.
     52     """
     53     print('Call ended')
     54 
     55     #Popen(['amixer', '-c', cardno, 'cset', mic_play, '0'])
     56     #Popen(['amixer', '-c', cardno, 'cset', mic_cap, '100'])
     57 
     58     msgdict = {
     59         'type': 'note_on',
     60         'time': 0,
     61         'note': 62,
     62         'velocity': 127,
     63         'channel': 0,
     64     }
     65     msg = mido.Message.from_dict(msgdict)
     66     with mido.open_output(device_name) as midi_out:
     67         midi_out.send(msg)
     68 
     69     return 'Call ended\n'
     70 
     71 
     72 if __name__ == '__main__':
     73     APP.run(host='0.0.0.0', port=8000, threaded=True, debug=True)