Exemplo n.º 1
0
/*
 * Description: Plays a range of tracks from the CD.
 */
static void play_range ()
{
  int		  first ;
  int		  last  ;
  track_info	  tInfo ;
    
  if	( get_track_info( &tInfo ) == false )
	{
	  return ;
	}
  else
  if	((first = valid_input_int( FROM TRACK
				 , tInfo.first_track
				 , tInfo.last_track ) ) == -1 ) 
	{
	  show_error( CANCEL ) ;
	}
  else
  if	((last  = valid_input_int( TO TRACK
				 , tInfo.first_track
				 , tInfo.last_track ) ) == -1 ) 
	{
	  show_error( CANCEL ) ;
	}
  else
  if	( cd_play_range( first, last ) != 0 )
	{
  	  show_error( ERROR, cd_error ) ;
	}
}
Exemplo n.º 2
0
/* reads info from file and updates the ID3 tags of
 @selected_tracks. */
void mserv_from_file_tracks(GList *selected_tracks) {
    GList *gl;

    if (selected_tracks == NULL) {
        gtkpod_statusbar_message(_("Nothing to update"));
        return;
    }

    block_widgets();
    for (gl = selected_tracks; gl; gl = gl->next) {
        ExtraTrackData *etr;
        Track *track = gl->data;
        gchar *buf;
        g_return_if_fail (track);
        etr = track->userdata;
        g_return_if_fail (etr);

        buf = get_track_info(track, TRUE);
        gtkpod_statusbar_message (_("Retrieving mserv data %s"), buf);
        g_free(buf);
        if (etr->pc_path_locale && *etr->pc_path_locale)
            update_mserv_data_from_file(etr->pc_path_locale, track);
        else
            display_mserv_problems(track, _("no filename available"));
    }
    release_widgets();
    /* display log of problems with mserv data */
    display_mserv_problems(NULL, NULL);
    gtkpod_statusbar_message(_("Updated selected tracks with data from mserv."));
}
Exemplo n.º 3
0
XMLNode get_track_xml(const metadb_handle_ptr track, abort_callback &p_abort) {
	pfc::string8 page = get_track_info(track, p_abort);
	t_size page_wsize = pfc::stringcvt::estimate_utf8_to_wide(page, ~0);
	wchar_t *page_w = new wchar_t[page_wsize];
	pfc::stringcvt::convert_utf8_to_wide(page_w, page_wsize, page, ~0);
	XMLNode xml = XMLNode::parseString(page_w, L"lfm");
	delete[] page_w;
	return xml;
}
Exemplo n.º 4
0
int main(int argc, char *argv[], char **envp)
{
    ripncode_t r;

    config_set_defaults(&r, argv[0]);
    parse_cmdline(&r, argc, argv, envp);

    device_open(&r);
    get_track_info(&r);

    return 0;
}
Exemplo n.º 5
0
/* Logs tracks (@track) that could not be updated with info from mserv
 database for some reason. Pop up a window with the log by calling
 with @track = NULL, or remove the log by calling with @track = -1.
 @txt (if available) is added as an explanation as to why it was
 impossible to retrieve mserv information */
