Example #1
0
gint
main (gint argc, gchar ** argv)
{
  gboolean res = FALSE;
  gboolean arg_version = FALSE;
  gboolean arg_quiet = FALSE;
  gchar *command = NULL, *input_file_name = NULL, *output_file_name = NULL;
  gint saved_argc = argc;
  BtCmdApplication *app;
  GOptionContext *ctx;
  GOptionGroup *group;
  GError *err = NULL;

#ifdef ENABLE_NLS
  setlocale (LC_ALL, "");
  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);
#endif /* ENABLE_NLS */

  static GOptionEntry options[] = {
    {"version", '\0', 0, G_OPTION_ARG_NONE, NULL,
        N_("Print application version"), NULL},
    {"quiet", 'q', 0, G_OPTION_ARG_NONE, NULL, N_("Be quiet"), NULL},
    {"command", 'c', 0, G_OPTION_ARG_STRING, NULL, N_("Command name"),
        "{info, play, convert, encode}"},
    {"input-file", 'i', 0, G_OPTION_ARG_FILENAME, NULL, N_("Input file name"),
        N_("<songfile>")},
    {"output-file", 'o', 0, G_OPTION_ARG_FILENAME, NULL, N_("Output file name"),
        N_("<songfile>")},
    {NULL}
  };
  // setting this separately gets us from 76 to 10 instructions
  options[0].arg_data = &arg_version;
  options[1].arg_data = &arg_quiet;
  options[2].arg_data = &command;
  options[3].arg_data = &input_file_name;
  options[4].arg_data = &output_file_name;

  // init libraries
  ctx = g_option_context_new (NULL);
  //g_option_context_add_main_entries(ctx, options, GETTEXT_PACKAGE);
  group =
      g_option_group_new ("main", _("buzztrax-cmd options"),
      _("Show buzztrax-cmd options"), argv[0], NULL);
  g_option_group_add_entries (group, options);
  g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
  g_option_context_set_main_group (ctx, group);

  bt_init_add_option_groups (ctx);
  g_option_context_add_group (ctx, btic_init_get_option_group ());

  if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
    g_print ("Error initializing: %s\n", safe_string (err->message));
    g_option_context_free (ctx);
    exit (1);
  }
  if (arg_version) {
    g_printf ("%s from " PACKAGE_STRING "\n", argv[0]);
    res = TRUE;
    goto Done;
  }
  if (!command) {
    if (argc == saved_argc) {
      usage (argc, argv, ctx);
    }
    goto Done;
  }

  GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "bt-cmd", 0,
      "music production environment / command ui");
  GST_INFO ("starting: command=\"%s\" input=\"%s\" output=\"%s\"", command,
      input_file_name, output_file_name);

  // give some global context info
  g_set_prgname ("buzztrax-cmd");
  g_set_application_name ("Buzztrax");
  g_setenv ("PULSE_PROP_application.icon_name", "buzztrax", TRUE);
  g_setenv ("PULSE_PROP_media.role", "production", TRUE);

  app = bt_cmd_application_new (arg_quiet);


  // set a default command, if a file is given
  if (!command && BT_IS_STRING (input_file_name)) {
    command = g_strdup ("p");
  }
  // depending on the options call the correct method
  if (!strcmp (command, "p") || !strcmp (command, "play")) {
    if (!BT_IS_STRING (input_file_name))
      usage (argc, argv, ctx);
    res = bt_cmd_application_play (app, input_file_name);
  } else if (!strcmp (command, "i") || !strcmp (command, "info")) {
    if (!BT_IS_STRING (input_file_name))
      usage (argc, argv, ctx);
    res = bt_cmd_application_info (app, input_file_name, output_file_name);
  } else if (!strcmp (command, "c") || !strcmp (command, "convert")) {
    if (!BT_IS_STRING (input_file_name) || !BT_IS_STRING (output_file_name))
      usage (argc, argv, ctx);
    res = bt_cmd_application_convert (app, input_file_name, output_file_name);
  } else if (!strcmp (command, "e") || !strcmp (command, "encode")) {
    if (!BT_IS_STRING (input_file_name) || !BT_IS_STRING (output_file_name))
      usage (argc, argv, ctx);
    res = bt_cmd_application_encode (app, input_file_name, output_file_name);
  } else
    usage (argc, argv, ctx);

  // free application
  g_object_unref (app);

