Logo Search packages:      
Sourcecode: xcfa version File versions

cd_cue.c

 /*
 * file      : cd_cue.c
 * project   : xcfa
 * with      : Gtk-2
 *
 * copyright : (C) 2003,2004,2005,2006,2007,2008,2009 by Claude Bulin
 *
 * xcfa - GTK+ implementation of the GNU shell command
 * GNU General Public License
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * OLD ADRESS:
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * NEW ADRESS:
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */


#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include "support.h"

#include <gtk/gtk.h>
#include <glib/gprintf.h>

#include <string.h>
#include <string.h>
#include <stdlib.h>

#include "utils.h"
#include "global.h"
#include "secu.h"
#include "cd_audio.h"
#include "cdtoc.h"
#include "get.h"
#include "scan_cd.h"
#include "cd_cue.h"
#include "options.h"
#include "config_user.h"
#include "win_info.h"
#include "win_choice.h"




typedef struct {
      guint  handler_timeout;
} VAR_CDCUE;

VAR_CDCUE cdcue;

BASE_IOCTL BaseIoctl = { 0, NULL, NULL, NULL, NULL, NULL };





gboolean cdcue_is_alloc (void)
{
      return ((BaseIoctl.Cue == NULL) ? FALSE : TRUE);
}

gint cdcue_get_total_tracks (gchar *buffer)
{
      gchar  **Larrbuf = NULL;
      gint     i;
      gint     piste;
      gchar    *ptr;

      Larrbuf = g_strsplit(buffer, "\n", 0);
      for (i=0; Larrbuf[i]; i++) {
            if (strstr (Larrbuf[i], "TOTAL")) {
                  i --;
                  break;
            }
      }
      ptr = Larrbuf[i];
      while (*ptr == ' ') ptr ++;
      piste = atoi (ptr);
      g_strfreev(Larrbuf);
      return (piste);
}

void cdcue_make_cue_with_cdtoc (CD_TOC *CdToc)
{
      gint  i;
      gchar *Performer = NULL;
      gchar *Title = NULL;
      gchar *Ptr = NULL;
      
      if (BaseIoctl.Cue == NULL) return;

      if (CdToc->TitleCD == NULL) CdToc->TitleCD = g_strdup (" ");
      
      Performer = g_strdup (CdToc->TitleCD);
      if ((Ptr = strchr (Performer, '/')) != NULL) {
            Ptr--;
            while (*Ptr == ' ') Ptr--;
            Ptr ++;
            *Ptr = '\0';
      }

      if ((Ptr = strchr (CdToc->TitleCD, '/')) != NULL) {
            Ptr ++;
            while (*Ptr == ' ') Ptr++;
            Title = g_strdup (Ptr);
      }
      else {
            Title = g_strdup (CdToc->TitleCD);
      }

      /*
      "James Brown / Sex Machine - The Very Best Of James Brown"
      
      PERFORMER "James Brown"
      TITLE "Sex Machine - The Very Best Of James Brown"
      
      
      PERFORMER "Janis Joplin"
      TITLE "Super Hits"
      FILE "01 - Piece Of My Heart.wav" WAVE
        TRACK 01 AUDIO
          PERFORMER "Janis Joplin"
          TITLE "Piece Of My Heart"
          INDEX 01 00:00:00
      */
      
      BaseIoctl.Performer = g_strdup (Performer);
      BaseIoctl.Title     = g_strdup (Title);
      /*BaseIoctl.File      = g_strdup ("XCFA_CUE.wav");*/
      BaseIoctl.File      = g_strdup_printf ("%s.wav", Performer);
      
      for (i = 0; i < BaseIoctl.TotalTracks; i++) {
            BaseIoctl.Cue [ i ].Performer = g_strdup (Performer);
            BaseIoctl.Cue [ i ].Title     = g_strdup (CdToc->TimeTrack [ i ].TitleTrack);
      }
      /*
      g_print ("CdToc->TitleCD         = %s\n", CdToc->TitleCD);
      g_print ("CdToc->TT_Min          = %d\n", CdToc->TT_Min);
      g_print ("CdToc->TT_Sec          = %d\n", CdToc->TT_Sec);
      g_print ("CdToc->Str_ID_CD       = %s\n", CdToc->Str_ID_CD);
      g_print ("CdToc->TotalTracks     = %d\n", CdToc->TotalTracks);
      g_print ("CdToc->NumGenre        = %d\n", CdToc->NumGenre);
      g_print ("CdToc->StrGenre        = %s\n", CdToc->StrGenre);
      g_print ("CdToc->NumYear         = %d\n", CdToc->NumYear);
      g_print ("CdToc->StrYear         = %s\n", CdToc->StrYear);

      g_print ("CdToc->Bool_Connected  = ");
      if (CdToc->Bool_Connected == CONNECT_IS_TRUE)               g_print ("CONNECT_IS_TRUE\n");
      else if (CdToc->Bool_Connected == CONNECT_IS_FALSE)         g_print ("CONNECT_IS_FALSE\n");
      else if (CdToc->Bool_Connected == CONNECT_IS_NO_MATCH_FOUND)      g_print ("CONNECT_IS_NO_MATCH_FOUND\n");

      for (i = 0; i < CdToc->TotalTracks; i++)
            if (CdToc->TimeTrack [ i ].TitleTrack)
                  g_print ("TITLE_%d = %s\n", i, CdToc->TimeTrack [ i ].TitleTrack);
      */
      g_free (Performer);
      Performer = NULL;
      g_free (Title);
      Title = NULL;
}


