Logo Search packages:      
Sourcecode: xcfa version File versions

split_cue.c

 /*
 * file      : split_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 <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <string.h>
#include <stdlib.h>

#include "support.h"
#include "global.h"
#include "config_user.h"
#include "fileselect.h"
#include "utils.h"
#include "options.h"
#include "file.h"
#include "dragNdrop.h"
#include "split.h"
#include "gtkmarkscale.h"
#include "jogshuttle.h"
#include "player.h"
#include "win_info.h"
#include "prg_init.h"


/*
*---------------------------------------------------------------------------
* VARIABLES
*---------------------------------------------------------------------------
*/


/* Importer un fichier CUE
*/

/*
            
            guint Sec;
            guint Hundr;
            gdouble     SecondesTempsActuel = 0.0;
            VarPlayer.
                  gdouble     PercentTempsActuel = 0.0;
                  gdouble     DOUBLE_TempsTotal = 0.0;      --> DUREE TOTAL DU FICHIER EN SECONDES
            
                       Minutes
                       |  Secondes
                       |  |  Centiemes
                       |  |  |
            -- INDEX 01 00:00:00
            
            if ((Ptr = strstr(buf,"ANS_TIME_POSITION=")) != NULL) {
                                    
                  -- CHERCHE LES SECONDES
                  
                  while (*Ptr != '=') Ptr++;
                  if (*Ptr == '=') Ptr++;
                  Sec = atoi (Ptr);
                  
                  -- CHERCHE LES CENTIEMES
                  
                  while (*Ptr != '.') Ptr++;
                  if (*Ptr == '.') Ptr++;
                  Hundr = atoi (Ptr);
                  
                  -- SECONDES + CENTIEMES
                  
                  SecondesTempsActuel = (gdouble)Sec + ((gdouble)Hundr / 10.0);
                  
                  -- CONVERTIR EN POURCENTAGE
                  
                  PercentTempsActuel = (SecondesTempsActuel / DOUBLE_TempsTotal) * 100.0;
                  
            }
*/

DETAIL *split_selected_last (void)
{
      return (NULL);
}
gchar *splitcue_get_title (gchar *p_str)
{
      gchar *Ptr = NULL;
      gchar *Str = NULL;
      
      Ptr = strchr (p_str, '"');
      Ptr ++;
      Str = g_strdup (Ptr);
      Ptr = strchr (Str, '"');
      *Ptr = '\0';
      
      /* Suppression du caracteres '/' interdit si il existe */
      if (strchr (Str, '/')) {
            while ((Ptr = strchr (Str, '/'))) {
                  *Ptr = ' ';
            }
      }

      
      return ((gchar *)Str);
}

