示例#1
0
文件: main.c 项目: kazutomi/xiphqt
void
cmdline_mode(int argc,
	     char *argv[]) {

  int p, t;

  AppData *appdata = g_new(AppData, 1);
  appdata->runmode = CMDLINE;
  appdata->playlist = playlist_new();
  appdata->decoder = decoder_new();
  appdata->stream = NULL;


  /* setup callbacks */
  playlist_set_play_cb(appdata->playlist, play_cb, (void *) appdata);
  playlist_next(appdata->playlist);

  while (TRUE) {
    if (decoder_is_playing(appdata->decoder)) {
      
      p = decoder_get_position(appdata->decoder);
      t = decoder_get_total(appdata->decoder);
      printf("%s: %d / %d\n", appdata->decoder->tag_title, p, t);

    } else if (decoder_has_finished(appdata->decoder)) {

      playlist_next(appdata->playlist);
    }

    usleep(500);
  }

}
示例#2
0
文件: playlist.c 项目: edma2/vitunes
/*
 * Duplicate an existing playlist, returning a pointer to the newly allocated
 * playlist.  The filename and name of the new playlist must be specified.
 */
playlist *
playlist_dup(const playlist *original, const char *filename,
   const char *name)
{
   playlist *newplist;
   int i;

   /* create new playlist and copy simple members */
   newplist           = playlist_new();
   newplist->nfiles   = original->nfiles;
   newplist->capacity = original->nfiles;

   if (name != NULL) {
      if ((newplist->name = strdup(name)) == NULL)
         err(1, "playlist_dup: strdup name failed");
   }
   if (filename != NULL) {
      if ((newplist->filename = strdup(filename)) == NULL)
         err(1, "playlist_dup: strdup filename failed");
   }

   /* copy all of the files */
   newplist->files = calloc(original->nfiles, sizeof(meta_info*));
   if (newplist->files == NULL)
      err(1, "playlist_dup: failed to allocate files");

   for (i = 0; i < original->nfiles; i++)
      newplist->files[i] = original->files[i];

   return newplist;
}
示例#3
0
void command_plcreate(const struct command * const command)
{
	if(playlist_new(command->name))
	{
		sock_send_str(command->sockfd, "Created new playlist.\n");
	}
	else
	{
		sock_send_str(command->sockfd, "Couldn't create new playlist.\n");
	}
}
示例#4
0
文件: commands.c 项目: sahne/vitunes
int
cmd_new(int argc, char *argv[])
{
   playlist *p;
   char     *name;
   char     *filename;
   int       i;

   if (argc > 2) {
      paint_error("usage: new [name]");
      return 1;
   }

   /* defaults */
   name = "untitled";
   filename = NULL;

   /* was a name specified? */
   if (argc == 2) {
      /* check for existing playlist with name */
      for (i = 0; i < mdb.nplaylists; i++) {
         if (strcmp(mdb.playlists[i]->name, argv[1]) == 0) {
            paint_error("playlist \"%s\" already exists.", argv[1]);
            return 2;
         }
      }

      name = argv[1];
      asprintf(&filename, "%s/%s.playlist", mdb.playlist_dir, name);
      if (filename == NULL)
         err(1, "cmd_new: asprintf(3) failed");
   }

   /* create & setup playlist */
   p = playlist_new();
   p->needs_saving = true;
   p->filename = filename;
   if ((p->name = strdup(name)) == NULL)
      err(1, "cmd_new: strdup(3) failed");

   /* add playlist to media library and update ui */
   medialib_playlist_add(p);
   ui.library->nrows++;
   if (p->filename != NULL)
      playlist_save(p);

   /* redraw */
   paint_library();
   paint_message("playlist \"%s\" added", name);

   return 0;
}
示例#5
0
文件: playlist.c 项目: edma2/vitunes
/*
 * Loads a playlist from the provided filename.  The files within the playlist
 * are compared against the given meta-information-database to see if they
 * exist there.  If they do, the corresponding entry in the playlist structure
 * built is simply a pointer to the existing entry.  Otherwise, that file's
 * meta information is set to NULL and the file is copied (allocated) in the
 * playlist structure.
 *
 * A newly allocated playlist is returned.
 */
