Package: mp3splt
Version: 2.1-1.1.1
Severity: wishlist

Hello, 

Attached I have a patch which allows mp3splt to use exported Audacity label
tracks to split mp3 files with.  

I have already submitted the patch upstream.  They requestd that I resubmit
the patch against the current version of the code (which unfortunately has
been completely re-factored, but I hope to update later this week).   

In the mean time, I am sure this patch would be useful for those using the
current version of the mp3splt code.

thanks,
donfede



-- System Information:
Debian Release: 4.0
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.23.9-casagrau-2
Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ISO-8859-1)

Versions of packages mp3splt depends on:
ii  libc6                  2.3.6.ds1-13etch2 GNU C Library: Shared libraries
ii  libmad0                0.15.1b-2.1       MPEG audio decoder library
ii  libogg0                1.1.3-2           Ogg Bitstream Library
ii  libvorbis0a            1.1.2.dfsg-1.2    The Vorbis General Audio Compressi
ii  libvorbisfile3         1.1.2.dfsg-1.2    The Vorbis General Audio Compressi

mp3splt recommends no packages.

-- no debconf information

-- 
I choose information and knowledge over profit.
http://www.eff.org/share/
diff -Naur mp3splt-2.1_ORIG/audacitylabel.c mp3splt-2.1/audacitylabel.c
--- mp3splt-2.1_ORIG/audacitylabel.c	1969-12-31 19:00:00.000000000 -0500
+++ mp3splt-2.1/audacitylabel.c	2007-09-30 11:08:41.000000000 -0400
@@ -0,0 +1,128 @@
+/*
+ * audacitylabel.c -- Audacity label file parser portion of the Mp3Splt utility
+ *                    Utility for mp3/ogg splitting without decoding
+ *
+ * Copyright (c) 2002-2004 M. Trotta - <[EMAIL PROTECTED]>
+ * Copyright (c) 2007 Federico Grau - <[EMAIL PROTECTED]>
+ *
+ * http://mp3splt.sourceforge.net
+ * http://audacity.sourceforge.net/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <ctype.h>
+#include <netdb.h>
+#include <sys/types.h>
+#include <math.h>
+
+#ifndef NO_OGG
+#include <ogg/ogg.h>
+#include <vorbis/codec.h>
+#include <vorbis/vorbisfile.h>
+#endif
+
+#include "mp3.h"
+#include "ogg.h"
+#include "splt.h"
+#include "mp3splt.h"
+#include "cddb.h"
+
+int get_audacitylabel_splitpoints(unsigned char *file, splt_state *state)
+{
+	FILE *file_input;
+	char line[512];
+	double label_start;
+	double label_end;
+	char *label_name = NULL;
+	char *last_label_name = NULL;
+	int i;
+	int tracks = -1;
+	char *ptr = NULL;;
+
+	if (!(file_input=fopen(file, "r"))) {
+		perror(file);
+		exit(1);
+	}
+
+	fseek (file_input, 0, SEEK_SET);
+	while (fgets(line, 512, file_input)!=NULL)
+	{
+		ptr = line;
+
+		errno = 0;
+		label_start = strtod(ptr, &ptr);
+		if (errno != 0) return -1;
+		label_end = strtod(ptr, &ptr);
+		if (errno != 0) return -1;
+		// FIXME: how to handle if label_start != label_end?
+
+		// Trim off whitespace before the name.
+		while (isspace(*ptr)) {
+			ptr++;
+		}
+		// Trim off whitespace after the name.
+		i = strlen(ptr) - 1;
+		while (isspace(ptr[i])) {
+			ptr[i] = '\0';
+			i--;
+		}
+		if ( (last_label_name == NULL) && (label_name != NULL) ) {
+			last_label_name = strndup(label_name, 255);
+			free(label_name);
+			label_name = NULL;
+		}
+		label_name = strndup(ptr, 255);
+		cleanstring(label_name);
+
+		tracks++;
+
+		state->splitpoints[tracks] = floorf(label_start);
+		label_start = (label_start - state->splitpoints[tracks])*4/3; // FIXME: what/why is this...
+		state->splitpoints[tracks] += label_start;
+
+		if (tracks > 0) {
+			strncpy(state->fn[tracks], last_label_name, 256);
+			free(last_label_name);
+			last_label_name = NULL;
+		}
+	} // end while fgets line
+
+	if (tracks>0)  {
+		tracks++;
+		state->splitpoints[tracks] = (float) -1.f; // End of file
+	    	strncpy(state->fn[tracks], label_name, 256);
+		free(label_name);
+	}
+
+	fclose(file_input);
+
+	return tracks;
+}
+
+
+
+
diff -Naur mp3splt-2.1_ORIG/audacitylabel.h mp3splt-2.1/audacitylabel.h
--- mp3splt-2.1_ORIG/audacitylabel.h	1969-12-31 19:00:00.000000000 -0500
+++ mp3splt-2.1/audacitylabel.h	2007-09-29 16:17:29.000000000 -0400
@@ -0,0 +1,34 @@
+/*
+ * audacitylabel.h -- Audacity label file parser portion of the Mp3Splt utility
+ *                    Utility for mp3/ogg splitting without decoding
+ *
+ * Copyright (c) 2002-2004 M. Trotta - <[EMAIL PROTECTED]>
+ * Copyright (c) 2007 Federico Grau - <[EMAIL PROTECTED]>
+ *
+ * http://mp3splt.sourceforge.net
+ * http://audacity.sourceforge.net/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+ 
+#ifndef _MP3SPLT_AUDACITYLABEL_H
+#define _MP3SPLT_AUDACITYLABEL_H
+
+int get_audacitylabel_splitpoints(unsigned char *file, splt_state *state);
+
+#endif
+
diff -Naur mp3splt-2.1_ORIG/Makefile.am mp3splt-2.1/Makefile.am
--- mp3splt-2.1_ORIG/Makefile.am	2004-07-14 16:24:20.000000000 -0400
+++ mp3splt-2.1/Makefile.am	2007-09-29 14:35:49.000000000 -0400
@@ -8,6 +8,7 @@
 	mp3.c mp3.h \
 	wrap.c wrap.h \
 	cddb.c cddb.h \
+	audacitylabel.c audacitylabel.h \
 	ogg.c ogg.h
 
 mp3splt_LDADD = @OGG_LIBS@ @VORBIS_LIBS@
diff -Naur mp3splt-2.1_ORIG/mp3splt.c mp3splt-2.1/mp3splt.c
--- mp3splt-2.1_ORIG/mp3splt.c	2004-09-21 16:15:11.000000000 -0400
+++ mp3splt-2.1/mp3splt.c	2007-09-30 11:05:45.000000000 -0400
@@ -164,7 +164,7 @@
 	error(msg,erron);
 }
 
-unsigned char *get_out_filename(splt_state *state, unsigned char *filename, int num, char digits, int cddboption)
+unsigned char *get_out_filename(splt_state *state, unsigned char *filename, int num, char digits, int cddboption, int audacitylabeloption)
 {
 	char temp[256], fm[256];
 	int i;
@@ -198,6 +198,10 @@
 							{
 								sprintf(temp+2, state->format[i]+2);
 								sprintf(fm, temp, state->fn[num]);
+							} else if (audacitylabeloption)
+                            {
+								sprintf(temp+2, state->format[i]+2);
+								sprintf(fm, temp, state->fn[num]);
 							}
 							break;
 				case 'p':
@@ -227,7 +231,7 @@
 	FILE *file_input = NULL;
 	unsigned char filename[512];
 	int tracks = 0, stracks=0, i = 0, j = 0, k = 0, option, filenum=1, autowrap=0, gap=DEFAULT_GAP, rm=0;
-	short framemode=0, wrapoption=0, cddboption=0, listoption=0, errsyncoption = 0, outputdir = 0, timeoption=0, paramoption=0;
+	short framemode=0, wrapoption=0, cddboption=0, listoption=0, errsyncoption = 0, outputdir = 0, timeoption=0, paramoption=0, audacitylabeloption=0;
 	short noid3=0, quietoption=0, ogg=0, status = 0, silenceoption = 0, zpad=0, outformat=0, adjustoption=0, seekable=1;
 	char *ptr = NULL, id3buffer[128], *arg=NULL, *darg=NULL, *oarg=NULL, *parg=NULL;
 	char zstart[32], zend[32], digits='3';
@@ -237,7 +241,7 @@
 	fprintf (stderr, NAME" "VER" "YEAR" by "AUTHOR" "EMAIL"\n");
 	fprintf (stderr, "THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!\n");
 
-	while ((option=getopt(argc, argv, "fkwleqnasc:d:o:t:p:"))!=-1) {
+	while ((option=getopt(argc, argv, "fkwleqnasc:u:d:o:t:p:"))!=-1) {
 	  switch (option) {
 		case 'f': framemode=1;
 			break;
@@ -263,6 +267,9 @@
 		case 'c': cddboption=1;
 			arg = optarg;
 			break;
+		case 'u': audacitylabeloption=1;
+			arg = optarg;
+			break;
 		case 'd': outputdir=1;
 		  	darg = optarg;
 			break;
@@ -285,7 +292,7 @@
 		argc -= optind-1;
 	}
 
-	if ((argc<4)&&(!wrapoption)&&(!cddboption)&&(!errsyncoption)&&(!silenceoption)&&(!timeoption))
+	if ((argc<4)&&(!wrapoption)&&(!cddboption)&&(!audacitylabeloption)&&(!errsyncoption)&&(!silenceoption)&&(!timeoption))
 	{
 	   fprintf (stderr, "USAGE (Please read man page for complete documentation)\n");
 	   fprintf (stderr, "      mp3splt [OPTIONS] FILE... [BEGIN_TIME] [END_TIME...]\n");
@@ -297,6 +304,8 @@
 	   fprintf (stderr, " -f   Frame mode (mp3 only): process all frames. For higher precision and VBR.\n");
 	   fprintf (stderr, " -c + file.cddb, file.cue or \"query\". Get splitpoints and filenames from a\n");
 	   fprintf (stderr, "      .cddb or .cue file or from Internet (\"query\"). Use -a to auto-adjust.\n");
+	   fprintf (stderr, " -u + file. Get splitpoints and filenames from an Audacity label track\n");
+       fprintf (stderr, "      export file.\n");
 	   fprintf (stderr, " -t + TIME: to split files every fixed time len. (TIME format same as above). \n");
 	   fprintf (stderr, " -s   Silence detection: automatically find splitpoint. (Use -p for arguments)\n");
 	   fprintf (stderr, " -a   Auto-Adjust splitpoints with silence detection. (Use -p for arguments)\n");
@@ -320,6 +329,9 @@
 		if (cddboption && ((argc<2) || silenceoption || timeoption))
 			error("usage is 'mp3splt -c SOURCE FILE...''",1);
 
+		if (audacitylabeloption && ((argc<2) || silenceoption || timeoption)) // FIXME: check || donfede
+			error("usage is 'mp3splt -u SOURCE FILE...''",1);
+
 		if (silenceoption && ((argc<2) || wrapoption))
 			error("usage is 'mp3splt -s [th=THRESHOLD,nt=NUMBER,off=OFFSET,rm] FILE...'",1);
 
@@ -386,10 +398,13 @@
 			}
 			strncpy(state->performer[0], state->id.album, 128);
 			cleanstring(state->performer[0]);
-		}
+		} else if (audacitylabeloption) {
+			strncpy(filename, arg, 511);
+			tracks = get_audacitylabel_splitpoints(filename, state);
+        }
 		else tracks=0;
 
-		if (!cddboption && !errsyncoption && !silenceoption && !timeoption)
+		if (!cddboption && !audacitylabeloption && !errsyncoption && !silenceoption && !timeoption)
 		{
 			int timeptr;
 			for (i=2; i < argc; i++)
@@ -614,7 +629,7 @@
 				for (i = 0; i < state->mstate->syncerrors; i++) {
 					int ret;
 					if (outformat)
-						get_out_filename(state, filename, i+1, digits, 0);
+						get_out_filename(state, filename, i+1, digits, 0, 0);
 					else sprintf(filename, "Track %02d", i+1);
 					check_ext(filename, ogg);
 					if (outputdir)
@@ -759,7 +774,7 @@
 						float beg_pos, end_pos;
 
 						if (outformat)
-							get_out_filename(state, filename, i+1, digits, 0);
+							get_out_filename(state, filename, i+1, digits, 0, 0);
 						else sprintf(filename, "Track %02d", i+1);
 						check_ext(filename, ogg);
 						if (outputdir)
@@ -817,6 +832,11 @@
 					fprintf (stderr, "Album: %s\n\n", state->id.album);
 				}
 
+				if (!quietoption && audacitylabeloption) {
+					fprintf (stderr, "Reading informations from %s...\n", filename);
+					fprintf (stderr, "Tracks: %d \n\n", tracks);
+				}
+
 				if (timeoption)
 				{
 					if ((time_len = c_seconds(arg))==-1)
@@ -844,9 +864,19 @@
 						ptr = strchr(ptr, DIRCHAR) + 1;
 
 					if (outformat)
-						get_out_filename(state, filename, j, digits, cddboption);
+						get_out_filename(state, filename, j, digits, cddboption, audacitylabeloption);
 
-					if (!cddboption) {
+                    if (cddboption) {
+						memset(state->id.title, 0x00, 31);
+						strncpy(state->id.title, state->fn[j], 30);
+						if (!outformat)
+							sprintf (filename, "%s - %02d - %s", state->id.artist, j, state->fn[j]);
+                    } else if (audacitylabeloption) {
+						memset(state->id.title, 0x00, 31);
+						strncpy(state->id.title, state->fn[j], 30);
+						if (!outformat)
+							sprintf (filename, "%s", state->fn[j]);
+                    } else {
 						if (timeoption)
 						{
 							zero_pad_float(begin, zstart);
@@ -875,18 +905,14 @@
 							else sprintf (filename, "%s"SEP"%s", zstart, zend);
 						}
 					}
-					else {
-						memset(state->id.title, 0x00, 31);
-						strncpy(state->id.title, state->fn[j], 30);
-						if (!outformat)
-							sprintf (filename, "%s - %02d - %s", state->id.artist, j, state->fn[j]);
-					}
 
 					check_ext(filename, ogg);
 
 					if (!noid3) {
 						if (!cddboption) {
-							strncpy(state->id.title, ptr, 30);
+                            if (!audacitylabeloption) {
+							   strncpy(state->id.title, ptr, 30);
+                            }
 							strncpy(state->id.album, "Splitted by "NAME" v. "VER, 30);
 							strncpy(state->id.artist, "From \0", 6);
 							strncat(state->id.artist, zstart, 31-strlen(state->id.artist));

Attachment: signature.asc
Description: Digital signature

Reply via email to