#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# mididings
#
# Copyright (C) 2008-2014  Dominic Sacré  <dominic.sacre@gmx.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#

import sys
import argparse

from mididings.live.livedings import LiveDings


def fill_options(options, new_options):
    """Overwrites all values in 'options' with the corresponding values in 'new_options'."""
    for k, v in new_options.items():
        if getattr(options, k) == None:
            setattr(options, k, v)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-p",
        dest="control_port",
        default=56418,
        type=int,
        help="OSC port that mididings is listening on (56418)",
    )
    parser.add_argument(
        "-l",
        dest="listen_port",
        default=56419,
        type=int,
        help="OSC port for notifications from mididings (56419)",
    )
    parser.add_argument(
        "-T",
        dest="themed",
        default=False,
        action="store_true",
        help="enable custom theme and larger fonts",
    )
    parser.add_argument(
        "-x",
        dest="width",
        type=int,
        default=None,
        help="width of window in pixels (640)",
    )
    parser.add_argument(
        "-y",
        dest="height",
        type=int,
        default=None,
        help="height of window in pixels (400)",
    )
    parser.add_argument(
        "-w",
        dest="list_width",
        type=int,
        default=None,
        help="width of scene list in pixels (240)",
    )
    parser.add_argument(
        "-F", dest="font", type=str, default=None, help="display font (Sans 14 bold)"
    )
    parser.add_argument(
        "-f", dest="list_font", type=str, default=None, help="scene list font (Sans 10)"
    )
    parser.add_argument(
        "-c", dest="color", type=str, default=None, help="text color (gray50)"
    )
    parser.add_argument(
        "-C",
        dest="color_highlight",
        type=str,
        default=None,
        help="highlight text color (black)",
    )
    parser.add_argument(
        "-b", dest="color_background", type=str, default=None, help="background color"
    )
    parser.add_argument(
        "-n",
        dest="name",
        type=str,
        default=None,
        help="name to be shown in window title",
    )

    args = parser.parse_args()

    if args.themed:
        fill_options(
            args,
            {
                "width": 1024,
                "height": 640,
                "list_width": 320,
                "font": "Sans 32 bold",
                "list_font": "Sans 16",
                "color": "green",
                "color_highlight": "white",
                "color_background": "black",
            },
        )
    else:
        fill_options(
            args,
            {
                "width": 640,
                "height": 400,
                "list_width": 240,
                "font": "Sans 14 bold",
                "list_font": "Sans 10",
                "color": "gray50",
                "color_highlight": "black",
                "color_background": None,
            },
        )

    app = LiveDings(args)
    app.run()