playlist *
playlist_load(const char *filename, meta_info **db, int ndb)
{
   meta_info *mi, **mit;
   FILE *fin;
   char *period;
   char  entry[PATH_MAX + 1];

   /* open file */
   if ((fin = fopen(filename, "r")) == NULL)
      err(1, "playlist_load: failed to open playlist '%s'", filename);

   /* create playlist and setup */
   playlist *p = playlist_new();
   p->filename = strdup(filename);
   p->name     = strdup(basename(filename));
   if (p->filename == NULL || p->name == NULL)
      err(1, "playlist_load: failed to allocate info for playlist '%s'", filename);

   /* hack to remove '.playlist' from name */
   period  = strrchr(p->name, '.');
   *period = '\0';

   /* read each line from the file and copy into playlist object */
   while (fgets(entry, PATH_MAX, fin) != NULL) {
      /* sanitize */
      entry[strcspn(entry, "\n")] = '\0';

      /* check if file exists in the meta info. db */
      mit = bsearch(entry, db, ndb, sizeof(meta_info *), cmp_fn_mi);
      mi = *mit;

      if (mi != NULL)   /* file DOES exist in DB */
         playlist_files_append(p, &mi, 1, false);
      else {            /* file does NOT exist in DB */
         /* create empty meta-info object with just the file name */
         mi = mi_new();
         mi->filename = strdup(entry);
         if (mi->filename == NULL)
            err(1, "playlist_load: failed to strdup filename");

         /* add new record to the db and link it to the playlist */
         playlist_files_append(p, &mi, 1, false);
         warnx("playlist \"%s\", file \"%s\" is NOT in media database (added for now)",
            p->name, entry);
      }
   }

   fclose(fin);
   return p;
}
示例#6
0
// Tritt ein, wenn auf dem Track TreeView eine Zeile aktiviert wird
void on_treeview_tracks_row_activated (GtkTreeView *tree,
                                       GtkTreePath *path,
                                       GtkTreeViewColumn *column,
                                       gpointer user_data)
{
    GtkTreeModel *model;
    GtkTreeIter iter;
    gint id;
    char **results;
    gint rows;
    gint cols;
    char *err;
    gboolean iter_ok;
    gchar *sql;
    gchar *uri;
    PlayList *list;
    gint *indices;

    model = gtk_tree_view_get_model (tree);
    list = playlist_new ();

    // Alle Tracks einlesen
    iter_ok = gtk_tree_model_get_iter_first (model, &iter);
    while (iter_ok) {

        // Track Id holen
        gtk_tree_model_get (model, &iter, COL_TRACK_ID, &id, -1);

        // Hier Track-Details holen
        sql = g_strdup_printf ("SELECT trackpath FROM tbl_track WHERE IDtrack = %d", id);
        if (sqlite3_get_table (db, sql, &results, &rows, &cols, &err)) {
            g_warning ("%s", err);
            return;
        }

        // Pfad in Liste einfügen
        uri = g_strdup_printf ("file://%s", results[1]);
        playlist_add_uri (list, uri);
        g_free (uri);
        g_free (sql);
        iter_ok = gtk_tree_model_iter_next (model, &iter);
    }
    indices = gtk_tree_path_get_indices (path);
    player_play_playlist (list, indices[0]);
}
示例#7
0
文件: playlist.c 项目: edma2/vitunes
/*
 * Filter a playlist.  After a query string is setup using the meta_info
 * function "mi_query_set(..)" function, this function can be used to
 * filter out all of the entried of a playlist that match/do-not-match
 * that query string.
 *
 * The results are in the new playlist that is returned.
 * If no query is set with mi_query_init(), NULL is returned.
 *
 * The 'm' parameter controls if records matching should be returned
 * (m = true) or if records not matching should be returned (m=false)
 */
