Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

qwerty-keyboard realtime midi

by zentara (Archbishop)
on Jun 21, 2004 at 17:15 UTC ( #368509=snippet: print w/replies, xml ) Need Help??
Description: Getting bored in the office? A few of your officemates can drive the boss crazy by starting your own "cubicle rock band". This is an simple script, to help waste "many many man-hours". :-) It probably works on linux only. Windows users already waste enough time. :-)

Press a key and a midi note is sounded. My favorite is "r".

#!/usr/bin/perl
use warnings;
use strict;
use MIDI::Realtime;
use Term::ReadKey;

ReadMode('cbreak');

#this works on linux with an SBlive, Alsa 1.0.4, kernel 2.4.22 
# on my system, it has a bug when usb-hotplug and usb-midi are used 
my $midi = MIDI::Realtime->new(dev=>'/dev/sequencer',
                               midi_device=> 1); #1,2,3,4 

while(1){
my $char;
if (defined ($char = ReadKey(0)) ) {
        print ord($char),"\n";    # input was waiting and it was $char
+ 

        $midi->patch(ord($char)); 
#change instrument, 127 gives "exploding keyboard" :-) 

        $midi->note(50,1,127); #play note 

} else {
          # no input was waiting 
        }
}


ReadMode('normal');                  # restore normal tty settings 

__END__ 

Replies are listed 'Best First'.
Re: qwerty-keyboard realtime midi
by Juerd (Abbot) on Jun 21, 2004 at 20:53 UTC

    How exactly is this QWERTY related? As far as I can tell, it works with QWERTZ, AZERTY, Dvorak, etcetera too.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

      Yes, I guess qwerty was a bad choice of words, but I asked my self what was the shortest way I could convey the concept of the console keyboard so it would fit in the title. Qwerty popped into mind, and I went with it over "console".

      I'm not really a human, but I play one on earth. flash japh
      I would assume he meant text keyboard as opposed to a synthesizer keyboard, a pour choice of qualifiers, but it made instant sense to me.

        I would assume he meant text keyboard as opposed to a synthesizer keyboard, a pour choice of qualifiers

        It is like saying "English" when you mean "a human language". A poor choice indeed.

        Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://368509]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2019-09-17 10:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (206 votes). Check out past polls.

    Notices?