#########################################################
# A generic Jam-O-Drum class to interface with the drum pads
#This files is specific to those people who don't have access to the jamodrum
#these files are replaced with better files on the actual drum
#
#DO NOT MAKE CHANGES TO THIS FILE- YOU WON'T GET THEM ON THE DRUM
#
# Author Jen Smith (jsmith2)
# Last Updated Aug 11, 2004
#########################################################

from globals import * #these are our global definey thigns
from direct.showbase import DirectObject

#this is the midi signal we get
PAD_2 = 60
PAD_3 = 65
PAD_0 = 64
PAD_1 = 62


#python doesn't make anythign private- so be nice and use the functions
#instead of accessing data directly
class DrumPads(DirectObject.DirectObject):

    #****************************************************************************
    #Constructor for a Drumpads object
    #****************************************************************************/
    def __init__( self ):
        self.midi=None
        self.mIsLoaded=False
        
    #****************************************************************************
    #Initialize the drum pads.
    #@param pDeviceID id of MIDI device controlling drum pads.
    #@return true on success, false on failure
    #@todo figure out how to print error messages
    #****************************************************************************/
    def Start(self): 
        #cheap jamodrum emulator
        self.accept('k', self.Handler, [PAD_0, 1])
        self.accept('d', self.Handler, [PAD_1, 1])
        self.accept('e', self.Handler, [PAD_2, 1])
        self.accept('i', self.Handler, [PAD_3, 1]) 
        self.mIsLoaded = True
           
    #****************************************************************************
    #Clear out drumpad data
    #@todo add error messages and such
    #***************************************************************************/     
    def Clear(self):
        for p in self.mDrumPads:
            p=PAD_NOHIT

    #****************************************************************************/    
    #See if drumpads were loaded successfully- that is, if the midi device was found were found.
    #@return True is joysticks have been loaded
    #****************************************************************************/  
    def isLoaded(self):
        return self.mIsLoaded
    
    #****************************************************************************
    #Retrieve state of requested Drumpad.
    #@param pPad requested pad.
    #@return state of pPad.
    #****************************************************************************/
    def GetPadState(self,pPad):
        return self.mDrumPads[pPad]

    def Poll(self):
        if self.mIsLoaded:
             return #this does nothign in this file, since everythign is key presses
        
    #****************************************************************************
    #Handle drumpad hits
    #@param pPad pad whose state we are updating
    #@param pValue velocity passed pad was hit at
    #****************************************************************************/
    def Handler(self, pPad, pValue): 
        station=-1
        if pPad == PAD_0:
            station=STATION_0
        elif pPad == PAD_1:
            station=STATION_1
        elif pPad == PAD_2:
            station=STATION_2
        elif pPad == PAD_3:
            station=STATION_3
        print "station ", station," hit:", pValue 
        s="HIT_"+str(station)
        messenger.send(s) 
        










