Exemplo n.º 1
0
def main(configfile='../default_setup.ini'):
    """
    Start hello world!

    :param int configfile: use this configuration file. Defaults to 'default_setup.ini'.
    """

    #Read config and settings
    config = configparser.ConfigParser()
    config.read(configfile, encoding='utf8')

    try:
        myPort = config['midi'].getint('port')
        device_id = config['midi'].getint('noteon_id')
    except KeyError:
        raise LookupError('Missing key information in the config file.')

    if (myPort == None or device_id == None):
        raise LookupError('Missing key information in the config file.')

    codeK = Setup()
    tutorial = Instructions()
    codeK.open_port(myPort)
    codeK.open_port_out(myPort)

    # Use your favourite mapping of the keys
    mapping = Mapping_HelloWorld_NKK()

    # class to handle the midi input and map it to characters
    #TODO: this is ugly! Move this to the CodeKlavier module
    class HelloWorld(object):
        def __init__(self, port):
            self.port = port

        def __call__(self, event, data=None):
            message, deltatime = event
            # print(message)
            if message[2] > 0:  #only noteOn
                if (message[0] == device_id):
                    mapping.mapping(message[1])
                    # forwarding only note on messages to tutorial terminal for NKK:
                    codeK.send_message([message[0], message[1], message[2]])
                if (message[0] == 176):  #hardcoded pedal id (not pretty)
                    mapping.stopSC(message[1])

    codeK.set_callback(HelloWorld(myPort))

    # Loop to program to keep listening for midi input
    try:
        # timer = time.time()
        while True:
            if tutorial.mode():
                break
            time.sleep(0.01)
    except KeyboardInterrupt:
        print('')
    finally:
        # print("Bye-Bye :(")
        codeK.end()
Exemplo n.º 2
0
def main(configfile='../default_setup.ini'):
    # Start the CodeKlavier
    #Read config and settings
    config = configparser.ConfigParser()
    config.read(configfile, encoding='utf8')

    try:
        myPort = config['midi'].getint('port')
        device_id = config['midi'].getint('noteon_id')
    except KeyError:
        raise LookupError('Missing key information in the config file.')

    if (myPort == None or device_id == None):
        raise LookupError('Missing key information in the config file.')

    codeK = Setup()
    tutorial = Instructions()
    codeK.open_port(myPort)
    codeK.open_port_out(myPort)

    # Use your favourite mapping of the keys
    mapping = Mapping_HelloWorld_NKK()

    # class to handle the midi input and map it to characters
    #TODO: this is ugly! Move this to the CodeKlavier module
    class HelloWorld(object):
        def __init__(self, port):
            self.port = port

        def __call__(self, event, data=None):
            message, deltatime = event
            # print(message)
            if message[2] > 0:  #only noteOn
                if (message[0] == device_id):
                    mapping.mapping(message[1])

    codeK.set_callback(HelloWorld(myPort))

    tutorial.do_tutorial()
    codeK.send_message([0x90, 108, 127])  #send enter to codespace
    tutorial.level_four()

    # Loop to program to keep listening for midi input
    try:
        timer = time.time()
        while True:
            time.sleep(0.01)
    except KeyboardInterrupt:
        print('')
    finally:
        # print("Bye-Bye :(")
        codeK.end()
Exemplo n.º 3
0
def main(configfile='default_setup.ini'):
    """
    Start hello world!

    :param int configfile: use this configuration file. Defaults to 'default_setup.ini'.
    """

    #Read config and settings
    config = configparser.ConfigParser()
    config.read(configfile, encoding='utf8')
    
    try:
        myPort = config['midi'].getint('port')
        device_id = config['midi'].getint('noteon_id')
    except KeyError:
        raise LookupError('Missing key information in the config file.')

    if (myPort == None or device_id == None):
        raise LookupError('Missing key information in the config file.')
    
    codeK = Setup()
    codeK.print_welcome(27)
    codeK.open_port(myPort)
    
    # Use your favourite mapping of the keys
    mapping = Mapping_HelloWorld()
    
    print("\nCodeKlavier is ready and ON.")
    print("You are performing: HELLO WORLD")
    print("\nPress Control-C to exit.")
    
    codeK.set_callback(HelloWorld(myPort, mapping, device_id))
    
    # Loop to program to keep listening for midi input
    try:
        while True:
            time.sleep(0.01)
    except KeyboardInterrupt:
        print('')
    finally:
        print("Bye-Bye :(")
        codeK.end()