void cdcue_remove_base_ioctl (void)
{
      BaseIoctl.TotalTracks = 0;
      if (BaseIoctl.Datas != NULL) {
            g_free (BaseIoctl.Datas);
            BaseIoctl.Datas = NULL;
      }
      
      /*g_free (BaseIoctl.PathNameDestFileCue); BaseIoctl.PathNameDestFileCue = NULL;*/
      g_free (BaseIoctl.Performer);       BaseIoctl.Performer = NULL;
      g_free (BaseIoctl.Title);           BaseIoctl.Title = NULL;
      g_free (BaseIoctl.File);            BaseIoctl.File = NULL;
      
      if (BaseIoctl.Cue != NULL) {
            gint i;
            for (i = 0; i < BaseIoctl.TotalTracks; i++) {
                  g_free (BaseIoctl.Cue [ i ].Performer);         BaseIoctl.Cue [ i ].Performer = NULL;
                  g_free (BaseIoctl.Cue [ i ].Title);       BaseIoctl.Cue [ i ].Title = NULL;
                  g_free (BaseIoctl.Cue [ i ].Partiel_Title);     BaseIoctl.Cue [ i ].Partiel_Title = NULL;
            }
            g_free (BaseIoctl.Cue);
            BaseIoctl.Cue = NULL;
      }
}

void cdcue_alloc_base_ioctl (gint p_taille)
{
      gint  index;
      
      cdcue_remove_base_ioctl ();

      BaseIoctl.TotalTracks = p_taille;
      BaseIoctl.Datas = (BASE_IOCTL_DATAS *)g_malloc0 (sizeof(BASE_IOCTL_DATAS) * (p_taille +4));
      
      BaseIoctl.Cue = (CDCUE *)g_malloc0 (sizeof(CDCUE) * (p_taille +4));
      
      /* Aucune extraction */
      for (index = 0; index < p_taille; index ++)
            BaseIoctl.Cue [ index ].BoolExtract = FALSE;
}

void cdcue_set_BoolExtract (gint p_index, gboolean p_flag)
{
      BaseIoctl.Cue [ p_index ].BoolExtract = p_flag;
}

