예제 #1
0
def slice_callback(unused_addr, args, the_OSC_message_argument):
    D("SliceCallback")
    #print("{} {} {} ".format(unused_addr, args, the_obj))
    message_ok = True

    if (len(unused_addr) != 15):
        message_ok = False
    loop_i = -1
    slice_i = -1
    new_mode = 'NOT-SET'

    the_status_obj = args[0]
    #probably should do a type() check here on the_status_obj

    try:
        loop_s = unused_addr[6]
        slice_s = unused_addr[14]
        loop_i = int(loop_s)
        slice_i = int(slice_s)

    except Exception as jeje:
        L("exception in handling OSC message {}".format(unused_addr))
        L("Exception: {}".format(jeje))
        L("{}".format(repr(jeje)))
        message_ok = False

    if (loop_i > 4 or loop_i < 1):
        D("Loop value out of range {} ".format(loop_i))
        #do nothing
        message_ok = False

    if (slice_i < 0 or slice_i > 7):
        D("slice value out of range {} ".format(slice_i))
        #do nothing
        message_ok = False

    #check is the_OSC_message_argument is a correct slice mode

    new_slice_mode = the_OSC_message_argument
    if not MODES.is_valid_mode(new_slice_mode):
        message_ok = False

    if (message_ok):
        set_slice_mode(loop_i, slice_i, new_slice_mode, the_status_obj)
        the_status_obj.set_osc_message("{} : {}  DONE".format(
            unused_addr, the_OSC_message_argument))
    else:
        # log error message
        #TODO fix this error message
        L("unable to parse message {} {} ".format(unused_addr,
                                                  the_OSC_message_argument))
        the_status_obj.set_osc_message("{} : {}  FAIL".format(
            unused_addr, the_OSC_message_argument))
        return
    #print("Loop:{}  slice:{}".format(loop_i,slice_i))
    return
예제 #2
0
 def stop_audio(self):
     """ Stop the audio callback.  we want to exit cleanly using this"""
     L("Stopping Audio Engine")
     self.stream.stop_stream()
     self.stream.close()
     p.terminate()
     return
예제 #3
0
    def start_audio(self):
        """Start the audio stream.  setup the callbacks then enter a loop.  """
        L("Starting Audio Engine")
        self.stream = p.open(
            format=pyaudio.paFloat32, channels=2, rate=44100,
            output=True, stream_callback=self.audio_callback)

        self.stream.start_stream()
        return
예제 #4
0
def loop_mode_callback(unused_addr, args, the_OSC_message_argument):
    D("LoopCallback")
    #print("{} {} {} ".format(unused_addr, args, the_obj))
    message_ok = True

    if (len(unused_addr) != 12):
        message_ok = False
    loop_i = -1
    new_mode = 'NOT-SET'

    the_status_obj = args[0]
    try:
        loop_s = unused_addr[6]
        loop_i = int(loop_s)

    except Exception as jeje:
        L("exception in handling OSC message {}".format(unused_addr))
        L("Exception: {}".format(jeje))
        L("{}".format(repr(jeje)))
        message_ok = False

    if (loop_i > 4 or loop_i < 1):
        D("Loop value out of range {} ".format(loop_i))
        #do nothing
        message_ok = False

    new_slice_mode = the_OSC_message_argument
    if not LM.is_valid_mode(new_slice_mode):
        message_ok = False

    if (message_ok):
        set_loop_mode(loop_i, new_slice_mode, the_status_obj)
        the_status_obj.set_osc_message("{} : {}  DONE".format(
            unused_addr, the_OSC_message_argument))
    else:
        # log error message
        #TODO fix this error message
        L("unable to parse message {} {} ".format(unused_addr,
                                                  the_OSC_message_argument))
        the_status_obj.set_osc_message("{} : {}  FAIL".format(
            unused_addr, the_OSC_message_argument))
        return
    #print("Loop:{}  slice:{}".format(loop_i,slice_i))
    return
예제 #5
0
def loop_volume_callback(unused_addr, args, the_OSC_message_argument):
    D("loop_volume_callback")
    #set the volume level of a loop.
    #.set_volume(float)
    #range 0.0 - 1.0

    #    if(len(unused_addr) != 12):
    #        message_ok = False
    loop_i = -1
    new_volume_level = -1.0

    message_ok = True

    the_status_obj = args[0]
    #get the loop id. /loop/*
    try:
        loop_s = unused_addr[6]
        loop_i = int(loop_s)

    except Exception as jeje:
        L("exception in handling OSC message {}".format(unused_addr))
        L("Exception: {}".format(jeje))
        L("{}".format(repr(jeje)))
        message_ok = False

    if (loop_i > 4 or loop_i < 1):
        D("Loop value out of range {} ".format(loop_i))
        #do nothing
        message_ok = False
    #convert the argument to a float.
    try:
        new_volume_level = float(the_OSC_message_argument)
        if (new_volume_level < 0.0):
            message_ok = False
    #float parsing error handling.
    except Exception as flt_error:
        L("exception handing OSC message {}".format(unused_addr))
        L("exception parsing {}".format(the_OSC_message_argument))
        L("Exception: {}".format(flt_error))
        L("{}".format(rep(flt_error)))
        message_ok = False

    if (message_ok):
        set_loop_volume(loop_i, new_volume_level, the_status_obj)
        the_status_obj.set_osc_message("{} : {}  DONE".format(
            unused_addr, the_OSC_message_argument))
    else:
        # log error message
        #TODO fix this error message
        L("unable to parse message {} {} ".format(unused_addr,
                                                  the_OSC_message_argument))
        the_status_obj.set_osc_message("{} : {}  FAIL".format(
            unused_addr, the_OSC_message_argument))
    return
