#!/usr/bin/perl # Rock Band Drum Controller Player # Copyright (C) 2008 Timm Murray # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # use strict; use warnings; use Linux::Input; use IO::Select; use SDL; use SDL::Sound; use SDL::Mixer; use constant DEBUG => 0; my $DEV = shift; die "Need a device\n" unless $DEV; my %SOUNDS = ( snare => 'rock_band_drums/snare.wav', drum => 'rock_band_drums/drum.wav', hi_hat => 'rock_band_drums/hi_hat.wav', smash => 'rock_band_drums/crash.wav', bass => 'rock_band_drums/bass.wav', ); my %EVENTS = ( 308 => $SOUNDS{bass}, # Foot 306 => $SOUNDS{snare}, # Red 307 => $SOUNDS{hi_hat}, # Yellow 304 => $SOUNDS{drum}, # Blue 305 => $SOUNDS{smash}, # Green ); { my $ret = SDL::MixOpenAudio( 44100, AUDIO_S16, 2, 4096 ); die "Can't open audio: " . SDL_GetError() . "\n" if 0 > $ret; } sub debug { my (@in) = @_; return unless DEBUG; print @in, "\n"; } sub do_event { my ($event) = @_; my $code = $$event{code}; my $value = $$event{value}; debug( "Code [$code], value [$value]" ); return 0 if ! exists $EVENTS{$code}; return 0 if $value == 0; my $file = $EVENTS{$code}; my $sound = SDL::MixLoadWAV( $file ); SDL::MixPlayChannel( -1, $sound, 0 ); return 1; } { my $js1 = Linux::Input->new( $DEV ); my $selector = IO::Select->new; $selector->add( $js1->fh ); while( my $fh = $selector->can_read ) { my @events = $js1->poll; foreach (@events) { next unless $$_{type} == 1; do_event( $_ ); } } }