コード例 #1
0
ファイル: track.c プロジェクト: EQ4/musicd
void tracks_free(track_t **tracks)
{
  int i;
  for (i = 0; tracks[i] != NULL; ++i) {
    track_free(tracks[i]);
  }
  free(tracks);
}
コード例 #2
0
ファイル: track.c プロジェクト: benhoskings/textmms
void tlist_uninit(tlist_t *tlist)
{
	for (int i = 0; i < tlist->num; i++)
	{
		track_free(tlist->tracks[i]);
	}
	
	free(tlist->tracks);
	tlist_init(tlist);
}
コード例 #3
0
ファイル: track.c プロジェクト: EQ4/musicd
static track_t *track_create(const char *path, 
                             AVFormatContext *avctx, 
                             int track_index)
{
  track_t *track;
  char *tmp;

  /*av_dump_format(avctx, 0, NULL, 0);*/

  /* For each metadata first try container-level metadata. If no value is
   * found, try stream-specific metadata.
   */

  track = track_new();

  track->file = strcopy(path);

  track->title = copy_metadata(avctx, "title") ? : copy_metadata(avctx, "song");

  if (!track->title) {
    /* No title in metadata, use plain filename (no basename, it's crap). */
    for (tmp = (char *)path + strlen(path);
        tmp > path && *(tmp - 1) != '/';
        --tmp) { }
    track->title = strcopy(tmp);
  }

  track->trackindex = track_index;

  tmp = get_metadata(avctx, "track");
  if (tmp) {
    sscanf(tmp, "%d", &track->track);
  } else {
    track->track = track_index;
  }

  track->artist = copy_metadata(avctx, "artist") ? : copy_metadata(avctx, "author");
  track->album = copy_metadata(avctx, "album") ? : copy_metadata(avctx, "game");
  track->albumartist = copy_metadata(avctx, "albumartist");

  if (avctx->duration > 0) {
    track->duration = avctx->duration / (double)AV_TIME_BASE;
  } else {
    track->duration =
      avctx->streams[0]->duration * av_q2d(avctx->streams[0]->time_base);
  }

  if (track->duration <= 0) {
    track_free(track);
    track = NULL;
  }
  return track;
}
コード例 #4
0
ファイル: track.c プロジェクト: benhoskings/textmms
void tlist_del(tlist_t *list, int pos)
{
    if ((pos >= 0) && (pos < list->num))
	{
		track_free(list->tracks[pos]);
		
		list->num--;
		
		for (int i = pos; i < list->num; i++)
		{
			list->tracks[i] = list->tracks[i + 1];
		}
	}
}
コード例 #5
0
ファイル: lyrics.c プロジェクト: EQ4/musicd
static void *task_func(void *args)
{
  int64_t id = *((int64_t *)args);
  track_t *track = library_track_by_id(id);
  lyrics_t *lyrics;

  if (!track) {
    free(args);
    return NULL;
  }

  lyrics = lyrics_fetch(track);
  library_lyrics_set(id, lyrics);

  lyrics_free(lyrics);
  free(args);
  track_free(track);
  return NULL;
}
コード例 #6
0
// Datei in Datenbank eintragen
gboolean register_file (gchar *file)
{
	TagLib_File *tagfile;
	TagLib_Tag *tag;
	
	gint id_track;
	gchar *line;
	
	TrackDetails *track;
	
	// Prüfen ob die Datei gültig ist
	tagfile = taglib_file_new (file);
	if (tagfile == NULL) {
		return FALSE;
	}
	
	// Prüfen ob wir Tags haben
	tag = taglib_file_tag (tagfile);
	if (tagfile == NULL) {
		return FALSE;
	}
	
	// Track hinzufügen
	track = track_new ();
	track->number = taglib_tag_track (tag);
	track->path = g_strdup (file);
	track->title = g_strdup (taglib_tag_title (tag));
	track->artist->name = g_strdup (taglib_tag_artist (tag));
	track->album->title = g_strdup (taglib_tag_album (tag));
	track->album->genre = g_strdup (taglib_tag_genre (tag));
	id_track = db_track_add (track);
	
	line = g_strdup_printf ("Importiert: %s - %s (%s)", track->artist->name,
							track->title, track->album->title);
	settings_import_messages_add (line);
	g_free (line);
	
	// Speicher freigeben
	track_free (track);
	taglib_file_free (tagfile);
	
	return TRUE;
}
コード例 #7
0
ファイル: stream.c プロジェクト: EQ4/musicd
void stream_close(stream_t *stream)
{
  if (!stream) {
    return;
  }

  track_free(stream->track);

  av_free_packet(&stream->src_packet);
  av_free_packet(&stream->encode_packet);

  avcodec_free_frame(&stream->decode_frame);
  avcodec_free_frame(&stream->resample_frame);
  avcodec_free_frame(&stream->encode_frame);

  av_audio_fifo_free(stream->src_buf);

  resampler_free(&stream->resampler);
  
  if (stream->decoder) {
    avcodec_close(stream->decoder);
  }
  if (stream->encoder) {
    avcodec_close(stream->encoder);
    av_free(stream->encoder);
  }

  av_free(stream->dst_iobuf);
  av_free(stream->dst_ioctx);

  av_free(stream->resample_buf);
  av_free(stream->encode_buf);

  if (stream->src_ctx) {
    avformat_close_input(&stream->src_ctx);
  }
  if (stream->dst_ctx) {
    avformat_free_context(stream->dst_ctx);
  }

  free(stream);
}
コード例 #8
0
ファイル: track.c プロジェクト: pa345/lib
track_workspace *
track_alloc(void)
{
    track_workspace *w;

    w = calloc(1, sizeof(track_workspace));
    if (!w)
        return 0;

    w->ntot = TRACK_MAX;
    w->tracks = malloc(w->ntot * sizeof(track_data));
    if (!w->tracks)
    {
        track_free(w);
        return 0;
    }

    w->msynth_workspace_p = msynth_alloc(20, 1, NULL);

    w->n = 0;

    return w;
} /* track_alloc() */
コード例 #9
0
ファイル: cue.c プロジェクト: EQ4/musicd
/**
 * @todo FIXME Multiple files in same cue sheet
 * @todo FIXME Rewrite this garbage
 */