예제 #6
0
def loop_file_callback(unused_addr, args, the_OSC_message_argument):
    D("loop file callback")
    # has an argument of an int.
    message_ok = True

    the_status_obj = args[0]
    #get the loop id. /loop/*
    try:
        loop_s = unused_addr[6]
        loop_i = int(loop_s)
        # get the track index
        new_track_index = int(the_OSC_message_argument)
    except Exception as errerr:
        L("exception with loop_file_callback ")
        L("Error: {}".format(errerr))
        message_ok = False
        return
    if (loop_i not in range(1, 5)):
        message_ok = False

    if (message_ok):
        try_load_new_file_by_int(loop_i, new_track_index, the_status_obj)
        the_status_obj.set_osc_message("{} : {}  DONE".format(
            unused_addr, the_OSC_message_argument))
        D("loop_file_callback {} {}".format(loop_i, new_track_index))

    else:
        L("message not processed. loop_file_callback")
        L("Message received {}".format(the_OSC_message_argument))
        L("Message Received {} ".format(unused_addr))
        L("Message Received {}".format(args))
        the_status_obj.set_osc_message("{} : {}  FAIL".format(
            unused_addr, the_OSC_message_argument))
    return
예제 #7
0
def loop_jump_callback(unused_addr, args, the_OSC_message_argument):
    D("loop jump callback")
    message_ok = True

    if (len(unused_addr) != 12):
        message_ok = False

    the_status_obj = args[0]
    try:
        loop_s = unused_addr[6]
        loop_i = int(loop_s)
        jump_i = int(the_OSC_message_argument)

    except Exception as jj:
        L("Exception parsing {} {}".format(unused_addr),
          the_OSC_message_argument)
        L("Exception {} ".format(jj))
        message_ok = False
        loop_i = -1
        jump_i = -1

    if (loop_i > 4 or loop_i < 1):
        D("Loop value out of range {} ".format(loop_i))
        message_ok = False
    if (jump_i > 7 or jump_i < 0):
        D("jump value out of range {}".format(jump_i))
        message_ok = False

    if (message_ok):
        set_loop_jump(loop_i, jump_i, the_status_obj)
        the_status_obj.set_osc_message("{} : {}  DONE".format(
            unused_addr, the_OSC_message_argument))
    else:
        # log error message
        #TODO fix this error message
        L("unable to parse message {} {} ".format(unused_addr,
                                                  the_OSC_message_argument))
        the_status_obj.set_osc_message("{} : {}  FAIL".format(
            unused_addr, the_OSC_message_argument))
    return
예제 #8
0
def start_OSC_server(spoon_status_object):
    
    disp = dispatcher.Dispatcher()

    disp.map("/loop/*/slice/*", slice_callback, spoon_status_object)
    disp.map("/loop/*/mode", loop_mode_callback, spoon_status_object)
    disp.set_default_handler(default_callback)
    
    new_osc_port = spoon_status_object.osc_port
    
    server = osc_server.ThreadingOSCUDPServer( ("127.0.0.1", new_osc_port), disp)
    server_thread = threading.Thread(target=server.serve_forever)
    server_thread.start()
    L("Serving on {}".format(server.server_address))
    #return the server and thread so we can shut it down when we quit
    # server.shutdown()
    return server , server_thread
예제 #9
0
def test_file_correctness(audio_file_path):
    #TODO make this actually test the file
    #returns true if the file is OK.  false otherwise
    # D("trying to open: {}".format(audio_file_path))
    try:
        j = soundfile.info(audio_file_path)
        # D("{} :  soundfile info {}".format(audio_file_path, str(j)))

        #TODO add more supported formats in a future time
        if (j.samplerate == 44100 and j.channels == 2):
            L("File {} is OK.".format(audio_file_path))
            return True
        else:
            W("File {} is NOT OK. Sample rate is {} and channels are {}".
              format(audio_file_path, j.samplerate, j.channels))
            return False
    except Exception as e:
        W("Error opening file {}. Message was {}".format(
            audio_file_path, repr(e)))
    #if we have got to this point, we've failed the try/except so there is a filepath or permissions problem. return False
    return False
예제 #10
0
 def toggle_mute(self):
     # toggles the mute state
     # returns the new mute state.
     self.mute = (not self.mute)
     L("Mute state toggled.  new state {}".format(str(self.mute)))
     return self.mute
예제 #11
0
def default_callback(unused_addr, args):
    L("unknown message {} {}".format(unused_addr, args))
    return