void cdcue_print_base_ioctl (void)
{
      gint   base;
      gint   TempDiv;
      gint   TempMod;
      
      /*
      1. length   12923 [02:52:23]  begin      32 [00:00:32]      cdparanoia [.begin<44 ? 0 : begin][.(length + begin) -1] -d /dev/hdb -O 0 "1.wav"
      2. length   14175 [03:09:00]  begin   12955 [02:52:55]      cdparanoia [.begin][.length -1] -d /dev/hdb -O 0 "2.wav"
      3. length   14627 [03:15:02]  begin   27130 [06:01:55]      cdparanoia [.begin][.length -1] -d /dev/hdb -O 0 "3.wav"
      */    
      
      for (base = 0; base < BaseIoctl.TotalTracks; base++) {
            TempDiv = BaseIoctl.Datas[ base ].length / 75;
            TempMod = BaseIoctl.Datas[ base ].length % 75;
            
            g_print("  %2d. ", base +1);
            g_print("length %7d [%02d:%02d:%02d]  ",
                  BaseIoctl.Datas[ base ].length,
                  BaseIoctl.Datas[ base ].length_min,
                  BaseIoctl.Datas[ base ].length_sec,
                  BaseIoctl.Datas[ base ].length_cent);
            
            TempDiv = BaseIoctl.Datas[ base ].begin / 75;
            TempMod = BaseIoctl.Datas[ base ].begin % 75;
      
            g_print("begin %7d [%02d:%02d:%02d]",
                  BaseIoctl.Datas[ base ].begin,
                  BaseIoctl.Datas[ base ].begin_min,
                  BaseIoctl.Datas[ base ].begin_sec,
                  BaseIoctl.Datas[ base ].begin_cent);
            
            g_print("\tcdparanoia [.%d]-[.%d] -d %s -O 0 \"%d.wav\"",
                  BaseIoctl.Datas[ base ].begin < 44 ? 0 : BaseIoctl.Datas[ base ].begin,
                  base == 0
                        ? 
                        (BaseIoctl.Datas[ base ].length + BaseIoctl.Datas[ base ].begin) -1
                        :
                        BaseIoctl.Datas[ base ].length -1,
                  EnteteCD.NameCD_Device,
                  base +1
                  );
                  
                  
            if (BaseIoctl.Cue [ base ].BoolExtract == TRUE)
                  g_print(" -> Extract");
            
            g_print("\n");
      }

      TempDiv = BaseIoctl.Datas[ BaseIoctl.TotalTracks ].begin / 75;
      TempMod = BaseIoctl.Datas[ BaseIoctl.TotalTracks ].begin % 75;
      
      g_print("TOTAL %7d [%02d:%02d:%02d]  ",
                  BaseIoctl.Datas[ BaseIoctl.TotalTracks ].begin,
                  BaseIoctl.Datas[ BaseIoctl.TotalTracks ].begin_min,
                  BaseIoctl.Datas[ BaseIoctl.TotalTracks ].begin_sec,
                  BaseIoctl.Datas[ BaseIoctl.TotalTracks ].begin_cent);
      g_print("\n\n");
}

