Example #1
0
def function_make_sequencer(context: Context,
                            sequencer: SequencerLike) -> Sequencer:
    std = cast(StandardLibrary, context.library(StandardLibrary))

    format = None
    uri = None
    args = None

    if type(sequencer) is str:
        uri = sequencer
    elif type(sequencer) is list:
        args_start = 0

        if len(sequencer) >= args_start + 2 and sequencer[args_start] == '-o':
            uri = sequencer[args_start + 1]
            args_start += 2

        if len(sequencer) >= args_start + 2 and sequencer[args_start] == '-f':
            format = sequencer[args_start + 1]
            args_start += 2

        args = sequencer[args_start:]
    elif isinstance(sequencer, Sequencer):
        return sequencer

    if format is not None:
        return std.player.make_sequencer_from_format(format, uri or "", args
                                                     or [])

    return std.player.make_sequencer_from_uri(uri or "", args or [])
Example #2
0
def keyboard_close ( context : Context, keyboard : Keyboard ):
    if keyboard != None:
        keyboard.close()
    else:
        lib : KeyboardLibrary = cast( KeyboardLibrary, context.library( KeyboardLibrary ) )

        lib.close()
Example #3
0
def keyboard_filedialog ( context : Context, title : str = "File", text : str = "File Path:", default_value : str = None, cb = None ):
    from prompt_toolkit.patch_stdout import patch_stdout
    from prompt_toolkit.shortcuts import input_dialog
    from prompt_toolkit.completion import PathCompleter

    lib : KeyboardLibrary = cast( KeyboardLibrary, context.library( KeyboardLibrary ) )

    def _run ():
        with patch_stdout():
            application = input_dialog( title = title, text = text, completer = PathCompleter() )

            with application.input.raw_mode():
                application.input.read_keys()

            application.layout.current_control.buffer.insert_text(default_value or "")
            
            return application.run_async()

    lib.prompt( _run, cb )
Example #4
0
def function_readmidi(context: Context,
                      file: str = None,
                      port: Union[str, List[str], bool] = None,
                      voices: List[Voice] = None,
                      cutoff_sequence=None,
                      ignore_message_types: List[str] = None):
    if file is not None:
        mid = mido.MidiFile(file)

        return read_midi_file(context, mid, voices, cutoff_sequence,
                              ignore_message_types)
    else:
        if port == True:
            default_port = context.library(
                MidiLibrary).get_midi_default_input()

            if default_port is None:
                port = mido.open_input()
            else:
                port = mido.open_input(default_port)
        elif type(port) == str:
            port = mido.open_input(port)
        elif type(port) == list:
            port = MultiPort([mido.open_input(p) for p in port])

        events = midi_stream_to_music(context, port, context.voice,
                                      ignore_message_types)

        events = ComposeNotesTransformer.iter(events)

        if cutoff_sequence != None:
            events = TerminationMelodyTransformer.iter(
                events, list(cutoff_sequence.expand(context.fork(cursor=0))))

        events = TeeTransformer.iter(
            events,
            Transformer.pipeline(
                VoiceIdentifierTransformer(),
                MusiklaNotationBuilderTransformer(),
                Transformer.subscriber(lambda n: print(n + '\n\n'))))

        return Music(list(events))
Example #5
0
def function_set_midi_input_name(context: Context, name: str):
    context.library(MidiLibrary).set_midi_default_input(name)
Example #6
0
def function_get_midi_input_name(context: Context) -> str:
    return context.library(MidiLibrary).get_midi_default_input()
Example #7
0
def keyboard_readperf ( context : Context, file : str, keyboards : List[Keyboard] = None ) -> Music:
    lib : KeyboardLibrary = cast( KeyboardLibrary, context.library( KeyboardLibrary ) )

    return lib.readperf( context, file, keyboards )
Example #8
0
def keyboard_open_repl ( context : Context ):
    lib : KeyboardLibrary = cast( KeyboardLibrary, context.library( KeyboardLibrary ) )

    lib.eval( context )

    return None
Example #9
0
def keyboard_replay ( context : Context, file : str ):
    lib : KeyboardLibrary = cast( KeyboardLibrary, context.library( KeyboardLibrary ) )

    lib.replay( file )
Example #10
0
def keyboard_create ( context : Context ) -> Keyboard:
    lib : KeyboardLibrary = cast( KeyboardLibrary, context.library( KeyboardLibrary ) )

    return lib.create()
Example #11
0
def on_release ( context : Context, key : Union[str, KeyboardEvent] ):
    lib : KeyboardLibrary = cast( KeyboardLibrary, context.library( KeyboardLibrary ) )

    return lib.on_release( key )