gchar *splitcue_search_file_cue (gchar *p_path, gint *Err)
{
      FILE  *fp;
#define MAX_CARS 255
      gchar  buf   [ MAX_CARS +1 ];
      gchar *Ptr = NULL;
      gchar *Str = NULL;
      gchar *PathNameSong = NULL;
      gchar *Path = NULL;
      
      /* PRINT_FUNC_LF(); */
      
      /* Aucune erreur */
      *Err = 0;
      
      if ((fp = fopen (p_path, "r")) == NULL) {
            *Err = 1;
            return(NULL);
      }
      
      /*
      PERFORMER "Rita Mitsouko / Rita Mitsouko"
      TITLE "Rita Mitsouko / Rita Mitsouko"
      FILE "XCFA_CUE.wav" WAVE

      PERFORMER "José de Divina"
      TITLE "Ibiza World Tour @ Space"
      FILE "Ibiza1.mp3" WAVE
      
      REM GENRE Jazz
      REM DATE 1966
      REM DISCID 120F4902
      REM COMMENT "ExactAudioCopy v0.95b4"
      PERFORMER "John Coltrane"
      TITLE "Live in Japan (CD1)"
      FILE "un.flac" WAVE

      REM Cue file written by K3b 1.0.5
      PERFORMER "Rita Mitsouko"
      TITLE "Rita Mitsouko"
      FILE "01 - Restez Avec Moi.wav" WAVE
      */
      
      while (fgets (buf, MAX_CARS, fp) != NULL) {
            
            /* Si debut de ligne ok */
            if ((Ptr = strstr (buf, "FILE \"")) != NULL) {

                  /* Str contiendra le nom du fichier delimite par les signes "
                  */
                  Ptr = strchr (buf, '"');
                  Ptr ++;
                  Str = g_strdup (Ptr);
                  if ((Ptr = strrchr (Str, '"')) == NULL) {
                        *Err = 2;
                        fclose (fp);
                        g_free (Str);
                        Str = NULL;
                        return (NULL);
                  }
                  *Ptr = '\0';
                  
                  /* Path contiendra le chemin
                  */
                  Path = g_strdup (p_path);
                  if ((Ptr = strrchr (Path, '/')) != NULL) {
                        *Ptr = '\0';
                  }
                  
                  /* PathNameSong contiendra: chemin + nom du fichier musical
                  */
                  PathNameSong = g_strdup_printf ("%s/%s", Path, Str);
                  g_free (Path);
                  Path = NULL;
                  g_free (Str);
                  Str = NULL;
                  break;
            }
      }
      fclose (fp);
      
      if (PathNameSong == NULL) {
            *Err = 3;
      }
      else if (g_str_has_suffix (PathNameSong, ".wav") == FALSE &&
             g_str_has_suffix (PathNameSong, ".mp3") == FALSE &&
             g_str_has_suffix (PathNameSong, ".ogg") == FALSE &&
             g_str_has_suffix (PathNameSong, ".flac") == FALSE &&
             g_str_has_suffix (PathNameSong, ".wv") == FALSE &&
             g_str_has_suffix (PathNameSong, ".shn") == FALSE ) {
            
            g_print ("====\n%s\n----\n%s\t%s\n\t\tFILE NOT IN: .wav .mp3 .ogg .flac .wv .shn\n====\n", p_path, buf, PathNameSong);
            *Err = 4;
            g_free (PathNameSong);
            PathNameSong = NULL;
      }

      return ((gchar *)PathNameSong);
}

void splitcue_ajouter_track (DETAIL *detail)
{
}

gdouble splitcue_get_percentage (gchar *p_str, FIC_SPLIT *FicSplit)
{
      gchar       *Ptr = NULL;
      guint        Min, Sec, Hundr;
      gdouble            SecondesTempsActuel = 0.0;
      gdouble            PercentTempsActuel = 0.0;
      
      
      /* PRINT(""); */

      /* MINUTES */
      Ptr = strchr (p_str, ':');
      while (*Ptr != ' ') Ptr --;
      if (*Ptr == ' ') Ptr ++;
      Min = atoi (Ptr);
      
      /* SECONDES */
      Ptr = strchr (p_str, ':');
      Ptr ++;
      Sec = atoi (Ptr);

      /* CENTIEMES */
      Ptr = strrchr (p_str, ':');
      Ptr ++;
      Hundr = atoi (Ptr);

      /* Temps Total en secondes */
      SecondesTempsActuel = (gdouble)(Min * 60) + (gdouble)Sec + (gdouble)(Hundr / 10000.0);
      
      /* POURCENTAGE */
      if (FicSplit != NULL) {
            PercentTempsActuel = (SecondesTempsActuel / (gdouble)FicSplit->GUINT_TempsTotal ) * 100.0;
      }
      
      return (PercentTempsActuel);
}

static gint splitcue_timeout_waiting_fileanalyze (gpointer data)
{
      if (fileanalyze_IS_END_OF_add_file_to_treeview () == FALSE) {
#define SPLIT_MAX_CARS 1024
            FILE              *fp;
            gchar              buf   [ SPLIT_MAX_CARS +4 ];
            GList             *List = NULL;
            FIC_SPLIT         *FicSplit = NULL;
            DECOUPES_FIC_SPLIT      *DecoupesFicSplit = NULL;
            /*DETAIL                *detail = split_get_first_line_is_selected ();*/

            if (split_get_first_line_is_selected () != NULL) PRINT("split_get_first_line_is_selected () OK\n");
      
            if ((fp = fopen (VarSplit.Dummy, "r")) == NULL) {
                  g_free (VarSplit.Dummy);
                  VarSplit.Dummy = NULL;
                  gtk_timeout_remove (VarSplit.HandlerTimeout);
                  return (TRUE);
            }

            while (fgets (buf, MAX_CARS, fp) != NULL) {
            
                  /* Allocation structure tache */
                  if (strstr (buf, "TRACK ")) {
                        g_print("%s", buf);
                        List             = split_ajouter_decoupe_from_file ();
                        List             = g_list_last (List);
                        DecoupesFicSplit = (DECOUPES_FIC_SPLIT *)List->data;
                        FicSplit         = split_get_ptr_ficsplit ();
                  }
                  /* Temps DEBUT */
                  else if (strstr (buf, "INDEX 01")) {
                        g_print("%s", buf);
                        DecoupesFicSplit->AdrValueMarkA = splitcue_get_percentage (buf, FicSplit);
                        if (g_list_previous (List) != NULL) {
                              gdouble old = DecoupesFicSplit->AdrValueMarkA;
                              List             = g_list_previous (List);
                              DecoupesFicSplit = (DECOUPES_FIC_SPLIT *)List->data;
                              DecoupesFicSplit->AdrValueMarkB = old;
                              List             = g_list_last (List);
                              DecoupesFicSplit = (DECOUPES_FIC_SPLIT *)List->data;
                        }
                  }
                  /* Temps FIN */
                  /*
                  else if (strstr (buf, "INDEX 00")) {
                        g_print("%s", buf);
                        List             = g_list_previous (List);
                        DecoupesFicSplit = (DECOUPES_FIC_SPLIT *)List->data;
                  
                        DecoupesFicSplit->AdrValueMarkB = splitcue_get_percentage (buf, FicSplit);
                        if (DecoupesFicSplit->AdrValueMarkB < DecoupesFicSplit->AdrValueMarkA) 
                              DecoupesFicSplit->AdrValueMarkB = 100.0;
                        
                        List             = g_list_last (List);
                        DecoupesFicSplit = (DECOUPES_FIC_SPLIT *)List->data;
                  }
                  */
                  /* Les titres des musiques */ 
                  else if (strstr (buf, "TITLE ")) {
                        if (FicSplit != NULL && FicSplit->ListDecoupes != NULL) {
                              g_print("%s", buf);
                              DecoupesFicSplit->Name = splitcue_get_title (buf);
                        }
                  }
            }
            
            fclose (fp);
            g_free (VarSplit.Dummy);
            VarSplit.Dummy = NULL;
                        
            split_decoupe_affiche_glist ();
            
            gtk_timeout_remove (VarSplit.HandlerTimeout);
#undef SPLIT_MAX_CARS
      }
      return (TRUE);
}

gboolean splitcue_is_dupply (gchar *namefile)
{
      
      /*
      return (split_is_dupply (namefile));
      */
      if (split_is_dupply (namefile) == TRUE) {
            g_print("%s IS DUPPLY -> TRUE\n",namefile);
            return (TRUE);
      }
      
      return (FALSE);
}

void splitcue_import_file_cue (gchar *path)
{
      gchar       *PathNameSong = NULL;
      gint         Err;
      
      /* PRINT_FUNC_LF(); */
            
      if (g_str_has_suffix (path, ".cue") == FALSE) {
            wininfo_create (
                  _("Erreur de choix de fichier"),
                  _("   L'extention du fichier est incorrect !      "),
                    "\n",
                  "");
            return;
      }
      
      if ((PathNameSong = splitcue_search_file_cue (path, &Err)) == NULL) {

            switch (Err) {
            case 1:
                  /* Erreur de lecture sur le support */
                  wininfo_create (
                        _("Erreur de lecture"),
                        _("   Impossible de lire le fichier depuis le support !      "),
                          "\n",
                        "");
                  break;
            case 2:
                  /* Le nom du fichier est absent ou pas termine par le signe " */
                  wininfo_create (
                        _("Le nom du fichier est absent"),
                        _("   Le nom du fichier est absent ou pas termine par le signe \"      "),
                          "\n",
                        "");
                  break;
            case 3:
                  /* Aucun fichier de musique pour ce fichier CUE */
                  wininfo_create (
                        _("References absentes"),
                        _("   Aucun fichier de musique pour ce fichier CUE      "),
                          "\n",
                        "");
                  break;
            case 4 :
                  /* Aucune reference a: WAV or OGG or MP3 or FLAC */
                  wininfo_create (
                        _("References absentes"),
                        _("   Aucune reference a un fichier musical de type:          "),
                          "\n",
                        _("   WAV ou OGG ou MP3 ou FLAC ou WV ou SHN    "),
                          "\n",
                        "");
                  break;
            }
            return;
      }
      
      if (splitcue_is_dupply (PathNameSong) == TRUE) {
            wininfo_create (
                  _("Duplication de fichier"),
                  _("   Ce fichier est deja present dans la liste     "),
                    "\n",
                  "");
            return;
      }

      if (fileanalyze_create_glist_analyze_file (PathNameSong, TRUE) == FALSE) {
            wininfo_create (
                  _("Fichier CUE non conforme"),
                  _("   Le fichier CUE et son fichier musical doivent etre dans le meme dossier.    "),
                    "\n\n",
                  _("   Veuillez recommencer l'operation.      "),
                    "\n",
                  "");
            return;
      }
      g_free (PathNameSong);
      PathNameSong = NULL;

      /* Ajout du fichier de MUSIQUE dans le TreeView */
      fileanalyze_add_file_to_treeview (_TREEVIEW_SPLIT_);

      /* Ce timeout permet d'attendre la fin de traitement de la fonction:
      *     fileanalyze_add_file_to_treeview (_TREEVIEW_SPLIT_);
      */
      VarSplit.Dummy = g_strdup (path);
      VarSplit.HandlerTimeout = gtk_timeout_add (100, splitcue_timeout_waiting_fileanalyze, 0);
}

void splitcue_button_import_cue_split_clicked (void)
{
      if (PrgInit.bool_mp3splt == FALSE  ||
          PrgInit.bool_shntool == FALSE  ||
          PrgInit.bool_cuetools == FALSE ||
          PrgInit.bool_checkmp3 == FALSE) {
            gtk_notebook_set_current_page (GTK_NOTEBOOK (lookup_widget (wind_main, "notebook_general")), NOTEBOOK_PRGEXTERNES);
            gtk_notebook_set_current_page (GTK_NOTEBOOK (lookup_widget (wind_main, "notebook_app_externes")), NOTEBOOK_OPTIONS_PRGEXTERNES);
            
            wininfo_create (
                  _("PACKAGE(s) ABSENT(s) pour SPLIT"),
                  _("   Veuillez verifier la presence de ces packages  "),
                    "               \n",
                  _("   pour pouvoir utiliser la fonction Split:"),
                    "               \n",
                    "   <b>mp3splt, shntool, cuetools, checkmp3</b>",
                    "\n\n",
                  _("   Veuillez installer et recommencer."),
                    "\n",
                  "");
            return;
      }
      fileselect_create (_PATH_IMPORT_FILE_CUE_, splitcue_import_file_cue);
}


Generated by  Doxygen 1.6.0   Back to index