void cdcue_set_base_ioctl (gchar *p_buffer,     /* Lerr                 */
                     gint p_TotalTracks)  /* CdToc->TotalTracks   */
{
      gchar        *Lerr = NULL;
      gchar       **Larrbuf = NULL;
      gint          index;
      gchar        *ptr = NULL;
      gint          piste;
      gint          base = 0;
      gint          TempDiv;
      gint          TempMod;
      
      cdcue_alloc_base_ioctl (p_TotalTracks);
      if (BaseIoctl.Datas == NULL) {
            PRINT("BaseIoctl.Datas == NULL");
            return;
      }
      
      Lerr = p_buffer;
      if (*Lerr) {
      
            /* decoupage du texte en lignes */
            Larrbuf = g_strsplit(Lerr, "\n", 0);
            
            /* debut du texte */
            for (index=0; Larrbuf[index]; index++) {
                  if (strstr (Larrbuf[index], "===")) {
                        index ++;
                        break;
                  }
            }
            /*
            Table of contents (audio tracks only):
            track        length               begin        copy pre ch
            ===========================================================
              1.    12375 [02:45.00]       32 [00:00.32]    no   no  2
              2.    12500 [02:46.50]    12407 [02:45.32]    no   no  2
              3.    15925 [03:32.25]    24907 [05:32.07]    no   no  2
              4.    10775 [02:23.50]    40832 [09:04.32]    no   no  2
              5.     9550 [02:07.25]    51607 [11:28.07]    no   no  2
              6.    12550 [02:47.25]    61157 [13:35.32]    no   no  2
              7.    12613 [02:48.13]    73707 [16:22.57]    no   no  2
              8.    12925 [02:52.25]    86320 [19:10.70]    no   no  2
              9.    12550 [02:47.25]    99245 [22:03.20]    no   no  2
             10.    23737 [05:16.37]   111795 [24:50.45]    no   no  2
             11.    16363 [03:38.13]   135532 [30:07.07]    no   no  2
             12.    14712 [03:16.12]   151895 [33:45.20]    no   no  2
             13.    16325 [03:37.50]   166607 [37:01.32]    no   no  2
             14.    16188 [03:35.63]   182932 [40:39.07]    no   no  2
             15.    18800 [04:10.50]   199120 [44:14.70]    no   no  2
             16.    17925 [03:59.00]   217920 [48:25.45]    no   no  2
             17.    21212 [04:42.62]   235845 [52:24.45]    no   no  2
             18.    25063 [05:34.13]   257057 [57:07.32]    no   no  2
             19.    14112 [03:08.12]   282120 [62:41.45]    no   no  2
             20.    19550 [04:20.50]   296232 [65:49.57]    no   no  2
            TOTAL  315750 [70:10.00]    (audio only)
            */
            for (base = 0, piste = 0; Larrbuf[index]; index++, piste ++) {

                  /* calcul la fin et quitte la boucle */
                  if ((ptr = strstr (Larrbuf[index], "TOTAL"))) {
                        ptr += 5;
                        while (*ptr == ' ') ptr ++;
                        BaseIoctl.Datas[ base ].begin = atoi (ptr);
                        TempDiv = BaseIoctl.Datas[ base ].begin / 75;
                        TempMod = BaseIoctl.Datas[ base ].begin % 75;
                        BaseIoctl.Datas[ base ].begin_min  = TempDiv / 60;
                        BaseIoctl.Datas[ base ].begin_sec  = TempDiv % 60;
                        BaseIoctl.Datas[ base ].begin_cent = TempMod;
                        break;
                  }
                  
                  /* Stocke 'length' */
                  if ((ptr = strchr (Larrbuf[index], '.')) != NULL) {
                        ptr ++;
                        while (*ptr == ' ') ptr ++;
                        BaseIoctl.Datas[ base ].length = atoi (ptr);
                        TempDiv = BaseIoctl.Datas[ base ].length / 75;
                        TempMod = BaseIoctl.Datas[ base ].length % 75;
                        BaseIoctl.Datas[ base ].length_min  = TempDiv / 60;
                        BaseIoctl.Datas[ base ].length_sec  = TempDiv % 60;
                        BaseIoctl.Datas[ base ].length_cent = TempMod;
                  }
                  
                  /* Stocke 'begin' */
                  if ((ptr = strchr (Larrbuf[index], ']')) != NULL) {
                        ptr ++;
                        while (*ptr == ' ') ptr ++;
                        BaseIoctl.Datas[ base ].begin = atoi (ptr);
                        TempDiv = BaseIoctl.Datas[ base ].begin / 75;
                        TempMod = BaseIoctl.Datas[ base ].begin % 75;
                        BaseIoctl.Datas[ base ].begin_min  = TempDiv / 60;
                        BaseIoctl.Datas[ base ].begin_sec  = TempDiv % 60;
                        BaseIoctl.Datas[ base ].begin_cent = TempMod;
                        base ++;
                  }
            }
            g_strfreev(Larrbuf);
            cdcue_print_base_ioctl ();
      }
}
                     

