Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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".

use warnings;
use strict;
use MIDI::Realtime;
use Term::ReadKey;


#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 

my $char;
if (defined ($char = ReadKey(0)) ) {
        print ord($char),"\n";    # input was waiting and it was $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 


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 => '', plp_site => '', 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.
      A reply falls below the community's threshold of quality. You may see it by logging in.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2020-02-19 18:58 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (84 votes). Check out past polls.