예제 #1
0
def composer_prompt(db):
    composers = db_interface.explore_table(db.table("composers"),
                                           search=("name", ""))
    comp = prompt("Enter Composer: ",
                  completer=InsensitiveCompleter(composers))
    matches = []
    for item in composers:
        if comp in item:
            matches.append(item)
    if matches:
        load = prompt(f"Would you like to load {comp} from the database? ",
                      default='Y',
                      validator=YNValidator())
        if answered_yes(load):
            if len(matches) > 1:
                for num, match in enumerate(matches):
                    print(f"{num}. {match}")
                choice = prompt(
                    "Please enter the number of the "
                    "matching composer or press [enter] if none match: ",
                    validator=IndexValidator(len(matches) - 1,
                                             allow_empty=True))
                if choice:
                    found = matches[int(choice[0])]
            else:
                found = matches[0]
            try:
                return info.Composer.load_from_db(found, db)
            except NameError:
                pass
    new_comp = info.Composer(comp)
    guess_short_name = new_comp.get_short_name()
    try:
        guess_mutopia_name = new_comp.get_mutopia_name(guess=True)
    except AttributeError:
        guess_mutopia_name = ''
    new_comp.shortname = prompt("Enter the abbreviated name of the composer: ",
                                default=guess_short_name)
    new_comp.mutopianame = prompt(
        "Enter the mutopia formatted name of the composer "
        "or [enter] for none: ",
        default=guess_mutopia_name)
    add_to_db = prompt(
        "Would you like to add this composer to the database for easy usage next time? ",
        default='Y',
        validator=YNValidator())
    if answered_yes(add_to_db):
        new_comp.add_to_db(db)
    return new_comp
예제 #2
0
def build(file_path, target_dir, extra_includes, key_in_partname,
          compress_full_bar_rests):
    target_dir = Path(target_dir)
    if not file_path:
        possible_configs = [
            possible for possible in os.listdir(target_dir)
            if '.yaml' in possible or '.yml' in possible
        ]
        if len(possible_configs) == 0:
            print("No config file found. Please specify one with -f")
            raise SystemExit(1)
        elif len(possible_configs) == 1:
            print(f"Config file found: {possible_configs[0]}")
            use = prompt("Use this config? ",
                         default='Y',
                         validator=YNValidator())
            if answered_yes(use):
                file_path = possible_configs[0]
            else:
                print(
                    "Please specify a config file with -f or change to the directory it is in."
                )
                raise SystemExit(1)
    piece = yaml_interface.read_config(Path(file_path))
    # piece = info.Piece.load(config_data)
    lyglobal = lynames.LyName('global')
    include_paths = []
    flags = {
        "key_in_partname": key_in_partname,
        "compress_full_bar_rests": compress_full_bar_rests
    }
    global_file = render.make_global(lyglobal, piece, location=target_dir)
    include_paths.extend(global_file)
    for instrument in piece.instruments:
        new_includes = render.make_instrument(instrument=instrument,
                                              lyglobal=lyglobal,
                                              piece=piece,
                                              location=target_dir,
                                              flags=flags)
        include_paths.extend(new_includes)
    render.render_includes(include_paths,
                           piece,
                           extra_includes=extra_includes,
                           location=target_dir)
    render.render_defs(piece, location=target_dir)
    render.render_score(piece,
                        piece.instruments,
                        lyglobal,
                        path_prefix=Path('.'))
예제 #3
0
def ensemble_prompt(curr_instruments, db_):
    """
    Prompt for creating ensembles.

    :param curr_instruments: Current list of instruments.
    :param db_: database to load to/from
    :return: lynames.Ensemble object
    """
    ensemble_names = db_interface.explore_table(db_.table("ensembles"),
                                                search=("name", ""))
    ensembles = [
        titlecase(' '.join(name.split('_'))) for name in ensemble_names
    ]
    ensemble_name = prompt("Please enter a name for the ensemble: ",
                           completer=InsensitiveCompleter(ensembles))
    ensemble_name_normal = lynames.normalize_name(ensemble_name)
    new_ens = None
    if ensemble_name_normal in ensemble_names:
        load = prompt(
            f"{ensemble_name} is in the database, would you like to load it? "
            "[Y/n] ",
            default='Y',
            validator=YNValidator())
        if answered_yes(load):
            return lynames.Ensemble.load_from_db(ensemble_name, db_)
    while True:
        new_ens = common.create_ensemble(ensemble_name, db_, curr_instruments)
        if isinstance(new_ens, lynames.Ensemble):
            break
        else:
            retry = prompt(f"No new ensemble was created. Try again? ",
                           validator=YNValidator(),
                           default='Y')
            if not answered_yes(retry):
                break
    return new_ens