void cdcue_make_cue (void)
{
      gint  piste;
      
      if (BaseIoctl.Cue == NULL) return;
      
      for (piste = 0; piste < BaseIoctl.TotalTracks; piste ++) {
            BaseIoctl.Cue [ piste ].BeginTime.total  = BaseIoctl.Datas[ piste ].begin / 75;
            BaseIoctl.Cue [ piste ].BeginTime.min    = BaseIoctl.Datas[ piste ].begin_min;
            BaseIoctl.Cue [ piste ].BeginTime.sec    = BaseIoctl.Datas[ piste ].begin_sec;
            BaseIoctl.Cue [ piste ].BeginTime.cent   = BaseIoctl.Datas[ piste ].begin_cent;
                              
            if (BaseIoctl.Cue [ piste ].Title == NULL) {
                  BaseIoctl.Cue [ piste ].Title = g_strdup_printf ("Track_%02d", piste + 1);
            }
      }

      for (piste = 0; piste < BaseIoctl.TotalTracks; piste ++) {
            if (piste > 0) {
                  
                  BaseIoctl.Cue [ piste ].EndTime.total  = BaseIoctl.Cue [ piste ].BeginTime.total - 3;
                  BaseIoctl.Cue [ piste ].EndTime.sec    = BaseIoctl.Cue [ piste ].EndTime.total % 60;
                  BaseIoctl.Cue [ piste ].EndTime.total -= BaseIoctl.Cue [ piste ].EndTime.sec;
                  BaseIoctl.Cue [ piste ].EndTime.min    = BaseIoctl.Cue [ piste ].EndTime.total / 60;
                  BaseIoctl.Cue [ piste ].EndTime.cent   = BaseIoctl.Cue [ piste ].BeginTime.cent;
            }
      }
}

void cdcue_write_cue_ok (void)
{
      gint   piste;
      gchar *PathName = NULL;
      FILE  *fp;
      
      PathName = g_strdup_printf ("%s/%s.cue", (gchar *)Config_User.Path_Destination_CD, BaseIoctl.Performer);
      
      PRINT("Production du fichier");

      fp = fopen (PathName, "w");

      fprintf (fp,   "REM Cue file written by Xcfa\n\n");

      fprintf (fp,   "PERFORMER \"%s\"\n", BaseIoctl.Performer);
      fprintf (fp,   "TITLE \"%s\"\n", BaseIoctl.Title);
      fprintf (fp,   "FILE \"%s\" WAVE\n", BaseIoctl.File);
      for (piste = 0; piste < BaseIoctl.TotalTracks; piste ++) {
            fprintf (fp,   "  TRACK %02d AUDIO\n", piste +1);
            fprintf (fp,   "    PERFORMER \"%s\"\n", BaseIoctl.Cue [ piste ].Performer);
            fprintf (fp,   "    TITLE \"%s\"\n", BaseIoctl.Cue [ piste ].Title);
            if (piste > 0)
            fprintf (fp,   "    INDEX 00 %02d:%02d:%02d\n", BaseIoctl.Cue [ piste ].EndTime.min, BaseIoctl.Cue [ piste ].EndTime.sec, BaseIoctl.Cue [ piste ].EndTime.cent);
            fprintf (fp,   "    INDEX 01 %02d:%02d:%02d\n", BaseIoctl.Cue [ piste ].BeginTime.min, BaseIoctl.Cue [ piste ].BeginTime.sec, BaseIoctl.Cue [ piste ].BeginTime.cent);
/*
g_print ("    PERFORMER \"%s\"\n", BaseIoctl.Cue [ piste ].Performer);
g_print ("    TITLE \"%s\"\n", BaseIoctl.Cue [ piste ].Title);
if (piste > 0)
g_print ("    INDEX 00 %02d:%02d:%02d\n", BaseIoctl.Cue [ piste ].FMin, BaseIoctl.Cue [ piste ].FSec, BaseIoctl.Cue [ piste ].FCent);
g_print ("    INDEX 01 %02d:%02d:%02d\n", BaseIoctl.Cue [ piste ].DMin, BaseIoctl.Cue [ piste ].DSec, BaseIoctl.Cue [ piste ].DCent);
*/
      }
      fprintf (fp,   "\n");

      fclose (fp);
      g_free (PathName);
      PathName = NULL;
            
      /* FIN de creation CUE-FILE */
      var_cd.TypeCreateCue = TYPE_CUE_NONE;
}

/* ADD == 0 : no change
   ADD == 1 : + 3 secondes
   ADD == 2 : - 3 secondes
*/
void cdcue_calcul_start (gint piste, gint Add)
{
      gint   TempDiv = 0;
      gint   TempMod = 0;
      
      if (Add == 0) {
            TempDiv = BaseIoctl.Cue [ piste ].CuePartiel.Start / 75;
            TempMod = BaseIoctl.Cue [ piste ].CuePartiel.Start % 75;
      }
      else if (Add == 1) {
            TempDiv = (BaseIoctl.Cue [ piste ].CuePartiel.Start +32) / 75;
            TempMod = (BaseIoctl.Cue [ piste ].CuePartiel.Start +32) % 75;
      }
      else if (Add == 2) {
            TempDiv = (BaseIoctl.Cue [ piste ].CuePartiel.Start -32) / 75;
            TempMod = (BaseIoctl.Cue [ piste ].CuePartiel.Start -32) % 75;
      }
      BaseIoctl.Cue [ piste ].CuePartiel.StartMin  = TempDiv / 60;
      BaseIoctl.Cue [ piste ].CuePartiel.StartSec  = TempDiv % 60;
      BaseIoctl.Cue [ piste ].CuePartiel.StartCent = TempMod;
}

/*
REM Cue file written by Xcfa

PERFORMER "James Brown"
TITLE "Sex Machine - The Very Best Of James Brown"
FILE "aurelie.wav" WAVE
  TRACK 01 AUDIO
    PERFORMER "James Brown"
    TITLE "Please"
    INDEX 01 00:00:32         DEBUT Please
  TRACK 02 AUDIO
    PERFORMER "James Brown"
    TITLE "Think"
    INDEX 00 02:44:00         FIN   Please
    INDEX 01 02:45:00         DEBUT Think
  TRACK 03 AUDIO
    PERFORMER "James Brown"
    TITLE "Nigth"
    INDEX 00 05:00:00         FIN   Think
    INDEX 01 05:00:32         DEBUT Nigth
*/
void cdcue_write_cue_ok_partiel (void)
{
      gint   piste;
      gint   track;
      gint   old_piste = 0;
      gchar  *Ptr = NULL;
      FILE  *fp;
      gchar *PathName = NULL;
      
      /*gint       TempDiv;
      gint   TempMod;*/
      
      /* Initialisation */
      for (piste = 0; piste < BaseIoctl.TotalTracks; piste ++) {
            BaseIoctl.Cue [ piste ].CuePartiel.Start     = 0;
            BaseIoctl.Cue [ piste ].CuePartiel.StartMin  = 0;
            BaseIoctl.Cue [ piste ].CuePartiel.StartSec  = 0;
            BaseIoctl.Cue [ piste ].CuePartiel.StartCent = 0;
            
            BaseIoctl.Cue [ piste ].CuePartiel.Len     = 0;
      }
      
      /* init Len */
      for (piste = 0; piste < BaseIoctl.TotalTracks; piste ++) {
            BaseIoctl.Cue [ piste ].CuePartiel.Len     = BaseIoctl.Datas[ piste ].length;
      }
      
      /* Init Start ZERO */
      BaseIoctl.Cue [ 0 ].CuePartiel.Start = BaseIoctl.Datas[ 0 ].begin;
      
      /* Init Start ZERO */
      old_piste = 0;
      for (piste = 0; piste < BaseIoctl.TotalTracks; piste ++) {
            if (BaseIoctl.Cue [ piste ].BoolExtract == TRUE) {
                  
                  BaseIoctl.Cue [ piste  ].CuePartiel.Start   = BaseIoctl.Cue [ old_piste ].CuePartiel.Start +
                                                      BaseIoctl.Cue [ piste ].CuePartiel.Len;
                  cdcue_calcul_start (piste, 0);
                  old_piste = piste;
            }
      }
      
      for (piste = 0; piste < BaseIoctl.TotalTracks; piste ++) {
            
            g_print ("%2d  LEN [ %7d ]    START [ %7d ]  %02d:%02d:%02d   %s  %s\n",
                  piste,
                  BaseIoctl.Cue [ piste ].CuePartiel.Len,
                  BaseIoctl.Cue [ piste ].CuePartiel.Start,
                  BaseIoctl.Cue [ piste ].CuePartiel.StartMin,
                  BaseIoctl.Cue [ piste ].CuePartiel.StartSec,
                  BaseIoctl.Cue [ piste ].CuePartiel.StartCent,
                  BaseIoctl.Cue [ piste ].BoolExtract == TRUE ? "EXTRACT" : "       ",
                  BaseIoctl.Cue [ piste ].Title
                  );
      }
      
      Ptr = (gchar *)gtk_entry_get_text (GTK_ENTRY (var_cd.Adr_entry_name_file_cue));
      PathName = g_strdup_printf ("%s/%s.cue", (gchar *)Config_User.Path_Destination_CD, Ptr);
      
      /*fp = fopen (PathName, "w");*/
      fp = fopen (BaseIoctl.PathNameDestFileCue, "w");
      /*g_print ("PathName =  = %s\n", PathName);
      g_print ("BaseIoctl.PathNameDestFileCue = %s\n", BaseIoctl.PathNameDestFileCue);*/
      
      g_print("\n");
      fprintf (fp,   "REM Cue file written by Xcfa\n\n");

      fprintf (fp,   "PERFORMER \"%s\"\n", BaseIoctl.Performer);
      fprintf (fp,   "TITLE \"%s\"\n", BaseIoctl.Title);


      switch (gtk_combo_box_get_active ( GTK_COMBO_BOX ( GTK_WIDGET (lookup_widget (wind_main, "combobox_choice_file_cue"))))) {
      case 0 : fprintf (fp,   "FILE \"%s.wav\" WAVE\n", Ptr);     break;
      case 1 : fprintf (fp,   "FILE \"%s.flac\" WAVE\n", Ptr);    break;
      case 2 : fprintf (fp,   "FILE \"%s.ogg\" WAVE\n", Ptr);     break;
      case 3 : fprintf (fp,   "FILE \"%s.mpc\" WAVE\n", Ptr);     break;
      }
      
      old_piste = 0;
      for (track = 0, piste = 0; piste < BaseIoctl.TotalTracks; piste ++) {
            
            if (BaseIoctl.Cue [ piste ].BoolExtract == FALSE) continue;
            
            fprintf (fp,   "  TRACK %02d AUDIO\n", track +1);
            
            fprintf (fp,   "    PERFORMER \"%s\"\n", BaseIoctl.Cue [ piste ].Performer);
            fprintf (fp,   "    TITLE \"%s\"\n", BaseIoctl.Cue [ piste ].Title);
            
            if (track == 0) {
                  /*g_print("    %02d track == 0\n", piste);*/
                  /*g_print("    INDEX 01 %02d:%02d:%02d\n",
                        BaseIoctl.Cue [ 0 ].CuePartiel.StartMin,
                        BaseIoctl.Cue [ 0 ].CuePartiel.StartSec,
                        BaseIoctl.Cue [ 0 ].CuePartiel.StartCent);*/
                  fprintf (fp,   "    INDEX 01 00:00:00\n");
                  track ++;
                  old_piste = piste;
                  continue;
            }
            if (track > 0) {
                  cdcue_calcul_start (old_piste, 2);
                  fprintf (fp,   "    INDEX 00 %02d:%02d:%02d\n",
                        BaseIoctl.Cue [ old_piste ].CuePartiel.StartMin,
                        BaseIoctl.Cue [ old_piste ].CuePartiel.StartSec,
                        BaseIoctl.Cue [ old_piste ].CuePartiel.StartCent);
                  cdcue_calcul_start (old_piste, 1);
            }

            fprintf (fp,   "    INDEX 01 %02d:%02d:%02d\n",
                        BaseIoctl.Cue [ old_piste ].CuePartiel.StartMin,
                        BaseIoctl.Cue [ old_piste ].CuePartiel.StartSec,
                        BaseIoctl.Cue [ old_piste ].CuePartiel.StartCent);

            track ++;
            old_piste = piste;
      }
      
      fclose (fp);
      g_free (PathName);
      PathName = NULL;
            
      /* FIN de creation CUE-FILE */
      var_cd.TypeCreateCue = TYPE_CUE_NONE;
}

void cdcue_write_cue (void)
{
      gchar *PathName = NULL;
      gchar *Str = NULL;
      gchar *Ptr = NULL;
      
      if (BaseIoctl.Cue == NULL) return;
      
      switch (var_cd.TypeCreateCue) {
      case TYPE_CUE_NONE :
            break;
            
      case TYPE_CUE_FILE :
            /*
            Ptr = (gchar *)gtk_entry_get_text (GTK_ENTRY (var_cd.Adr_entry_name_file_cue));
            PathName = g_strdup_printf ("%s/%s.cue", (gchar *)Config_User.Path_Destination_CD, Ptr);
            */
            if (gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON (lookup_widget (wind_main, "checkbutton_creation_fichier_cue"))) == TRUE) {
                  
                  /*if (infosong_file_is_reg (PathName) == TRUE) {*/
                  if (infosong_file_is_reg (BaseIoctl.PathNameDestFileCue) == TRUE) {
                        
                        Str = g_strdup_printf (_("<b>\nLe fichier existe:\n%s       \nVoulez vous le remplacer  ?       \n</b>"), BaseIoctl.PathNameDestFileCue);
                        windchoice_open (
                              _("Le fichier existe"),
                              Str,
                              TRUE,
                              cdcue_write_cue_ok_partiel
                              );
                        break;
                  }
                  cdcue_write_cue_ok_partiel ();
            }
            break;
            
      case TYPE_CUE_CD :
            PathName = g_strdup_printf ("%s/%s.cue", (gchar *)Config_User.Path_Destination_CD, BaseIoctl.Performer);
            
            if (infosong_file_is_reg (PathName) == TRUE) {
                  
                  Str = g_strdup_printf (_("<b>\nLe fichier existe:\n%s       \nVoulez vous le remplacer  ?       \n</b>"), PathName);
                  windchoice_open (
                        _("Le fichier existe"),
                        Str,
                        TRUE,
                        cdcue_write_cue_ok
                        );
                  break;
            }
            cdcue_write_cue_ok ();
            break;
      }
      
      /* FIN de creation CUE-FILE */
      var_cd.TypeCreateCue = TYPE_CUE_NONE;
      
      if (PathName != NULL) {
            g_free (PathName);
            PathName = NULL;
      }
      if  (Str != NULL) {
            g_free (Str);
            Str = NULL;
      }
      Ptr = NULL;
}