Done:
  g_free (command);
  g_free (input_file_name);
  g_free (output_file_name);
  g_option_context_free (ctx);

  return !res;
}
Example #2
0
gint
main (gint argc, gchar ** argv)
{
  gboolean res = FALSE;
  gchar *command = NULL, *input_file_name = NULL;
  BtEditApplication *app;
  GOptionContext *ctx = NULL;
  GOptionGroup *group;
  GError *err = NULL;

#ifdef ENABLE_NLS
  setlocale (LC_ALL, "");
  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);
#endif /* ENABLE_NLS */

  bt_setup_for_local_install ();

  GOptionEntry options[] = {
    {"version", '\0', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
        (gpointer) parse_goption_arg, N_("Print application version"), NULL}
    ,
    {"command", 'c', 0, G_OPTION_ARG_STRING, &command, N_("Command name"),
        "{load}"}
    ,
    {"input-file", 'i', 0, G_OPTION_ARG_FILENAME, &input_file_name,
        N_("Input file name"), N_("<songfile>")}
    ,
    {NULL}
  };

  // init libraries
  ctx = g_option_context_new (NULL);
  //g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
  group =
      g_option_group_new ("main", _("buzztrax-edit options"),
      _("Show buzztrax-edit options"), argv[0], NULL);
  g_option_group_add_entries (group, options);
  g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
  g_option_context_set_main_group (ctx, group);

  bt_init_add_option_groups (ctx);
  g_option_context_add_group (ctx, btic_init_get_option_group ());
  g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
  g_option_context_add_group (ctx, clutter_get_option_group_without_init ());
  g_option_context_add_group (ctx, gtk_clutter_get_option_group ());

  if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
    g_print ("Error initializing: %s\n", safe_string (err->message));
    g_error_free (err);
    goto Done;
  }

  GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "bt-edit", 0,
      "music production environment / editor ui");

  // give some global context info
  g_set_prgname ("buzztrax-edit");
  g_set_application_name ("Buzztrax");
  gtk_window_set_default_icon_name ("buzztrax");
  g_setenv ("PULSE_PROP_media.role", "production", TRUE);

  extern gboolean bt_memory_audio_src_plugin_init (GstPlugin * const plugin);
  gst_plugin_register_static (GST_VERSION_MAJOR,
      GST_VERSION_MINOR,
      "memoryaudiosrc",
      "Plays audio from memory",
      bt_memory_audio_src_plugin_init,
      VERSION, "LGPL", PACKAGE, PACKAGE_NAME, "http://www.buzztrax.org");

  GST_INFO ("starting: thread=%p", g_thread_self ());

  app = bt_edit_application_new ();

  // set a default command, if a file is given
  if (!command && BT_IS_STRING (input_file_name)) {
    command = g_strdup ("l");
  }

  if (command) {
    // depending on the options call the correct method
    if (!strcmp (command, "l") || !strcmp (command, "load")) {
      if (!BT_IS_STRING (input_file_name)) {
        usage (argc, argv, ctx);
        // if commandline options where wrong, just start
        res = bt_edit_application_run (app);
      } else {
        res = bt_edit_application_load_and_run (app, input_file_name);
      }
    } else {
      usage (argc, argv, ctx);
      // if commandline options where wrong, just start
      res = bt_edit_application_run (app);
    }
  } else {
    res = bt_edit_application_run (app);
  }

  // free application
  GST_INFO ("app %" G_OBJECT_REF_COUNT_FMT, G_OBJECT_LOG_REF_COUNT (app));
  g_object_unref (app);

Done:
  g_free (command);
  g_free (input_file_name);
  g_option_context_free (ctx);
  return !res;
}