Example #1
0
def get_tracks(filename):
    if filename=="":
        filename = radium.getLoadFilename("Choose midi file", "*.mid *.MID *.midi *.MIDI")
    if not filename or filename=="":
        return False
    try:
        tracks = midi.read_midifile(filename)
    except:
        radium.showMessage("Could not read "+filename+". Either file doesn't exist, or it could not be read as a standard midi file.");
        return False
    
    return tracks
Example #2
0
def putCode(keyhandles,parser,codestring):
    keys=parser.getKeys()+parser.getQualifiers() 
    firstkey=keys.pop(0)
    #print "adding \"%s\", line: %d, firstkey: %d, keys: %s" % (codestring,parser.getCurrLineNum(),firstkey,keys)

    if keyhandles[firstkey].addHandle(keys,compile(codestring,'<string>','single'))==false:
        message = "Keybindings for command \"%s\" in line %d is already used" % (codestring , parser.getCurrLineNum())
        print message
        radium.showMessage(message)
        return False
    else:
        print "%s compiled." % codestring

    return true
Example #3
0
def get_tracks(filename):
    if filename == "":
        filename = radium.getLoadFilename("Choose midi file")
    if not filename or filename == "":
        return False
    try:
        tracks = midi.read_midifile(filename)
    except:
        radium.showMessage(
            "Could not read " + filename +
            ". Either file doesn't exist, or it could not be read as a standard midi file."
        )
        return False

    return tracks
Example #4
0
def start(keyhandles,filehandle,filehandle2,outfilehandle):
    keybindingsdict={} # Note: Latest E-radium version has just removed everything related to keybindingsdict from this function. Could be unnecessary.
    
    parser=Parser(filehandle,filehandle2)
    defnum=0
    reader=protoconfparser.Read()
    
    while parser.nextLine()!="ENDFILE":

        if outfilehandle:
            if parser.getLineType()=="GOINGTOINSERTCODE":
                outfilehandle.write("def keycodedef%d():\n" % defnum)
            if parser.getLineType()=="INSERTCODE":
                outfilehandle.write(parser.getCurrLine()+"\n")
            if parser.getLineType()=="INSERTCODELAST":
                outfilehandle.write("\treturn\n")
                if putCode(keyhandles,parser,"eventreceiverparser_generated.keycodedef%d()" % defnum)==false:
                    return False
                defnum+=1
            if parser.getLineType()=="INSERTCLEANCODE":
                outfilehandle.write(parser.getCurrLine()+"\n")

        if parser.getLineType()=="ERROR":
            return False

        if parser.getLineType()=="NORMAL":
            commands=parser.getCommands()


            lokke=2
            while lokke<len(commands):
                if commands[lokke][0]=="+":
                    add=int(commands.pop(lokke)[1:])
                    commands[lokke-1]="%d" % (int(commands[lokke-1])+add)
                elif commands[lokke][0]=="-":
                    add=int(commands.pop(lokke)[1:])
                    commands[lokke-1]="%d" % (int(commands[lokke-1])-add)
                elif commands[lokke][0]=="*":
                    add=int(commands.pop(lokke)[1:])
                    commands[lokke-1]="%d" % (int(commands[lokke-1])*add)
                elif commands[lokke][0]=="/":
                    add=int(commands.pop(lokke)[1:])
                    commands[lokke-1]="%d" % (int(commands[lokke-1])/add)
                lokke+=1

            ercommands=commands[:]
                      
            intercommands=range(len(ercommands))
            dascommand=ercommands.pop(0)
            command=commands.pop(0)
            command+="("
            while len(commands)>1:
                command+=commands.pop(0)+","
            if len(commands)>0:
                command+=commands.pop(0)
            command+=")"
            keys=parser.getKeys()+parser.getQualifiers() 
            firstkey=keys.pop(0)
            ccommand=false
            if dascommand[:3]=="ra.":
                ccommand=true
                for lokke in range(len(ercommands)):
                    if ercommands[lokke][0]!="\"":
                        intercommands[lokke]=ercommands[lokke]
                    else:
                        ccommand=false
                        break

            keybindingsdict[command]=[map(lambda x:keysub[x],parser.getKeys()),map(lambda x:keysub[x],parser.getQualifiers())]
            #printsak(0,keyhandles,parser,command)
            
            if ccommand==false:
                if putCode(keyhandles,parser,command)==false:
                    print "false"
                    return false
            else:
                success,intercommands2=reader.getUnfoldedCall(dascommand[3:],ercommands)
                if not success:
                    message = "Error at line %d: \"%s\"" % (parser.getCurrLineNum(),parser.getCurrLine())+"\n"+command+"\n"+str(intercommands2[0])
                    print message
                    radium.showMessage(message)
                    return False
                else:
                    retstring=radium.ER_keyAdd(firstkey,dascommand[3:],keys,intercommands2);
                    if retstring!="OK":
                        message = "Error at line %d: \"%s\"" % (parser.getCurrLineNum(),parser.getCurrLine())+"\n"+str(intercommands2[0])
                        print message
                        radium.showMessage(message)
                        return False


    import cPickle

    try:
        keybindingsfile=open("keybindings.cPickle","w")
        keybindingsfile.write(cPickle.dumps(keybindingsdict))
        keybindingsfile.close()
        #print keybindingsdict
    except:
        print "Couldn't create keybindings.cPickle. Using default."

    return true