static gint cdcue_timeout (gpointer data)
{
      if (var_cd.bool_timeout_read_toc_cd == FALSE) {
            
            /* Creation de fichier CUE */
            cdcue_write_cue ();
            
            /* FIN timeout */
            gtk_timeout_remove (cdcue.handler_timeout);
      }
      
      return (TRUE);
}

/* Demande de creation CUE totale
*/
void cdcue_button_cue_creation_from_cd_clicked (void)
{
      
      if (cdcue_is_alloc () == TRUE) {
            
            /* DEBUT de creation de fichier CUE */
            var_cd.TypeCreateCue = TYPE_CUE_CD;
            
            /*
            cdcue_make_cue ();
            cdcue_make_cue_with_cdtoc (CdToc);
            */
            cdcue_write_cue ();
      }
      else {
      
            /* DEBUT de creation de fichier CUE */
            var_cd.TypeCreateCue = TYPE_CUE_CD;

            /* Pré-initialisations indispensable */
            var_cd.bool_thread_read_toc_cd = TRUE;
            var_cd.bool_timeout_read_toc_cd = TRUE;
            
            /* Le timer de fin */
            cdcue.handler_timeout = gtk_timeout_add (100, cdcue_timeout, 0);
            
            /* Et action */
            cdaudiotoc_reffresh_list_cd ();
      }
}

void cdcue_entry_name_fichier_unique_cue_changed (void)
{
      gchar        *ptr_template = NULL;
      gchar        *str = NULL;
      gchar        *ptr = NULL;
      
      if (var_cd.Adr_entry_name_file_cue == NULL) return;

      ptr_template = (gchar *)gtk_entry_get_text (GTK_ENTRY (var_cd.Adr_entry_name_file_cue));
      
      /* Suppression du caracteres '/' interdit si il existe */
      str = g_strdup (ptr_template);
      if (strchr (str, '/')) {

            while ((ptr = strchr (str, '/'))) {
                  strcpy (ptr, ptr+1);
            }
            gtk_entry_set_text (GTK_ENTRY (var_cd.Adr_entry_name_file_cue), str);

            utils_puts_statusbar_global (_("Le caractere  /  est interdit  !!!"));
      }

      g_free (str);
      str = NULL;

}












Generated by  Doxygen 1.6.0   Back to index