void display_mserv_problems(Track *track, gchar *txt) {
    gchar *buf;
    static gint track_nr = 0;
    static GString *str = NULL;

    if ((track == NULL) && str) {
        if (prefs_get_int("mserv_use") && prefs_get_int("mserv_report_probs") && str->len) { /* Some tracks have had problems. Print a notice */
            buf
                    = g_strdup_printf(ngettext("No mserv information could be retrieved for the following track", "No mserv information could be retrieved for the following %d tracks", track_nr), track_nr);
            gtkpod_confirmation(-1, /* gint id, */
            FALSE, /* gboolean modal, */
            _("mserv data retrieval problem"), /* title */
            buf, /* label */
            str->str, /* scrolled text */
            NULL, 0, NULL, /* option 1 */
            NULL, 0, NULL, /* option 2 */
            TRUE, /* gboolean confirm_again, */
            "mserv_report_probs",/* confirm_again_key,*/
            CONF_NULL_HANDLER, /* ConfHandler ok_handler,*/
            NULL, /* don't show "Apply" button */
            NULL, /* cancel_handler,*/
            NULL, /* gpointer user_data1,*/
            NULL); /* gpointer user_data2,*/
            g_free(buf);
        }
        display_mserv_problems((void *) -1, NULL);
    }

    if (track == (void *) -1) { /* clean up */
        if (str)
            g_string_free(str, TRUE);
        str = NULL;
        track_nr = 0;
        gtkpod_tracks_statusbar_update();
    }
    else if (prefs_get_int("mserv_use") && prefs_get_int("mserv_report_probs") && track) {
        /* add info about it to str */
        buf = get_track_info(track, TRUE);
        if (!str) {
            track_nr = 0;
            str = g_string_sized_new(2000); /* used to keep record */
        }
        if (txt)
            g_string_append_printf(str, "%s (%s)\n", buf, txt);
        else
            g_string_append_printf(str, "%s\n", buf);
        g_free(buf);
        ++track_nr; /* count tracks */
    }
}
Exemplo n.º 6
0
/*
 * Description: Shows the current track type.
 */
static void show_audio()
{
  int		  trk ;
  track_info	  tInfo ;
    
  if	( get_track_info( &tInfo ) == false )
	{
	  return ;
	}
  else
  if	((trk = valid_input_int( TRACK	, tInfo.first_track
					, tInfo.last_track ) ) == -1 ) 
	{
	  show_error( CANCEL ) ;
	}
  else
	{
	  printf( TRACK " %d is %s\n", trk, AUDIO(trk) ) ;
	}
}
Exemplo n.º 7
0
/*
 * Description: Plays a random track from the CD.
 */
static void random_track ()
{
  int		  ct ;
  track_info	  tInfo ;
    
  if	( get_track_info( &tInfo ) == false )
	{
	  return ;
	}
    
  srand	( time (NULL ) ) ;
    
  ct	 = (( rand () % ( tInfo.last_track + 1 - tInfo.first_track ) )
		       + tInfo.first_track ) ;

  if	( cd_play_from( ct ) != 0 )
	{
  	  show_error( ERROR, cd_error ) ;
	}
}
Exemplo n.º 8
0
/*
 * Description: Displays the CD Table Of Contents
 */
static void show_toc ()
{
  int  		i ;
  int		no ;
  track_info	tInfo ;
    
  if	( get_track_info( &tInfo ) == false )
	{
	  return ;
	}

  no	= tInfo.last_track - tInfo.first_track + 1 ;
        
  printf( TRACK "  Type  (%d tracks)\n", no ) ;
    
  for	( i = tInfo.first_track; i <= tInfo.last_track; i++ ) 
	{
          printf( "  %2d   %s\n", i, AUDIO(i) ) ;
	}
}
Exemplo n.º 9
0
/*
 * Description: Plays a track from the CD.
 */
static void play_track ()
{
  int		  trk ;
  track_info	  tInfo ;
    
  if	( get_track_info( &tInfo ) == false )
	{
	  return ;
	}
  else
  if	((trk = valid_input_int( TRACK	, tInfo.first_track
					, tInfo.last_track ) ) == -1 ) 
	{
	  show_error( CANCEL ) ;
	}
  else
  if	( cd_play( trk ) != 0 )
	{
  	  show_error( ERROR, cd_error ) ;
	}
}
Exemplo n.º 10
0
/*
 * Description: Plays the previous track from the CD.
 */
static void back_track ()
{
  int		  ct ;
  track_info	tInfo ;
    
  if	( get_track_info( &tInfo ) == false )
	{
	  return ;
	}

  ct	= ( cd_current_track() - 1 ) % tInfo.last_track ;

  if	( ct < 1 )
	{
	  ct =  tInfo.last_track ;
	}

  if	( cd_play_from( ct ) != 0 )
	{
  	  show_error( ERROR, cd_error ) ;
	}
}
Exemplo n.º 11
0
/*
 * Description: Displays minimal information regardin gthe current track.
 */