Example #5
0
    def nextLine(self):
        if not self.readNextLine():
            return "ENDFILE"
        
        if self.currline[0:1]=='*':
            if self.linetype=="GOINGTOINSERTCODE":
                self.linetype="INSERTCODELAST"
            else:
                if self.linetype=="INSERTCODE":
                    self.linetype="INSERTCODELAST"
                else:
                    if self.linetype=="INSERTCLEANCODE":
                        self.linetype="INSERTCLEANCODELAST"
                    else:
                        self.linetype="GOINGTOINSERTCLEANCODE"
                
        else:
            if self.linetype=="GOINGTOINSERTCODE":
                self.linetype="INSERTCODE"
            if self.linetype=="GOINGTOINSERTCLEANCODE":
                self.linetype="INSERTCLEANCODE"
            if self.linetype=="INSERTCODELAST" or self.linetype=="INSERTCLEANCODELAST":
                self.linetype="NORMAL"
            if self.linetype=="NORMAL" or self.linetype=="SKIP":
                if self.currline[-2:]=="* ":
                    self.linetype="GOINGTOINSERTCODE"

                parts=self.parser.getParts()

                keys=[]
                self.command=[]
                for lokke in range(len(parts)):
                    if parts[lokke]==":":
                        keys=parts[:lokke]
                        self.command=parts[lokke+1:]
                        break
                lokke=0
                while lokke<len(keys):
                    key=tuple_has_key(keysub,keys[lokke])
                    if key==-1:
                        key=tuple_has_key(qualsub,keys[lokke])
                        if(key!=-1):
                            key+=tuple_has_key(keysub,"CTRL_L")
                    if key==-1:
                        message = "Unknown key \""+keys[lokke] +"\" in line %d in keyconfig file." % self.linenum
                        print message
                        radium.showMessage(message)
                        del keys[lokke]
                        self.linetype="ERROR"
                        return "OK"
                    else:
                        keys[lokke]=key
                        lokke+=1

                keys.sort()
                new_keys = []
                self.qualifiers = []
                
                for key in keys:
                    if key_is_qualifier(key):
                        self.qualifiers.append(key)
                    else:
                        new_keys.append(key)

                if len(keys)>len(self.qualifiers): # ????????
                    self.keys=new_keys
                        
                if self.linetype!="GOINGTOINSERTCODE":
                    if len(self.command)==0:
                        self.linetype="SKIP"
                    else:
                        self.linetype="NORMAL"

                #print "------------------------------------------>"
                #print "command: %s" % self.command
                #print "self.qualifiers: %s" % str(map(lambda k:keysub[k], self.qualifiers))
                #print "self.keys: %s " % str(map(lambda k:keysub[k], self.keys))
                #print "<------------------------------------------"

        return "OK"
Example #6
0
    return KeyHandler()

keyhandles=map(getKeyHandler,range(len(keybindingsparser.keysub)))

# key and keys are constants!
def gotKey(windownum,key,keys):
    #print "*********** key: " + keybindingsparser.keysub[key] + ". keys: " + str(map(lambda k:keybindingsparser.keysub[k], keys))
    #    key=keys.pop(0)
    return keyhandles[key].exe(windownum,keys);    


try:
    infilehandle=open(sys.argv[1],'r')
except:
    print "Cant open %s" % sys.argv[1]
    radium.showMessage("Cant open %s" % sys.argv[1])
    sys.exit(1)

try:
    infilehandle2=open(sys.argv[2],'r')
except:
    print "Cant open %s" % sys.argv[2]
    infilehandle2 = None

    #print "Cant open %s" % sys.argv[2], infilehandle2
    #sys.exit(-1)

try:
    outfilehandle=open("eventreceiverparser_generated.py",'w+')
    outfilehandle.write("#Do not edit. This file is automatically generated from keybindings.config.\n")
except: