mp3splt-gtk: src/libmp3splt_manager.c Source File

mp3splt-gtk 0.9.3.1519

Loading...
Searching...
No Matches
libmp3splt_manager.c
1/**********************************************************
2 *
3 * mp3splt-gtk -- utility based on mp3splt,
4 * for mp3/ogg splitting without decoding
5 *
6 * Copyright: (C) 2005-2014 Alexandru Munteanu
7 * Contact: m@ioalex.net
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
28 * USA.
29 *
30 *********************************************************/
31
32#include "libmp3splt_manager.h"
33
34static void lmanager_change_window_progress_bar(splt_progress *p_bar, void *data);
35static void lmanager_put_message_from_library(const char *message, splt_message_type mess_type, void *data);
36
37void lmanager_init_and_find_plugins(ui_state *ui)
38{
39 mp3splt_set_progress_function(ui->mp3splt_state, lmanager_change_window_progress_bar, ui);
40 mp3splt_set_split_filename_function(ui->mp3splt_state, lmanager_put_split_filename, ui);
41 mp3splt_set_message_function(ui->mp3splt_state, lmanager_put_message_from_library, ui);
42
43 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_DEBUG_MODE, SPLT_FALSE);
44 mp3splt_set_int_option(ui->mp3splt_state,
45 SPLT_OPT_SET_FILE_FROM_CUE_IF_FILE_TAG_FOUND, SPLT_TRUE);
46
47 gint error = mp3splt_find_plugins(ui->mp3splt_state);
48 if (error < 0)
49 {
50 char *error_from_library = mp3splt_get_strerror(ui->mp3splt_state, error);
51 if (error_from_library == NULL) { return; }
52 ui_fail(ui, error_from_library);
53 }
54}
55
56void lmanager_stop_split(ui_state *ui)
57{
58 gint err = mp3splt_stop_split(ui->mp3splt_state);
59 print_status_bar_confirmation(err, ui);
60}
61
62static gboolean lmanager_put_split_filename_idle(ui_with_fname *ui_fname)
63{
64 char *filename = ui_fname->fname;
65 ui_state *ui = ui_fname->ui;
66
67 add_split_row(filename, ui);
68
69 gint fname_status_size = (strlen(filename) + 255);
70 gchar *fname_status = g_malloc(sizeof(char) * fname_status_size);
71 g_snprintf(fname_status, fname_status_size, _(" File '%s' created"), filename);
72
73 put_status_message(fname_status, ui);
74
75 if (fname_status)
76 {
77 free(fname_status);
78 fname_status = NULL;
79 }
80
81 gtk_widget_set_sensitive(ui->gui->queue_files_button, TRUE);
82 gtk_widget_set_sensitive(ui->gui->remove_all_files_button, TRUE);
83
84 if (filename)
85 {
86 g_free(filename);
87 }
88 g_free(ui_fname);
89
90 return FALSE;
91}
92
94void lmanager_put_split_filename(const char *filename, void *data)
95{
96 ui_state *ui = (ui_state *)data;
97
98 ui_with_fname *ui_fname = g_malloc0(sizeof(ui_with_fname));
99 ui_fname->ui = ui;
100 ui_fname->fname = NULL;
101 if (filename)
102 {
103 ui_fname->fname = strdup(filename);
104 }
105
106 add_idle(G_PRIORITY_HIGH_IDLE,
107 (GSourceFunc)lmanager_put_split_filename_idle, ui_fname, NULL);
108}
109
110static gboolean lmanager_put_message_from_library_idle(ui_with_message *ui_message)
111{
112 splt_message_type mess_type = ui_message->mess_type;
113 ui_state *ui = ui_message->ui;
114
115 char *mess = ui_message->message;
116 if (mess)
117 {
118 gint i = 0;
119 //replace '\n' with ' '
120 for (i = 0;i < strlen(mess);i++)
121 {
122 if (mess[i] == '\n')
123 {
124 mess[i] = ' ';
125 }
126 }
127
128 put_status_message_with_type(mess, mess_type, ui);
129
130 g_free(mess);
131 mess = NULL;
132 }
133
134 g_free(ui_message);
135
136 return FALSE;
137}
138
140static void lmanager_put_message_from_library(const char *message, splt_message_type mess_type, void *data)
141{
142 ui_state *ui = (ui_state *)data;
143
144 ui_with_message *ui_message = g_malloc0(sizeof(ui_with_message));
145 ui_message->ui = ui;
146 ui_message->message = NULL;
147 if (message)
148 {
149 ui_message->message = strdup(message);
150 }
151 ui_message->mess_type = mess_type;
152
153 add_idle(G_PRIORITY_HIGH_IDLE,
154 (GSourceFunc)lmanager_put_message_from_library_idle, ui_message, NULL);
155}
156
157static gboolean lmanager_change_window_progress_bar_idle(ui_with_p_bar *ui_p_bar)
158{
159 ui_state *ui = ui_p_bar->ui;
160
161 gchar progress_text[1024] = " ";
162
163 switch (ui_p_bar->progress_type)
164 {
165 case SPLT_PROGRESS_PREPARE:
166 g_snprintf(progress_text,1023, _(" preparing \"%s\" (%d of %d)"),
167 ui_p_bar->filename_shorted,
168 ui_p_bar->current_split,
169 ui_p_bar->max_splits);
170 break;
171 case SPLT_PROGRESS_CREATE:
172 g_snprintf(progress_text,1023, _(" creating \"%s\" (%d of %d)"),
173 ui_p_bar->filename_shorted,
174 ui_p_bar->current_split,
175 ui_p_bar->max_splits);
176 break;
177 case SPLT_PROGRESS_SEARCH_SYNC:
178 g_snprintf(progress_text,1023, _(" searching for sync errors..."));
179 break;
180 case SPLT_PROGRESS_SCAN_SILENCE:
181 if (get_currently_scanning_for_silence_safe(ui))
182 {
183 g_snprintf(progress_text,1023, _("Computing amplitude wave data..."));
184 }
185 else
186 {
187 g_snprintf(progress_text,1023,
188 _("S: %02d, Level: %.2f dB; scanning for silence..."),
189 ui_p_bar->silence_found_tracks, ui_p_bar->silence_db_level);
190 }
191 break;
192 default:
193 g_snprintf(progress_text,1023, " ");
194 break;
195 }
196
197 gchar printed_value[1024] = { '\0' };
198 g_snprintf(printed_value, 1023, "%6.2f %% %s", ui_p_bar->percent_progress * 100, progress_text);
199
200 gtk_progress_bar_set_fraction(ui->gui->percent_progress_bar, ui_p_bar->percent_progress);
201 gtk_progress_bar_set_text(ui->gui->percent_progress_bar, printed_value);
202
203 if (ui_p_bar->filename_shorted)
204 {
205 g_free(ui_p_bar->filename_shorted);
206 }
207 g_free(ui_p_bar);
208
209 return FALSE;
210}
211
213static void lmanager_change_window_progress_bar(splt_progress *p_bar, void *data)
214{
215 ui_state *ui = (ui_state *) data;
216
217 ui_with_p_bar *ui_p_bar = g_malloc0(sizeof(ui_with_p_bar));
218 ui_p_bar->ui = ui;
219
220 ui_p_bar->progress_type = mp3splt_progress_get_type(p_bar);
221 ui_p_bar->filename_shorted = mp3splt_progress_get_filename_shorted(p_bar);
222 ui_p_bar->current_split = mp3splt_progress_get_current_split(p_bar);
223 ui_p_bar->max_splits = mp3splt_progress_get_max_splits(p_bar);
224 ui_p_bar->silence_found_tracks = mp3splt_progress_get_silence_found_tracks(p_bar);
225 ui_p_bar->silence_db_level = mp3splt_progress_get_silence_db_level(p_bar);
226 ui_p_bar->percent_progress = mp3splt_progress_get_percent_progress(p_bar);
227
228 add_idle(G_PRIORITY_HIGH_IDLE,
229 (GSourceFunc)lmanager_change_window_progress_bar_idle, ui_p_bar, NULL);
230}
231
print_status_bar_confirmation
void print_status_bar_confirmation(gint error, ui_state *ui)
Output an error message from libmp3splt to the status bar.
Definition main_window.c:1344
put_status_message_with_type
void put_status_message_with_type(const gchar *text, splt_message_type mess_type, ui_state *ui)
Output a message to the status message bar.
Definition main_window.c:277
put_status_message
void put_status_message(const gchar *text, ui_state *ui)
Output a info message to the status message bar.
Definition main_window.c:263
add_split_row
void add_split_row(const gchar *name, ui_state *ui)
add a row to the table
Definition split_files_window.c:104
ui_state
Definition ui_types.h:509
ui_with_fname
Definition ui_types.h:545
ui_with_message
Definition libmp3splt_manager.h:53
ui_with_p_bar
Definition libmp3splt_manager.h:42