playlist *
playlist_filter(const playlist *p, bool m)
{
   playlist *results;
   int       i;

   if (!mi_query_isset())
      return NULL;
   
   results = playlist_new();
   for (i = 0; i < p->nfiles; i++) {
      if (mi_match(p->files[i])) {
         if (m)  playlist_files_append(results, &(p->files[i]), 1, false);
      } else {
         if (!m) playlist_files_append(results, &(p->files[i]), 1, false);
      }
   }

   return results;
}
示例#8
0
文件: main.c 项目: kazutomi/xiphqt
void
gui_mode(int argc,
	 char *argv[]) {

  osso_context_t *osso_context;
  char *versionstring;
  AppData *appdata = g_new(AppData, 1);
  appdata->runmode = GUI;


  gtk_init(&argc, &argv);

  /* register OSSO service */
  osso_context = osso_initialize(NAME, VERSION, TRUE, NULL);
  if (! osso_context)
    fprintf(stderr, "Could not initialize OSSO.");

  appdata->playlist = playlist_new();
  appdata->decoder = decoder_new();
  appdata->stream = NULL;
  appdata->gui = gui_new(appdata->playlist);

  versionstring = g_strconcat(FULLNAME, " ", VERSION, NULL);
  gui_set_title(appdata->gui, "", versionstring, "");
  g_free(versionstring);

  /* setup callbacks */
  playlist_set_play_cb(appdata->playlist, play_cb, (void *) appdata);

  /* setup GUI callbacks */
  gui_set_open_cb(appdata->gui, open_cb, (void *) appdata);
  gui_set_volume_cb(appdata->gui, volume_cb, (void *) appdata);
  gui_set_seek_cb(appdata->gui, seek_cb, (void *) appdata);
  gui_set_control_cb(appdata->gui, control_cb, (void *) appdata);

  g_timeout_add(500, (GSourceFunc) status_cb, appdata);

  gui_run();

}
示例#9
0
void library_view_clear_playlist(library_view_t* view) 
{
  playlist_t* pl = playlist_new(view->library, "nil");
  playlist_model_set_playlist(view->playlist_model, pl);
}
示例#10
0
int main(char *argv[],int argc) {
  mc_init();
  el_bool stop = el_false;
  
  hre_t re_load = hre_compile("^load(&play)?\\s+(.*)$","i");
  hre_t re_play = hre_compile("^play$","i");
  hre_t re_pause = hre_compile("^pause$","i");
  hre_t re_next = hre_compile("^next$","i");
  hre_t re_previous = hre_compile("^prev(ious)?$","i");
  hre_t re_track = hre_compile("^track\\s+([0-9]+)$","i");
  hre_t re_quhit = hre_compile("^quit$","i");
  hre_t re_seek = hre_compile("^seek\\s([0-9]+([.][0-9]+)?)$","i");
  hre_t re_quit = hre_compile("^quit$","i");
  hre_t re_repeat = hre_compile("^repeat\\s+(off|list|track)$","i");
  hre_t re_again = hre_compile("^again$","i");
  hre_t re_scan = hre_compile("^scan\\s+(.*)$","i");
  
  file_info_t *history_file = mc_take_over(file_info_new_home(".btb_playlist"));
  printf("history file: %s\n", file_info_absolute_path(history_file));
  printf("history file: %s\n", file_info_path(history_file));
  if (file_info_exists(history_file)) {
    read_history(file_info_absolute_path(history_file));
  }
  
  i18n_set_language("nl");
  printf(_("Starting btb_playlist\n"));

  playlist_player_t *player = playlist_player_new();

  while (!stop) {
    char* line = readln(">", player);
    hre_trim(line);
    if (hre_has_match(re_quit, line)) {
      stop = el_true;
    } else if (hre_has_match(re_load, line)) {
      hre_matches m = hre_match(re_load, line);
      hre_match_t *mplay = hre_matches_get(m, 1);
      hre_match_t *match = hre_matches_get(m, 2);
      char* file = mc_strdup(hre_match_str(match));
      char* play = mc_strdup(hre_match_str(mplay));
      hre_matches_destroy(m);
      printf("loading '%s', '%s'\n", file, play);
      file_info_t *info = file_info_new(file);
      if (file_info_exists(info)) {
        if (file_info_is_file(info)) {
          if (file_info_can_read(info)) {
            const char *mediafile = NULL;
            track_array array;
            if (strcasecmp(file_info_ext(info),"cue") == 0) {
              array = tracks_from_cue(file_info_absolute_path(info));
              track_t* t = track_array_get(array, 0);
            } else {
              array = tracks_from_media(file_info_absolute_path(info));
            }
            playlist_t* pl = playlist_new("playlist");
            int i;
            for(i=0; i < track_array_count(array); ++i) {
              playlist_append(pl, track_array_get(array, i));
            }
            playlist_player_set_playlist(player, pl);
            track_array_destroy(array);
          }
        }
      }
      file_info_destroy(info);      
      if (strcasecmp(play,"&play")==0) { playlist_player_play(player); }
      mc_free(file);
      mc_free(play);
    } else if (hre_has_match(re_play, line)) {
      playlist_player_play(player);
    } else if (hre_has_match(re_pause, line)) {
      playlist_player_pause(player);
    } else if (hre_has_match(re_seek, line)) {
      hre_matches m = hre_match(re_seek, line);
      hre_match_t* match = hre_matches_get(m, 1);
      char* position = mc_strdup(hre_match_str(match));
      hre_matches_destroy(m);
      double s = atof(position);
      int ms = s * 1000;
      mc_free(position);
      playlist_player_seek(player, ms); 
    } else if (hre_has_match(re_next, line)) {
      playlist_player_next(player);
    } else if (hre_has_match(re_previous, line)) {
      playlist_player_previous(player);
    } else if (hre_has_match(re_track, line)) {
      hre_matches m = hre_match(re_track, line);
      hre_match_t* match = hre_matches_get(m, 1);
      char* nr = mc_strdup(hre_match_str(match));
      hre_matches_destroy(m);
      int index = atoi(nr);
      mc_free(nr);
      printf("setting track %d\n",index);
      playlist_player_set_track(player, index);
    } else if (hre_has_match(re_repeat, line)) {
      hre_matches m = hre_match(re_repeat, line);
      hre_match_t* match = hre_matches_get(m, 1);
      if (strcasecmp(hre_match_str(match),"track") == 0) {
        playlist_player_set_repeat(player, PLP_TRACK_REPEAT);
      } else if (strcasecmp(hre_match_str(match),"list") == 0) {
        playlist_player_set_repeat(player, PLP_LIST_REPEAT);
      } else {
        playlist_player_set_repeat(player, PLP_NO_REPEAT);
      }
      hre_matches_destroy(m);
    } else if (hre_has_match(re_again, line)) {
      playlist_player_again(player);
    } else if (hre_has_match(re_scan, line)) {
      hre_matches m = hre_match(re_scan, line);
      hre_match_t* match = hre_matches_get(m, 1);
      printf("scanning %s\n", hre_match_str(match));
      library_t* library = library_new();
      printf("calling scan_library\n");
      //scan_library(library, hre_match_str(match), library_cb);
      printf("\n");
      printf("library: %d tracks\n", library_count(library));
      printf("done scanning, destroying library\n");
      library_destroy(library);
      printf("library destroyed\n");
      hre_matches_destroy(m);
      printf("matches destroyed\n");
    }
    
    mc_free(line);
  }

  playlist_player_destroy(player);
  
  printf("%d\n",write_history(file_info_absolute_path(history_file)));
  
  file_info_destroy(history_file);
  hre_destroy(re_load);
  hre_destroy(re_play);
  hre_destroy(re_pause);
  hre_destroy(re_quit);
  hre_destroy(re_seek);
  hre_destroy(re_track);
  hre_destroy(re_next);
  hre_destroy(re_previous);
  hre_destroy(re_again);
  hre_destroy(re_repeat);
  hre_destroy(re_scan);
  
  return 0;
}