bool cue_read(const char *cuepath, int64_t directory)
{
  bool result = true;
  
  FILE *file;
  char *directory_path, *path, *path2;
  
  bool header_read = false;
  
  char album[512], albumartist[512];
  char line[1024], instr[16], string1[512], *ptr;
  
  int64_t track_file;
  
  struct stat status;
  
  //char file[strlen(path) + 1024 + 2], cuefile[strlen(path) + 1024 + 2];
  
  int i;
  
  int index, mins, secs, frames;
  /* Track is stored in prev_track until index of the following track is known.
   * This is mandatory for figuring out the track's length. Last track's
   * length is calculated from file's total length. */
  track_t *prev_track = NULL, *track = NULL, *file_track = NULL;
  
  file = fopen(cuepath, "r");
  if (!file) {
    musicd_perror(LOG_ERROR, "cue", "can't open file %s", cuepath);
    return false;
  }
  
  directory_path = malloc(strlen(cuepath));
  
  /* Extract directory path. */
  for (i = strlen(cuepath) - 1; i > 0 && cuepath[i] != '/'; --i) { }
  strncpy(directory_path, cuepath, i);
  directory_path[i] = '\0';
  
  /* Directory + 256 4-byte UTF-8 characters + '/' + '\0', more than needed. */
  path = malloc(strlen(directory_path) + 1024 + 2);
  path2 = malloc(strlen(directory_path) + 1024 + 2);
  
  album[0] = '\0';
  albumartist[0] = '\0';
  
  /* Check for BOM, seek back if not found. */
  fread(line, 1, 3, file);
  if (line[0] != (char)0xef
   || line[1] != (char)0xbb
   || line[2] != (char)0xbf) {
    fseek(file, 0, SEEK_SET);
  }

  while (read_line(file, line, sizeof(line))) {
    /* Read instruction, up to 15 characters. */
    if (sscanf(line, "%15s", instr) < 1) {
      continue;
    }
    
    
    /* Skip comments. */
    if (!strcmp(instr, "REM")) {
      continue;
    }
    
    ptr = line + strlen(instr) + 1;
    if (ptr[0] == '"') {
      ptr += read_string(ptr, string1) + 1;
    }
    
    if (!strcmp(instr, "PERFORMER")) {
      /*musicd_log(LOG_DEBUG, "cue", "performer: %s", string1);*/
      if (!header_read) {
        strcpy(albumartist, string1);
      } else if (track) {
        free(track->artist);
        track->artist = strcopy(string1);
      }
    } else if (!strcmp(instr, "TITLE")) {
      /*musicd_log(LOG_DEBUG, "cue", "title: %s", string1);*/
      if (!header_read) {
        strcpy(album, string1);
      } else if (track) {
        free(track->title);
        track->title = strcopy(string1);
      }
    } else if (!strcmp(instr, "FILE")) {
      if (file_track) {
        musicd_log(LOG_WARNING, "cue", "multiple FILEs in a single cue sheet"
                                       "(%s) is currently unsupported, sorry",
                                        cuepath);
        break;
      }
      
      header_read = true;
      
      sprintf(path, "%s/%s", directory_path, string1);
      
      if (stat(path, &status)) {
        result = false;
        break;
      }
      
      /* Prioritizing: if there are multiple cue sheets and a cue sheet with
       * same base name as the track file exists, it is used for the track.
       * otherwise, sheet with highest mtime will result to be selected.
       */
      for (i = strlen(path) - 1; i > 0 && path[i] != '.'; --i) { }
      strncpy(path2, path, i);
      strcpy(path2 + i, ".cue");
      
      if (strcmp(path2, cuepath) && stat(path2, &status) == 0) {
        musicd_log(LOG_DEBUG, "cue",
                   "multiple cue sheets for '%s', trying '%s'",
                   path, path2);
        if (cue_read(path2, directory)) {
          break;
        }
      }
      
      file_track = track_from_path(path);
      if (!file_track) {
        break;
      }
      
      track_file = library_file(path, 0);
      if (track_file > 0) {
        /* File already exists, clear associated tracks. */
        library_file_clear(track_file);
      } else {
        track_file = library_file(path, directory);
        if (track_file <= 0) {
          /* Some error... */
          break;
        }
      }
      
      library_file_mtime_set(track_file, status.st_mtime);
      
      musicd_log(LOG_DEBUG, "cue", "audio: %s", path);
      continue;
    }
    
    
    if (!file_track) {
      continue;
    }
    
    if (!strcmp(instr, "TRACK")) {
      sscanf(ptr, "%d %s", &index, string1);
      /*musicd_log(LOG_DEBUG, "cue", "track: %d '%s'", index, string1);*/
      if (track) {
        if (!prev_track) {
          prev_track = track;
        } else {
          prev_track->duration = track->start - prev_track->start;
          library_track_add(prev_track, directory);
          scan_track_added();
          track_free(prev_track);
          prev_track = track;
        }
      }
      
      track = track_new();
      track->cuefile = strcopy(cuepath);
      track->file = strcopy(path);
      track->track = index;
      /* Set artist same as the album artist and replace if track spefific
       * artist is later defined. */
      track->artist = strcopy(albumartist);
      track->album = strcopy(album);
      track->albumartist = strcopy(albumartist);
    }
    
    if (!strcmp(instr, "INDEX")) {
      sscanf(ptr, "%d %d:%d:%d", &index, &mins, &secs, &frames);
      /*musicd_log(LOG_DEBUG, "cue", "index: %d %2.2d:%2.2d.%2.2d", index, mins, secs, frames);*/
      if (index == 1) {
        /* One frame is 1/75 seconds */
        track->start = mins * 60.0 + secs + frames / 75.0;
      }
    }    
    
  }
  
  if (prev_track) {
    prev_track->duration = track->start - prev_track->start;
    library_track_add(prev_track, directory);
    scan_track_added();
    track_free(prev_track);
  }
  if (track) {
    track->duration = file_track->duration - track->start;
    library_track_add(track, directory);
    scan_track_added();
    track_free(track);
  }
  
  track_free(file_track);
  
  fclose(file);
  
  free(directory_path);
  
  free(path);
  free(path2);
  
  return result;
}
コード例 #10
0
ファイル: main.c プロジェクト: jgmp/8play
/*
 * Non-blocking getchar
 * Returns the character if one is available, else it returns -1.
 */
