Carl Burks is a software developer for a global financial institution. With over ten years experience in technology and software development for financial organizations and over twenty years of software experience, Carl Burks provides articles, musings and insight into technology issues, software development, and other selected topics.

Music

2014-01-07T19:12:00.000-08:00

Authors:
Carl Burks

Current script for starting Music

#!/bin/bash
echo "Spawning jackd -d alsa"
jackd -d alsa &
echo "Waiting For Jack to Wake Up...."
sleep 3
echo "Spawning a2jmidid -e"
a2jmidid -e &
sleep 3
echo "Spawning qjacktl"
qjackctl &
echo "Spawning qsynth"
qsynth &
echo "Finished"

Current script for Starting Midi listener

#!/usr/sbin/python2.7
from bottle import run, route, request
import alsaseq     
from time import sleep

alsaseq.client('WebMIDI', 1,1, False)#http://127.0.0.1/midi?note=60&duration=100
alsaseq.connectfrom(0,129,0)
IP = "127.0.0.1"
VOICE = 127
PLAYBACK_RATE = .5

notes = []

def save_note(note, duration, channel):
    notes.append({"note":note,"duration":duration,"channel":channel})

def play_note(note, duration, channel):   
    alsaseq.output( (6, 1, 0, 1, (5, 0), (0, 0), (0, 0), (channel,
int(note), 127, 0, int(duration))) )

def playback():
    for note in notes:
        sleep(PLAYBACK_RATE)
        play_note(note["note"],note["duration"],note["channel"])

@route('/midiclear',method="GET")
def midiclear():
    notes[:] = []

@route('/midiplayback',method="GET")
def midiplayback():
    playback()

@route('/midi',method="GET")
def midi():
        note = int(request.query['note'])
        duration = int(request.query['duration'])
        channel = int(request.query['channel'])
        save_note(note, duration, channel)
        play_note(note, duration, channel)
        return {"data":{"note":note,"duration":duration,"status":alsaseq.status()}}

run(host=IP, port=8080)


Current html page:


   
   
   
   
   
   



       

       

C


       


       

       

C#


       
   

       

       

D


       
   

       

       

D#


       
   

       

       

E


       
   

       

       

F


       
   

       

       

F#


       
   

       

       

G


       
   

       

       

G#


       
   

       

       

A


       
   

       

       

A#


       
   

       

       

B


       
   

       

Playback


       

Clear


       

0


       

+


       

-






Current Javascript:
(function(){
    var ip = "127.0.0.1:8080", channel = 0, channel_label;
    function update_channel(){
        channel_label.text(channel);
    }
    function up_channel(){
        if(channel<120){
            channel += 1;
            update_channel();
        }
    }
    function down_channel(){
        if(channel>0){
            channel -= 1;
            update_channel();
        }
    }
    function play_note(note){
        $.get("http://"+ip+"/midi?note="+note+"&duration=100&channel="+channel, function(){});   
    }
    $(document).ready(function(){
        var offset = 12,i = 0, notes =[
            "c",
            "cs",
            "d",
            "ds",
            "e",
            "f",
            "fs",
            "g",
            "gs",
            "a",
            "as",
            "b"
        ];
        channel_label = $("#channel_label");
        $("#playback").click(function(){
            $.get("http://"+ip+"/midiplayback",function(){});
        });
        $("#clear").click(function(){
            $.get("http://"+ip+"/midiclear",function(){});
        });
        $("#channel_up").click(function(){ up_channel();        });
        $("#channel_down").click(function(){ down_channel();        });
       
        $(notes).each(function(ni){
            var item = 60+i, note = notes[ni];
            i+=1;
            $("#"+note+"3").click(function(){
                play_note(item-offset);
            });
            $("#"+note+"4").click(function(){
                play_note(item);
            });
            $("#"+note+"5").click(function(){
                play_note(item+offset);
            });
        });
    });
}());

Screen shot: