mp3splt-gtk

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

export.c
Go to the documentation of this file.
1 /**********************************************************
2 *
3 * mp3splt-gtk -- utility based on mp3splt,
4 * for mp3/ogg splitting without decoding
5 *
6 * Copyright: (C) 2005-2010 Alexandru Munteanu
7 * Contact: io_fx@yahoo.fr
8 *
9 * http://mp3splt.sourceforge.net/
10 *
11 *********************************************************/
12
13 /**********************************************************
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 * USA.
29 *
30 *********************************************************/
31
32 /*!********************************************************
33 * \file
34 * The function that allows to export the current list of
35 * splitpoints as a Cue sheet.
36 *********************************************************/
37
38 #include <gtk/gtk.h>
39 #include <glib/gi18n.h>
40 #include <string.h>
41 #include <errno.h>
42 #include <stdio.h>
43 #include "export.h"
44 #include "main_win.h"
45 #include "player_tab.h"
46 #include "tree_tab.h"
47 #include "ui_manager.h"
48 #include "widgets_helper.h"
49
50 extern ui_state *ui;
51
64 void export_file(const gchar* filename)
65 {
66 FILE *outfile;
67 GtkTreeModel *model;
68 GtkTreeIter iter;
69
70 if((outfile=fopen(filename,"w"))==0)
71 {
72 put_status_message((gchar *)strerror(errno));
73 return;
74 };
75
76 if(fprintf(outfile,"REM CREATOR \"MP3SPLT_GTK\"\n")<0)
77 {
78 put_status_message((gchar *)strerror(errno));
79 return;
80 }
81
82 if(fprintf(outfile,"REM SPLT_TITLE_IS_FILENAME\n")<0)
83 {
84 put_status_message((gchar *)strerror(errno));
85 return;
86 }
87
88 // Determine which type our input file is of.
89 gchar *extension=inputfilename_get();
90 gchar *tmp;
91 while((tmp=strchr(extension,'.')))
92 {
93 extension=++tmp;
94 }
95
96 if(fprintf(outfile,"FILE \"%s\" %s\n",inputfilename_get(),extension)<0)
97 {
98 put_status_message((gchar *)strerror(errno));
99 return;
100 };
101
102 model = gtk_tree_view_get_model(tree_view);
103
104 //if the table is not empty get iter number
105 if(gtk_tree_model_get_iter_first(model, &iter))
106 {
107 // The track number
108 gint count = 1;
109
110 do
111 {
112 // All information we need for this track
113 gchar *description;
114 gint mins,secs,hundr;
115 gboolean keep;
116
117 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter,
118 COL_DESCRIPTION,&description,
119 COL_MINUTES, &mins,
120 COL_SECONDS, &secs,
121 COL_HUNDR_SECS, &hundr,
122 COL_CHECK, &keep,
123 -1);
124
125 // Sometimes libmp3splt introduces an additional split point
126 // way below the end of the file --- that breaks cue import
127 // later => skip all points with extremely high time values.
128 if(mins<357850)
129 {
130 // Output the track header
131 if(fprintf(outfile,"\tTRACK %02i AUDIO\n",count++)<0)
132 {
133 put_status_message((gchar *)strerror(errno));
134 return;
135 };
136
137
138 // Output the track description escaping any quotes
139 if(fprintf(outfile,"\t\tTITLE \"")<0)
140 {
141 put_status_message((gchar *)strerror(errno));
142 return;
143 }
144
145 gchar *outputchar;
146 for(outputchar=description;*outputchar!='\0';outputchar++)
147 {
148 if(*outputchar=='"')
149 {
150 if(fprintf(outfile,"\\\"")<0)
151 {
152 put_status_message((gchar *)strerror(errno));
153 return;
154 }
155 }
156 else
157 {
158 if(fprintf(outfile,"%c",*outputchar)<0)
159 {
160 put_status_message((gchar *)strerror(errno));
161 return;
162 }
163 }
164 }
165 if(fprintf(outfile,"\" \n")<0)
166 {
167 put_status_message((gchar *)strerror(errno));
168 return;
169 };
170
171 if(!keep)
172 {
173 if(fprintf(outfile,"\t\tREM NOKEEP\n")<0)
174 {
175 put_status_message((gchar *)strerror(errno));
176 return;
177 }
178 }
179
180 if(fprintf(outfile,"\t\tINDEX 01 %d:%02d:%02d\n",mins,secs,hundr)<0)
181 {
182 put_status_message((gchar *)strerror(errno));
183 return;
184 }
185 }
186 } while(gtk_tree_model_iter_next(model, &iter));
187 }
188
189 fclose(outfile);
190 }
191
193 void ChooseCueExportFile(GtkWidget *widget, gpointer data)
194 {
195 // file chooser
196 GtkWidget *file_chooser;
197
198 //creates the dialog
199 file_chooser = gtk_file_chooser_dialog_new(_("Select cue file name"),
200 NULL,
201 GTK_FILE_CHOOSER_ACTION_SAVE,
202 GTK_STOCK_CANCEL,
203 GTK_RESPONSE_CANCEL,
204 GTK_STOCK_SAVE,
205 GTK_RESPONSE_ACCEPT,
206 NULL);
207
208 wh_set_browser_directory_handler(ui, file_chooser);
209
210 // tells the dialog to list only cue files
211 GtkWidget *our_filter = (GtkWidget *)gtk_file_filter_new();
212 gtk_file_filter_set_name (GTK_FILE_FILTER(our_filter), _("cue files (*.cue)"));
213 gtk_file_filter_add_pattern(GTK_FILE_FILTER(our_filter), "*.cue");
214 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(file_chooser), GTK_FILE_FILTER(our_filter));
215 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(file_chooser),TRUE);
216
217
218 if (gtk_dialog_run(GTK_DIALOG(file_chooser)) == GTK_RESPONSE_ACCEPT)
219 {
220 gchar *filename =
221 gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_chooser));
222
223 //Write the output file
224 export_file(filename);
225 g_free(filename);
226 }
227
228 //destroy the dialog
229 gtk_widget_destroy(file_chooser);
230 }
231