static int
nbgetchar(void)
{
	struct timeval tv = { .tv_sec = 0, .tv_usec = 0 };
	fd_set fds;
	int nr;

	FD_ZERO(&fds);
	FD_SET(STDIN_FILENO, &fds);
	select(STDIN_FILENO + 1, &fds, NULL, NULL, &tv);
	if (FD_ISSET(STDIN_FILENO, &fds))
		nr = getchar();
	else
		nr = -1;
	return nr;
}

static void
play(const char *url, int cflag)
{
	struct mix *mix = NULL;
	char *playtoken;
	int mixid;

	settermios();
	player_init();

	playtoken = getplaytoken();
	if (playtoken == NULL) {
		printf("Could not get a playtoken\n");
		goto end;
	}

	mix = mix_getbyurl(url);
	if (mix == NULL) {
		printf("Mix not found.\n");
		goto end;
	}
start:
	printf("%s by %s\n", mix->name, mix->user);
	playmix(mix->id, playtoken);

	if (cflag && !quitflag) {
		mixid = mix->id;
		mix_free(mix);
		mix = mix_getbysimilar(mixid, playtoken);
		if (mix == NULL)
			printf("Could not get the next mix.\n");
		else
			goto start;
	}
 end:
	mix_free(mix);
	free(playtoken);
	player_exit();
	resettermios();
}

static void
playmix(int mixid, const char *playtoken)
{
	struct track *track;
	int cmd, i;

	track = track_getfirst(mixid, playtoken);
	if (track == NULL) {
		printf("Could not load the playlist.\n");
		return;
	}
	for (i = 1; track != NULL; ++i) {
		printf("%02d. %s - %s\n", i, track->performer, track->name);
		cmd = playtrack(mixid, track, playtoken);
		track_free(track);
		if (quitflag)
			break;
		if (cmd == NEXT)
			track = track_getnext(mixid, playtoken);
		else if (cmd == SKIP)
			track = track_getskip(mixid, playtoken);
		else if (cmd == SKIPMIX)
			break;
	}
}

/*
 * Playtrack plays the track and checks for user input.  It returns a
 * suggestion on what to do next.  It can return NEXT to suggest that the track
 * has finished without user interruption and it is ready for the next track,
 * or it can return SKIP or SKIPMIX.
 */
static int
playtrack(int mixid, struct track *track, const char *playtoken)
{
	struct timespec tm = { .tv_sec = 0, .tv_nsec = 50000000 };
	int ch, cmd = NEXT, reportflag = 0;

	player_play(track->url);
	while (player_getstatus() != STOPPED) {
		if (quitflag) {
			player_stop();
			goto end;
		}
		printtime();
		ch = nbgetchar();
		switch (ch) {
		case 'q':
			printf("Quitting...\n");
			player_stop();
			quitflag = 1;
			goto end;
		case '\n':
		case '\r':
			printf("Skipping...\n");
			if (!track->skipallowedflag) {
				printf("Skip not allowed.\n");
			} else {
				player_stop();
				cmd = SKIP;
				goto end;
			}
			break;
		case '>':
			printf("Skipping mix...\n");
			player_stop();
			cmd = SKIPMIX;
			goto end;
		case 'p':
		case ' ':
			player_togglepause();
			break;
		default:
			break;
		}
		if (!reportflag && player_getposition() > 30) {
			report(track->id, mixid, playtoken);
			reportflag = 1;
		}
		nanosleep(&tm, NULL);
	}
end:
	return cmd;
}

static void
printshortmix(struct mix *mix)
{
	printf("%s\n", mix->url + 1);	/* skip first character */
	printf("\t%s\n", mix->tags);
	if (mix->certification != NULL)
		printf("\tcert: %s\n", mix->certification);
	if (mix->duration < 0) {
		printf("\tplays: %d\tlikes: %d\t(%d tracks)\n",
		    mix->playscount, mix->likescount, mix->trackscount);
	} else {
		printf("\tplays: %d\t likes: %d\t%d min (%d tracks)\n",
		    mix->playscount, mix->likescount, mix->duration / 60,
		    mix->trackscount);
	}
}

static void
query(const char *url)
{
	struct mix *mix;

	mix = mix_getbyurl(url);
	if (mix == NULL) {
		printf("Mix not found.\n");
		goto end;
	}
	printf("Mix name:\t%s ", mix->name);
	printf("(id: %d)\n", mix->id);
	printf("Created by:\t%s ", mix->user);
	printf("(id: %d)\n", mix->userid);
	printf("Description:\n%s\n", mix->description);
	printf("Tags:\t%s\n", mix->tags);
	if (mix->certification)
		printf("Certification:\t%s\n", mix->certification);
	printf("Plays: %d\t likes: %d\t%d min (%d tracks)\n",
	    mix->playscount, mix->likescount, mix->duration / 60,
	    mix->trackscount);
end:
	mix_free(mix);
}

