Ejemplo n.º 1
0
static cue_t *mp3cue_readcue_in_hash(const char *path, int update_data)
{
  char *fullpath = make_path(path);
  char *cuefile = isCueFile(fullpath);
  log_debug3("reading cuefile %s for %s", cuefile, fullpath);
  cue_t *cue = (cue_t *) mc_take_over(cue_new(cuefile));
  struct stat st;
  stat(cuefile, &st);
  MK_READONLY(st);
  if (cue != NULL && cue_valid(cue)) {
    int added = 0;
    int i, N;

    // check if cue already exists in hash. If not, create whole cue in hash and read in again.
    for (i = 0, N = cue_count(cue); i < N; i++) {
      cue_entry_t *entry = cue_entry(cue, i);
      char *p = make_path2(path, cue_entry_vfile(entry));

      log_debug2("p=%s", p);
      if (datahash_exists(DATA, p)) {
        // update entry only if requested
        if ( update_data ) {
          // only update the data in d, otherwise we won't be thread safe!
          // Never deallocate an entry in the hash!
          // We also know, that when the track title is changed, there will be a
          // new entry in the hash, so, we get some rubbish but don't care.
          // We update the file sizes and the cue_entry here.

          // So we need a monitor around the file operations that act on the hash
          // data.

          data_entry_t *dd = datahash_get(DATA, p);
          cue_entry_destroy(dd->entry);
          dd->entry=entry;
          dd->st[0]=st;

          // we don't need to update dd->path as dd->path and p must be equal
        }
      } else {
        data_entry_t *d = data_entry_new(p, entry, &st);
        datahash_put(DATA, p, d);
        added = 1;
      }

      mc_free(p);
    }

    if (added) {
      mc_free(cuefile);
      mc_free(fullpath);
      return mp3cue_readcue_in_hash(path, false);
    }
  }

  mc_free(cuefile);
  mc_free(fullpath);
  return cue;
}
Ejemplo n.º 2
0
library_view_t* library_view_new(Backtobasics* btb, library_t* library)
{
  library_view_t* view = (library_view_t*) mc_malloc(sizeof(library_view_t));
  view->btb = btb;
  view->builder = btb->builder;
  view->library = library;
  
  view->playlist_model = mc_take_over(playlist_model_new());
  //view->library_list_changed = el_false;
  //view->library_list_hash = playlist_model_tracks_hash(view->playlist_model);
  
  view->genre_model = string_model_new();
  view->artist_model = string_model_new();
  view->album_model = string_model_new();
  
  view->aspect = GENRE_ASPECT;
  view->previous_aspect = NONE_ASPECT;
  
  playlist_model_set_playlist(view->playlist_model, library_current_selection(view->library, _("Library")));
  
  string_model_set_array(view->genre_model, library_genres(view->library), el_false);
  string_model_set_array(view->artist_model, library_artists(view->library), el_false);
  string_model_set_array(view->album_model, library_albums(view->library), el_false);
  
  view->run_timeout = el_true;
  view->time_in_ms = -1;
  view->len_in_ms = -1;
  view->track_index = -1;
  view->track_id = NULL;
  view->sliding = 0;
  view->repeat = -1;
  
  view->img_w = el_config_get_int(btb_config(view->btb), "image_art.width", 200);
  view->img_h = el_config_get_int(btb_config(view->btb), "image_art.height", 200);
  log_debug3("image art w=%d, h=%d", view->img_w, view->img_h);
  
  view->btn_play = NULL;
  view->btn_pause = NULL;
  view->cols = NULL;
  
  view->ignore_sel_changed = el_false;
  
  view->playlists_model = playlists_model_new(view->library);
  
  view->current_lyric_track_id = NULL;
  
  view->column_layout_changing = el_false;
  
  return view;
}
Ejemplo n.º 3
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;
}