static void show_info ()
{
  int		i ;
  int		no ;
  track_info	tInfo ;
    
  if	( get_track_info( &tInfo ) == false )
	{
	  return ;
	}

  i	= cd_current_track() ;
  no	= tInfo.last_track - tInfo.first_track + 1 ;
    
  if	( i > 0 )
	{
          printf ("Playing track %d (%d tracks)\n", i, no ) ;
	}
  else
	{
          printf ("Not playing (%d tracks)\n", no ) ;
	}
}
Exemplo n.º 12
0
gboolean update_track_info(track_t *t)
{
	gchar dummy[10], *markup = NULL, *markupProps = NULL;
	gint i = 0;
	GdkPixbuf *starPix = NULL;
	PangoLayout *layout = NULL;


	get_track_info(&t->track);
	if (!validate_track_info(&t->track)) {
		g_print("Malformed track data\n");
		gtk_main_quit();
	}


	if (t->track.changed) {
		gtk_image_set_from_file(GTK_IMAGE(t->trackw.image), t->track.artworkId);


		markupProps = g_strdup("<span font='Sans 11' font_weight='bold' color='#FFFFFF'>%s</span>");


		t->track.x.name = 0;
		t->track.x.name2 = 0;

		markup = g_markup_printf_escaped(markupProps, t->track.name);
		gtk_label_set_markup(GTK_LABEL(t->trackw.label.name), markup);
		layout = gtk_label_get_layout(GTK_LABEL(t->trackw.label.name));
		pango_layout_get_pixel_size(PANGO_LAYOUT(layout), &t->track.nameLen, NULL);

		if (t->track.nameLen > SCROLL_SIZE_W) {
			if (t->track.nameScroll)
				g_source_remove(t->track.nameTag);
			t->track.nameScroll = TRUE;
			t->track.nameTag = g_timeout_add(SCROLL_SPEED, (GSourceFunc) scroll_label_name, t);
		} else if (t->track.nameScroll) {
			/* if the previous label was scrolled and this one doesn't need do
			 * it stops the scrolling and puts the label at it's origin. Failure to do
			 * so causes the new label to be displayed at the last position the previous
			 * label was scrolled. */
			g_source_remove(t->track.nameTag);
			gtk_layout_move(GTK_LAYOUT(t->trackw.layout.name), t->trackw.label.name, 0, 0);
			t->track.nameScroll = FALSE;
		}
		g_free(markup);


		t->track.x.artist = 0;
		t->track.x.artist2 = 0;

		markup = g_markup_printf_escaped(markupProps, t->track.artist);
		gtk_label_set_markup(GTK_LABEL(t->trackw.label.artist), markup);
		layout = gtk_label_get_layout(GTK_LABEL(t->trackw.label.artist));
		pango_layout_get_pixel_size(PANGO_LAYOUT(layout), &t->track.artistLen, NULL);

		if (t->track.artistLen > SCROLL_SIZE_W-23) {
			if (t->track.artistScroll)
				g_source_remove(t->track.artistTag);
			t->track.artistScroll = TRUE;
			t->track.artistTag = g_timeout_add(SCROLL_SPEED, (GSourceFunc) scroll_label_artist, t);
		} else if (t->track.artistScroll) {
			g_source_remove(t->track.artistTag);
			gtk_layout_move(GTK_LAYOUT(t->trackw.layout.artist), t->trackw.label.artist, 0, 0);
			t->track.artistScroll = FALSE;
		}
		g_free(markup);


		t->track.x.album = 0;
		t->track.x.album2 = 0;

		markup = g_markup_printf_escaped(markupProps, t->track.album);
		gtk_label_set_markup(GTK_LABEL(t->trackw.label.album), markup);
		layout = gtk_label_get_layout(GTK_LABEL(t->trackw.label.album));
		pango_layout_get_pixel_size(PANGO_LAYOUT(layout), &t->track.albumLen, NULL);

		if (t->track.albumLen > SCROLL_SIZE_W-40) {
			if (t->track.albumScroll)
				g_source_remove(t->track.albumTag);
			t->track.albumScroll = TRUE;
			t->track.albumTag = g_timeout_add(SCROLL_SPEED, (GSourceFunc) scroll_label_album, t);
		} else if (t->track.albumScroll) {
			g_source_remove(t->track.albumTag);
			gtk_layout_move(GTK_LAYOUT(t->trackw.layout.album), t->trackw.label.album, 0, 0);
			t->track.albumScroll = FALSE;
		}
		g_free(markup);
		g_free(markupProps);


		markupProps = g_strdup("<span font='Sans 11' color='#FFFFFF'>%s</span>");
		markup = g_markup_printf_escaped(markupProps, t->track.genre);
		gtk_label_set_markup(GTK_LABEL(t->trackw.genre), markup);
		g_free(markup);

		g_sprintf(dummy, "%d", t->track.year);
		markup = g_markup_printf_escaped(markupProps, dummy);
		gtk_label_set_markup(GTK_LABEL(t->trackw.year), markup);
		g_free(markup);
		dummy[0] = '\0';

		format_time(dummy, t->track.length);
		markup = g_markup_printf_escaped(markupProps, dummy);
		gtk_label_set_markup(GTK_LABEL(t->trackw.length), markup);
		g_free(markup);
		g_free(markupProps);
		dummy[0] = '\0';


		gtk_range_set_range(GTK_RANGE(t->trackw.slider), 0, t->track.length);

		/* set the rating */
		starPix = gdk_pixbuf_new_from_xpm_data(starFull_xpm);
		for (i = 1; i <= t->track.rating; i++)
			gtk_image_set_from_pixbuf(GTK_IMAGE(t->trackw.stars[i-1]), GDK_PIXBUF(starPix));
		g_object_unref(starPix);
		starPix = gdk_pixbuf_new_from_xpm_data(starHollow_xpm);
		while (i <= 5) {
			gtk_image_set_from_pixbuf(GTK_IMAGE(t->trackw.stars[i-1]), GDK_PIXBUF(starPix));
			i++;
		}
		g_object_unref(starPix);
	}


	markupProps = g_strdup("<span font='Sans 11' color='#FFFFFF'>%s</span>");

	g_sprintf(dummy, "%d", t->track.playcount);
	markup = g_markup_printf_escaped(markupProps, dummy);
	gtk_label_set_markup(GTK_LABEL(t->trackw.playcount), markup);
	g_free(markup);
	dummy[0] = '\0';

	format_time(dummy, t->track.position);
	markup = g_markup_printf_escaped(markupProps, dummy);
	gtk_label_set_markup(GTK_LABEL(t->trackw.position), markup);
	g_free(markup);
	g_free(markupProps);
	dummy[0] = '\0';


	gtk_range_set_fill_level(GTK_RANGE(t->trackw.slider), t->track.position);
	gtk_range_set_value(GTK_RANGE(t->trackw.slider), t->track.position);


	/* NOTE: reuses the starPix pixbuf */
	if (t->playerInfo.counter == 4) { /* 2 seconds on currently UPDATE_SPEED */
		if (!get_player_info(&t->playerInfo))
				return FALSE;
		else {
			if (t->playerInfo.status) {
				starPix = gdk_pixbuf_new_from_xpm_data(pause_xpm);
				gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.playPause), starPix);
				g_object_unref(starPix);
			} else {
				starPix = gdk_pixbuf_new_from_xpm_data(play_xpm);
				gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.playPause), starPix);
				g_object_unref(starPix);
			}

			if (t->playerInfo.repeat == 0) {
				starPix = gdk_pixbuf_new_from_xpm_data(repeatOff_xpm);
				gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.repeat), starPix);
				g_object_unref(starPix);
			} else if (t->playerInfo.repeat == 1) {
				starPix = gdk_pixbuf_new_from_xpm_data(repeatAll_xpm);
				gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.repeat), starPix);
				g_object_unref(starPix);
			} else {
				starPix = gdk_pixbuf_new_from_xpm_data(repeatSingle_xpm);
				gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.repeat), starPix);
				g_object_unref(starPix);
			}

			if (t->playerInfo.shuffle) {
				starPix = gdk_pixbuf_new_from_xpm_data(shuffleOn_xpm);
				gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.shuffle), starPix);
				g_object_unref(starPix);
			} else {
				starPix = gdk_pixbuf_new_from_xpm_data(shuffleOff_xpm);
				gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.shuffle), starPix);
				g_object_unref(starPix);
			}
		}

		t->playerInfo.counter = 0;
	}


	free_track_info(&t->track);
	t->playerInfo.counter++;

	return TRUE;
}
Exemplo n.º 13
0
/** Read CD TOC and set CD information. */
static void
read_toc(CdIo_t *p_cdio)
{
  track_t i;

  action("read toc...");

  memset(cd_info, 0, sizeof(cd_info));
  title[0] = artist[0] = genre[0] = category[0] = year[0] = '\0';

  i_first_track       = cdio_get_first_track_num(p_cdio);
  i_last_track        = cdio_get_last_track_num(p_cdio);
  i_tracks            = cdio_get_num_tracks(p_cdio);
  i_first_audio_track = i_first_track;
  i_last_audio_track  = i_last_track;


  cdio_audio_get_volume(p_cdio, &audio_volume);
  for (i_vol_port=0; i_vol_port<4; i_vol_port++) {
    if (audio_volume.level[i_vol_port] > 0) break;
  }
  
  if ( CDIO_INVALID_TRACK == i_first_track ||
       CDIO_INVALID_TRACK == i_last_track ) {
    xperror("read toc header");
    b_cd = false;
    b_record = false;
    i_last_display_track = CDIO_INVALID_TRACK;
  } else {
    b_cd = true;
    i_data = 0;
    get_disc_info(p_cdio);
    for (i = i_first_track; i <= i_last_track+1; i++) {
      int s;
      if ( !cdio_get_track_msf(p_cdio, i, &(toc[i])) )
      {
        xperror("read toc entry");
        b_cd = false;
        return;
      }
      if ( TRACK_FORMAT_AUDIO == cdio_get_track_format(p_cdio, i) ) {
        
        if (i != i_first_track) 
          {
            s = cdio_audio_get_msf_seconds(&toc[i]) 
              - cdio_audio_get_msf_seconds(&toc[i-1]);
            snprintf(cd_info[i-1].length, sizeof(cd_info[0].length), 
                     "%02d:%02d",
                     s / CDIO_CD_SECS_PER_MIN,  s % CDIO_CD_SECS_PER_MIN);
          }
      } else {
        if ((i != i_last_track+1) ) {
          i_data++;
          if (i == i_first_track) {
            if (i == i_last_track)
              i_first_audio_track = CDIO_CDROM_LEADOUT_TRACK;
            else
              i_first_audio_track++;
          }
        }
      }
      get_track_info(i);
    }
    b_record = true;
    read_subchannel(p_cdio);
    if (auto_mode && sub.audio_status != CDIO_MMC_READ_SUB_ST_PLAY)
      play_track(1, CDIO_CDROM_LEADOUT_TRACK);
  }
  action("");
  if (!b_all_tracks)
    display_cdinfo(p_cdio, i_tracks, i_first_track);
}
Exemplo n.º 14
0
int mps_librarydb_traverse_directory(char *directoryName, sqlite3 *db,
				     long caller_file_path_id) 
{
  DIR *directoryStreamPointer;
  struct dirent *directoryElementPointer;
  struct stat statStructure;
  char filePathCopy[MPS_MAX_LIBRARY_PATH_LENGTH];
  char fullFilePath[MPS_MAX_LIBRARY_PATH_LENGTH];
  char escapedFileName[MPS_MAX_LIBRARY_PATH_LENGTH];
  char escapedTitle[MPS_MAX_TRACK_INFO_FIELD_LENGTH];
  char escapedArtist[MPS_MAX_TRACK_INFO_FIELD_LENGTH];
  char escapedAlbum[MPS_MAX_TRACK_INFO_FIELD_LENGTH];
  char escapedGenre[MPS_MAX_TRACK_INFO_FIELD_LENGTH];
  char escapedDname[NAME_MAX+1];
  char *zErrMsg = 0;
  int i, sqlite_rc, gti_rc, rv = MPS_LIBRARYDBD_SUCCESS;
  int updated_track_count, updated_file_path_count;
  int tempErrno;
  long artistId, albumId, filePathId;
  char sqlStatement[MAX_SQL_STATEMENT_LENGTH];
  char whereClause[MAX_SQL_STATEMENT_LENGTH];
  mps_library_track_info_t track_info;

  MPS_DBG_PRINT("Entering %s(%s, 0x%08x, %d)\n", __func__, 
		directoryName, (unsigned)db, caller_file_path_id);

  if ((directoryStreamPointer = opendir(directoryName))
      == NULL) {
    MPS_LOG("Error: Couldn't open \"%s\"\n", directoryName);
    goto OUT;
  }
                  
  while (1) {
    errno = 0;
    if ((directoryElementPointer = readdir(directoryStreamPointer))
        == NULL) {
      tempErrno=errno;
      if (tempErrno ==0) {
        break;
      }
      else {
        MPS_LOG("readdir() returned NULL with errno==%d\n", tempErrno);
        sleep(10);
        continue;
      }
    }
    MPS_DBG_PRINT("Top of while() loop. d_name=\"%s\"\n", 
		  directoryElementPointer->d_name);

    /* zero the track_info structure */
    memset(&track_info, 0, sizeof(mps_library_track_info_t));

    //Construct full path name in source directory 
    // could I just use realpath()?
    strcpy(fullFilePath, directoryName);
    strcat(fullFilePath, "/");
    strcat(fullFilePath, directoryElementPointer->d_name);
    
    track_info.parent_path_id = caller_file_path_id;
    strncpy(track_info.file_name, directoryElementPointer->d_name,
	    MPS_MAX_TRACK_INFO_FIELD_LENGTH);

    // escape the ' characters for sqlite's benefit
    copy_and_sqlite_escape(escapedFileName, 
                           track_info.file_name, 
                           MPS_MAX_LIBRARY_PATH_LENGTH); 
    
    stat(fullFilePath, &statStructure);
    
    if (S_ISREG(statStructure.st_mode)
	&& *(directoryElementPointer->d_name) != '.') {
      MPS_DBG_PRINT("Is a regular file\n");
      
      track_info.file_type = mps_get_file_type(directoryElementPointer->d_name);

      if (track_info.file_type == MPS_LIBRARY_UNKNOWN) {
	MPS_DBG_PRINT("\"%s\" has an unrecognized file type\n", 
		      directoryElementPointer->d_name);
	continue;
      }

      track_info.file_length = statStructure.st_size;
      track_info.file_last_modification = statStructure.st_mtime;

      if (*state == LIBRARYDBD_STATE_UPDATINGDB) {
	
	snprintf(sqlStatement, MAX_SQL_STATEMENT_LENGTH, 
		 "UPDATE mps_library_titles SET db_version=%ld "
		 "WHERE file_length=%ld AND file_last_modification=%ld "
		 "AND parent_path_id=%ld AND file_name='%s'; ",
		 /* "LIMIT 1; ", -- this might work if I build from 
		    non-"amalgamation" source */
		 dbVersion, track_info.file_length, 
		 track_info.file_last_modification,  
		 caller_file_path_id, escapedFileName);

	MPS_DBG_PRINT("Calling sqlite3_exec on \"%s\"\n", sqlStatement);
	sqlite_rc = sqlite3_exec(db, sqlStatement, NULL, 0, &zErrMsg);
	
	if( sqlite_rc != SQLITE_OK ){
	  MPS_LOG("SQL error: %s\n", zErrMsg);
	  sqlite3_free(zErrMsg);
	  return MPS_LIBRARYDBD_FAILURE;
	}
	else {
	  updated_track_count = sqlite3_changes(db);
	}

	if (updated_track_count > 0) {
	  MPS_DBG_PRINT("File \"%s\" doesn't appear to have changed, updated scan_counter = %d\n", 
			fullFilePath, dbVersion);
	}
      }

      if (*state == LIBRARYDBD_STATE_CREATINGDB ||
	  (*state == LIBRARYDBD_STATE_UPDATINGDB && updated_track_count == 0)){
	
	gti_rc = get_track_info(fullFilePath, &track_info);
	if (gti_rc != MPS_LIBRARYDBD_SUCCESS) {
	  MPS_DBG_PRINT("get_track_info() returned MPS_LIBRARYDBD_FAILURE\n");
	  // Don't continue and add entry if get_track_info failed.
	  continue; 
	}

	MPS_DBG_PRINT("Adding file \"%s\"\n", fullFilePath);
	highestTitleId++;

        sanitize_and_copy (escapedTitle, 
                           track_info.title, 
                           MPS_MAX_TRACK_INFO_FIELD_LENGTH);
        if (IS_UNKNOWN(escapedTitle)) {
          sprintf(escapedTitle, "Unknown Title (%s)", escapedFileName);
        }

        sanitize_and_copy (escapedAlbum, 
                           track_info.album, 
                           MPS_MAX_TRACK_INFO_FIELD_LENGTH);
        if (IS_UNKNOWN(escapedAlbum)) {
          strcpy(escapedAlbum, "Unknown Album");
        }

        sanitize_and_copy (escapedArtist, 
                           track_info.artist, 
                           MPS_MAX_TRACK_INFO_FIELD_LENGTH); 
        if (IS_UNKNOWN(escapedArtist)) {
          strcpy(escapedArtist, "Unknown Artist");
        }

	copy_and_sqlite_escape(escapedGenre, 
                               track_info.genre, 
                               MPS_MAX_TRACK_INFO_FIELD_LENGTH); 
		
	/* update artist table */
	artistId = update_artist_table(escapedArtist, db);
	
	/* update albums table */
	albumId = update_album_table(escapedAlbum, artistId, db);

	snprintf(sqlStatement, MAX_SQL_STATEMENT_LENGTH, 
		 "insert into mps_library_titles "
		 "values("
		 "%ld, "   // title_id int64
		 "%ld, "   // db_version int64
		 "%ld, "   // file_length int64
		 "%ld, "   // file_last_modification int64
		 "%ld, "   // parent_path_id int64
		 "'%s', "  // file_name text
		 "%d, "    // file_type int
		 "'%s', "  // title text
		 "%ld, "   // album_id int64
		 "%ld, "   // artist_id int64
		 "%d, "    // year int
		 "'%s', "  // genre text
		 "%d, "    // time_length int
		 "%d, "    // play_count int
		 "%ld, "   // last_played int64
		 "%d, "    // ordinal_track_number int
		 "%d, "    // bitrate int
		 "%d, "    // sampling_rate int
		 "%d, "    // channel_mode int
		 "%d, "    // vbr_mode int
		 "%ld "    // filesystem_id int64
		 "); ",
		 highestTitleId, dbVersion,
		 track_info.file_length, track_info.file_last_modification,
		 caller_file_path_id, escapedFileName, track_info.file_type,
		 escapedTitle, albumId, artistId,
		 track_info.year, escapedGenre, track_info.time_length, 
		 track_info.play_count, track_info.last_played, 
		 track_info.ordinal_track_number, track_info.bitrate,
		 track_info.sampling_rate, track_info.channel_mode, 
		 track_info.vbr_mode, 0L /*fs_id hardcoded */);

	MPS_DBG_PRINT("Calling sqlite3_exec on \"%s\"\n", sqlStatement);	
	sqlite_rc = sqlite3_exec(db, sqlStatement, NULL, 0, &zErrMsg);
	
	if( sqlite_rc != SQLITE_OK ){
	  MPS_LOG("SQL error: %s\n", zErrMsg);
	  sqlite3_free(zErrMsg);
	  highestTitleId--;
	  return MPS_LIBRARYDBD_FAILURE;
	}
	else {
	  numberTitlesAdded++;
	}
      }
    }
    else if (S_ISDIR(statStructure.st_mode)) {
      MPS_DBG_PRINT("Is a directory\n");

      copy_and_sqlite_escape(escapedDname, 
                             directoryElementPointer->d_name, 
                             MPS_MAX_LIBRARY_PATH_LENGTH); 	  
      
      if (strcmp(directoryElementPointer->d_name, ".") &&
	  strcmp(directoryElementPointer->d_name, "..")) {	  

	if (*state == LIBRARYDBD_STATE_UPDATINGDB) {	  
	  snprintf(sqlStatement, MAX_SQL_STATEMENT_LENGTH,
		   "update mps_library_file_path set db_version=%ld "
		   "where parent_id=%ld and name='%s'",
		   dbVersion, caller_file_path_id, escapedDname);
	  
	  MPS_DBG_PRINT("Calling sqlite3_exec on \"%s\"\n", sqlStatement);
	  sqlite_rc = sqlite3_exec(db, sqlStatement, NULL, 0, &zErrMsg);

	  if( sqlite_rc != SQLITE_OK ){
	    MPS_LOG("SQL error: %s\n", zErrMsg);
	    sqlite3_free(zErrMsg);
	    return MPS_LIBRARYDBD_FAILURE;
	  }
	  else {
	    updated_file_path_count = sqlite3_changes(db);
	  }
	  if (updated_file_path_count > 0) {
	    snprintf(whereClause, MAX_SQL_STATEMENT_LENGTH,
		     "parent_id=%ld and name='%s'",
		     caller_file_path_id, escapedDname);
	    rv = mps_librarydb_get_long(db, "mps_library_file_path", "id",
					 whereClause, &filePathId);
	    if (rv < MPS_LIBRARYDBD_SUCCESS) {
	      goto OUT;
	    }
	  }
	}
	if (*state == LIBRARYDBD_STATE_CREATINGDB ||
	    (*state == LIBRARYDBD_STATE_UPDATINGDB && 
	     updated_file_path_count == 0)){
	  filePathId = ++highestFilePathId;
	  snprintf(sqlStatement, MAX_SQL_STATEMENT_LENGTH, 
		   "insert into mps_library_file_path "
		   "values("
		   "%ld, "   // id int64
		   "%ld, "   // parent_id int64
		   "'%s', "  // name text
		   "%ld, "   // db_version int64
		   "%ld "    // filesystem_id int64
		   "); ",
		   highestFilePathId, caller_file_path_id,
		   escapedDname, dbVersion, 0L /* fs_id hard coded */);

	  MPS_DBG_PRINT("Calling sqlite3_exec on \"%s\"\n", sqlStatement);	
	  sqlite_rc = sqlite3_exec(db, sqlStatement, NULL, 0, &zErrMsg);
	  if( sqlite_rc != SQLITE_OK ){
	    MPS_LOG("SQL error: %s\n", zErrMsg);
	    sqlite3_free(zErrMsg);
	    highestFilePathId--;
	    rv = MPS_LIBRARYDBD_FAILURE;
	    goto CLOSE_OUT;
	  }
	  else {
	    numberFilePathsAdded++;
	  }
	}
	MPS_DBG_PRINT("Adding directory \"%s\"\n", fullFilePath); 
	mps_librarydb_traverse_directory(fullFilePath, db, filePathId);
      }
    }
  }

 CLOSE_OUT:  
  closedir(directoryStreamPointer);    
 OUT:
  MPS_DBG_PRINT("Leaving %s() - return value %d\n", __func__, rv);
  return rv;
}