static void
printtime(void)
{
	int duration, position;

	if (player_getstatus() == PAUSED) {
		printf("(paused)       \r");
	} else {
		duration = player_getduration();
		position = player_getposition();
		printf("%02d:%02d/%02d:%02d\r",
		    position / 60, position % 60,
		    duration / 60, duration % 60);
	}
	fflush(stdout);
}
コード例 #11
0
ファイル: necorrJ.c プロジェクト: pa345/lib
int
main(int argc, char *argv[])
{
  const char *peak_file1 = "peak1.dat";
  const char *prof_file1 = "prof1.dat";
  const char *peak_file2 = "peak2.dat";
  const char *prof_file2 = "prof2.dat";
  satdata_mag *data = NULL;
  current_data sat1, sat2;
  peak_workspace *peak_workspace_p;
  struct timeval tv0, tv1;

  sat1.n = 0;
  sat2.n = 0;

  while (1)
    {
      int c;
      int option_index = 0;
      static struct option long_options[] =
        {
          { "curr_file", required_argument, NULL, 'j' },
          { "curr_file2", required_argument, NULL, 'k' },
          { "swarm_file", required_argument, NULL, 's' },
          { 0, 0, 0, 0 }
        };

      c = getopt_long(argc, argv, "j:k:s:", long_options, &option_index);
      if (c == -1)
        break;

      switch (c)
        {
          case 'j':
            fprintf(stderr, "main: reading %s...", optarg);
            read_lc(optarg, &sat1);
            fprintf(stderr, "done (%zu profiles read)\n", sat1.n);
            break;

          case 'k':
            fprintf(stderr, "main: reading %s...", optarg);
            read_lc(optarg, &sat2);
            fprintf(stderr, "done (%zu profiles read)\n", sat2.n);
            break;

          case 's':
            fprintf(stderr, "main: reading %s...", optarg);
            gettimeofday(&tv0, NULL);
            data = satdata_swarm_read_idx(optarg, 0);
            gettimeofday(&tv1, NULL);
            if (!data)
              exit(1);
            fprintf(stderr, "done (%zu points read, %g seconds)\n",
                    data->n, time_diff(tv0, tv1));

            break;

          default:
            print_help(argv);
            exit(1);
            break;
        }
    }

  if (sat1.n == 0)
    {
      print_help(argv);
      exit(1);
    }

  peak_workspace_p = peak_alloc(NCURR);

  if (data)
    {
      track_workspace *track_p = track_alloc();

      fprintf(stderr, "main: separating into tracks...");
      track_init(data, NULL, track_p);
      fprintf(stderr, "done\n");

      /* north hemisphere peak finding */
      analyze_hemisphere(-3.0, 23.0, peak_file1, prof_file1, data, track_p, &sat1);

      /* south hemisphere peak finding */
      analyze_hemisphere(-23.0, 0.0, peak_file2, prof_file2, data, track_p, &sat1);

      satdata_mag_free(data);
      track_free(track_p);
    }
  else if (sat2.n > 0)
    {
      const char *data_file1 = "data.dat.north";
      const char *corr_file1 = "corr.dat.north";
      const char *data_file2 = "data.dat.south";
      const char *corr_file2 = "corr.dat.south";

      fprintf(stderr, "main: searching for northern J peaks in satellite 1...");
      find_J_peaks(5.0, 23.0, -100.0, peak_file1, prof_file1, NULL, NULL, &sat1);
      fprintf(stderr, "done\n");

      fprintf(stderr, "main: searching for northern J peaks in satellite 2...");
      find_J_peaks(5.0, 23.0, -100.0, peak_file2, prof_file2, NULL, NULL, &sat2);
      fprintf(stderr, "done\n");

      correlateJ(data_file1, corr_file1, &sat1, &sat2);

      fprintf(stderr, "main: data printed to %s\n", data_file1);
      fprintf(stderr, "main: correlation data printed to %s\n", corr_file1);

      fprintf(stderr, "main: searching for northern J peaks in satellite 2...");
      find_J_peaks(-23.0, -5.0, -100.0, peak_file1, prof_file1, NULL, NULL, &sat1);
      fprintf(stderr, "done\n");

      fprintf(stderr, "main: searching for northern J peaks in satellite 2...");
      find_J_peaks(-23.0, -5.0, -100.0, peak_file2, prof_file2, NULL, NULL, &sat2);
      fprintf(stderr, "done\n");

      correlateJ(data_file2, corr_file2, &sat1, &sat2);

      fprintf(stderr, "main: data printed to %s\n", data_file2);
      fprintf(stderr, "main: correlation data printed to %s\n", corr_file2);
    }

  peak_free(peak_workspace_p);

  return 0;
} /* main() */