예제 #4
0
def edit_prompt(piece, config_path, db, path_save):
    """
    edit_prompt is the prompt for editing the configuration in the command line
    :param piece: the data from the piece currently being worked on
    :param config_path: The path to the configuration file being worked on.
    :return:
    """
    prompt_help = (
        "\nYou can now add score information. Available modes are:\n"
        f"{BOLD}header:{END}\t\tadd title, composer, etc.\n"
        f"{BOLD}mutopia:{END}\tAdd information for submitting to the mutopia project\n"
        f"{BOLD}instrument:{END}\tadd/remove/re-order individual instruments "
        "in the score\n"
        f"{BOLD}ensemble:{END}\tadd an ensemble to the score\n"
        f"{BOLD}movement:{END}\tadd/remove movements (including time, key, "
        f"and tempo info\n"
        f"{BOLD}language:{END}\tset the region language for lilypond\n"
        f"{BOLD}print:{END}\t\t print the current state of the score info.\n"
        f"{BOLD}save:{END}\t\t save current state to config file\n"
        f"{BOLD}quit:{END}\t\texit (option to save)\n"
        f"{BOLD}help:{END}\t\tprint this message\n")
    command_list = [
        'header', 'instrument', 'ensemble', 'movement', 'print', 'quit', 'help'
    ]
    command_completer = WordCompleter(command_list)
    infodict = {}
    if isinstance(piece, info.Piece):
        infodict = {
            "headers": piece.headers,
            "instruments": piece.instruments,
            "opus": piece.opus,
            "movements": piece.movements,
            "mutopia_headers": piece.headers.mutopiaheaders,
            "language": piece.language
        }
    if "opus" not in infodict:
        infodict["opus"] = prompt(
            "Please enter an opus or catalog number or the piece: ")
    print(prompt_help)
    while 1:
        # DEBUG LINE
        # print(infodict)
        try:
            ps1 = infodict["headers"].title
        except (AttributeError, KeyError, TypeError):
            ps1 = "Untitled"
        command = prompt(f"{ps1}> ", completer=command_completer)
        if len(command) == 0:
            continue
        if command[0].lower() == 'q':
            save = prompt("Save file before exiting? ",
                          default='Y',
                          validator=YNValidator())
            if answered_yes(save):
                print('Saving File')
                save_config(infodict, config_path)
            try:
                os.remove(path_save)
            except FileNotFoundError:
                pass
            print("Exiting")
            raise SystemExit(0)
        elif command.lower().strip() == "save":
            save_config(infodict, config_path)
            print("Saved")
        elif command.lower().strip() == "help":
            print(prompt_help)
        elif "header" in command.lower():
            if "headers" not in infodict:
                infodict["headers"] = None
            infodict["headers"] = header_prompt(infodict["headers"], db)
        elif command.lower()[0] == 'i':
            if "instruments" not in infodict:
                infodict["instruments"] = []
            infodict["instruments"] = existing_instruments(
                infodict["instruments"], db, instrument_prompt)
        elif command.lower()[0] == 'e':
            if "instruments" not in infodict:
                infodict["instruments"] = []
            infodict["instruments"] = existing_instruments(
                infodict["instruments"], db, ensemble_prompt)
        elif command.lower()[0:2] == 'mo':
            if "movements" not in infodict:
                infodict["movements"] = []
            infodict["movements"] = movement_prompt(infodict["movements"])
        elif command.lower()[0:2] == 'mu':
            if "mutopia_headers" not in infodict:
                infodict["mutopia_headers"] = None
            infodict['mutopia_headers'] = mutopia_prompt(
                infodict["mutopia_headers"])
        elif command.lower()[0] == 'l':
            infodict["language"] = prompt("Enter Lilypond Language: ",
                                          completer=WordCompleter(
                                              info.get_valid_languages()),
                                          validator=LanguageValidator())
        elif command.lower()[0] == 'p':
            print_piece_info(infodict)
        else:
            print(INVALID)
예제 #5
0
def header_prompt(curr_headers, db):
    prompt_help = (
        "You may edit any of the following headers:\n"
        "title\t\tcomposer\n"
        "dedication\tsubtitle\n"
        "subsubtitle\tpoet\n"
        "meter\t\tarranger\n"
        "tagline\t\tcopyright\n"
        f"Enter {BOLD}print{END} to print the current headers and {BOLD}done{END} to finish"
        "and return to the main prompt.")
    print(prompt_help)
    titlewords = WordCompleter(
        db_interface.explore_table(db.table("titlewords"),
                                   search=("word", "")))
    field_completer = WordCompleter([
        "title", "composer", "subtitle", "subsubtitle", "poet", "meter",
        "arranger", "tagline", "copyright", "print", "done"
    ])
    if curr_headers is None:
        composer = composer_prompt(db)
        title = prompt("Enter Title: ", completer=titlewords)
        curr_headers = info.Headers(title=title, composer=composer)
    while 1:
        # DEBUG LINE
        # print(curr_headers)
        command = prompt("Headers> ", completer=field_completer)
        if len(command) == 0:
            continue
        field = command.lower().strip()
        if field == "title":
            title = prompt(
                "Current title is \"{}\" enter a new title or press "
                "enter to keep the current one: ".format(curr_headers.title))
            if len(title) != 0:
                curr_headers.title = title
        elif "comp" in field:
            change_comp = prompt(
                "Current composer is {}. Would you like to change "
                "it? ".format(curr_headers.composer.name),
                default='N',
                validator=YNValidator())
            if answered_yes(change_comp):
                curr_headers.composer = composer_prompt(db)
        elif field in [
                "dedication", "subtitle", "subsubtitle", "poet", "meter",
                "arranger", "tagline", "copyright"
        ]:
            print("{} is {}".format(field, getattr(curr_headers, field,
                                                   "blank")))
            new = prompt(
                f"Enter value for {field} or press enter to leave unchanged: ")
            if len(new) > 0:
                setattr(curr_headers, field, new)
        # Logistical commands
        elif field[0] == 'h':
            print(prompt_help)
        elif field[0] == 'p':
            print(curr_headers)
        elif field[0] == 'd' or field == "save":
            print("Saving headers")
            return curr_headers
        else:
            print(INVALID)