Permalink
Browse files

Merge pull request #2 from erikd/master

Please pull this set of changes
  • Loading branch information...
2 parents 3e530ab + 9ab4109 commit 27a78f397f4ed9d79196efb2f2c3d707655ed217 @kfish committed Feb 1, 2012
View
21 configure.ac
@@ -128,6 +128,23 @@ if test "x$HAVE_LIBSNDFILE1" = xmaybe ; then
fi
fi
+dnl
+dnl Detect tdb (Tiny Database library)
+dnl
+
+PKG_CHECK_MODULES(TDB, tdb >= 1.2.0,
+ HAVE_LIBTDB="yes", HAVE_LIBTDB="no")
+
+if test "x$HAVE_LIBTDB" = xyes ; then
+ AC_DEFINE([HAVE_LIBTDB], [], [Define if we have tdb.])
+ AC_SUBST(TDB_CFLAGS)
+ AC_SUBST(TDB_LIBS)
+else
+ sweep_config_ok="no"
+fi
+
+
+
AC_CHECK_SIZEOF(off_t,1)
@@ -590,7 +607,7 @@ if test "x$HAVE_VORBIS" != xyes ; then
fi
if test "x$HAVE_GLIB" = xmaybe || test "x$HAVE_GTK" = xmaybe ||
- test "x$HAVE_LIBSNDFILE1" = xmaybe || test "x$HAVE_TDB" = xmaybe ||
+ test "x$HAVE_LIBSNDFILE1" = xmaybe || test "x$HAVE_LIBTDB" = xmaybe ||
test "x$HAVE_GTHREADS" = xmaybe || test "x$HAVE_ALSA" = xmaybe ||
test "x$HAVE_OGG" = xmaybe || test "x$HAVE_VORBIS" = xmaybe ; then
AC_MSG_RESULT([
@@ -631,7 +648,6 @@ m4/Makefile
include/Makefile
include/sweep/Makefile
src/Makefile
-src/tdb/Makefile
plugins/Makefile
plugins/echo/Makefile
plugins/normalise/Makefile
@@ -659,6 +675,7 @@ AC_MSG_RESULT([
** MPEG (MP3) loading: ...... $HAVE_MAD
** Speex support: ........... $HAVE_SPEEX
** Secret Rabbit Code: ...... $HAVE_LIBSAMPLERATE
+** libtdb for preferences: .. $HAVE_LIBTDB
** Translations: ............ $ALL_LINGUAS
**
** Installation directories:
View
4 include/sweep/sweep_undo.h
@@ -27,11 +27,11 @@ gint
update_edit_progress (gpointer data);
sw_op_instance *
-sw_op_instance_new (sw_sample * sample, char * description,
+sw_op_instance_new (sw_sample * sample, const char * description,
sw_operation * operation);
void
-schedule_operation (sw_sample * sample, char * description,
+schedule_operation (sw_sample * sample, const char * description,
sw_operation * operation, void * do_data);
void
View
14 src/Makefile.am
@@ -1,7 +1,5 @@
## Process this file with automake to produce Makefile.in
-SUBDIRS = tdb
-
AM_CFLAGS = \
$(GTK_DISABLE_DEPRECATED) \
-DPACKAGE_DATA_DIR='@PACKAGE_DATA_DIR@' \
@@ -12,14 +10,12 @@ AM_CFLAGS = \
@GLIB_CFLAGS@ \
@GTHREADS_CFLAGS@ \
@ALSA_CFLAGS@ \
- @PULSEAUDIO_CFLAGS@
+ @PULSEAUDIO_CFLAGS@ \
+ @TDB_CFLAGS@
INCLUDES = \
-I$(top_srcdir)/intl \
- -I$(top_srcdir)/include \
- -I$(top_srcdir)/src/tdb
-
-TDB_LIBS = $(top_builddir)/src/tdb/libtdb.a
+ -I$(top_srcdir)/include
bin_PROGRAMS = sweep
@@ -40,7 +36,7 @@ sweep_SOURCES = \
edit.c edit.h \
file_dialogs.c file_dialogs.h \
file_sndfile.h \
- file_sndfile1.c \
+ file_sndfile.c \
file_mad.c \
file_speex.c \
file_vorbis.c \
@@ -74,7 +70,7 @@ sweep_SOURCES = \
view.c view.h \
view_pixmaps.h
-sweep_LDADD = $(TDB_LIBS) \
+sweep_LDADD = @TDB_LIBS@ \
@GTK_LIBS@ $(INTLLIBS) $(PTHREAD_LIBS) \
$(SNDFILE_LIBS) \
$(OGG_LIBS) $(VORBIS_LIBS) $(VORBISFILE_LIBS) $(VORBISENC_LIBS) \
View
13 src/channelops.c
@@ -146,7 +146,7 @@ dup_channels (sw_sample * sample, int new_channels)
g_snprintf (buf, sizeof (buf), _("Duplicate from %d to %d channels"),
sample->sounddata->format->channels, new_channels);
}
-
+
schedule_operation (sample, buf, &dup_channels_op,
GINT_TO_POINTER(new_channels));
}
@@ -195,12 +195,9 @@ dup_channels_dialog_new_cb (GtkWidget * widget, gpointer data)
sw_sample * sample = view->sample;
GtkWidget * dialog;
GtkWidget * main_vbox;
- /*GtkWidget * label;*/
GtkWidget * chooser;
GtkWidget * button, * ok_button;
- /*gchar * current;*/
-
dialog = gtk_dialog_new ();
gtk_window_set_title (GTK_WINDOW(dialog), _("Sweep: Duplicate channel"));
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
@@ -488,7 +485,7 @@ do_stereo_swap (sw_sample * sample, gpointer data)
remaining -= n;
run_total += n;
-
+
percent = run_total / ctotal;
sample_set_progress_percent (sample, percent);
}
@@ -630,7 +627,7 @@ change_channels (sw_sample * sample, int new_channels)
g_snprintf (buf, sizeof (buf), _("Convert from %d to %d channels"),
sample->sounddata->format->channels, new_channels);
-
+
schedule_operation (sample, buf, &change_channels_op,
GINT_TO_POINTER(new_channels));
}
@@ -674,7 +671,7 @@ channels_dialog_new_cb (GtkWidget * widget, gpointer data)
GtkWidget * chooser;
GtkWidget * button, * ok_button;
- gchar * current;
+ gchar current [128];
dialog = gtk_dialog_new ();
gtk_window_set_title (GTK_WINDOW(dialog), _("Sweep: Add/Remove channels"));
@@ -683,7 +680,7 @@ channels_dialog_new_cb (GtkWidget * widget, gpointer data)
main_vbox = GTK_DIALOG(dialog)->vbox;
- current = g_strdup_printf (_("Currently: %d channels"),
+ snprintf (current, sizeof (current), _("Currently: %d channels"),
sample->sounddata->format->channels);
label = gtk_label_new (current);
gtk_box_pack_start (GTK_BOX(main_vbox), label, TRUE, TRUE, 8);
View
10 src/db_slider.c
@@ -120,15 +120,15 @@ db_slider_value_changed_cb (GtkWidget * widget, gpointer data)
{
GtkWidget * slider = (GtkWidget *)data;
gfloat value, db_value;
- gchar * db_text;
+ gchar db_text [16];
value = db_slider_get_value (DB_SLIDER(slider));
db_value = VALUE_TO_DB (value);
if (db_value > -10.0) {
- db_text = g_strdup_printf ("%1.1f dB", db_value);
+ snprintf (db_text, sizeof (db_text), "%1.1f dB", db_value);
} else {
- db_text = g_strdup_printf ("%2.0f dB", db_value);
+ snprintf (db_text, sizeof (db_text), "%2.0f dB", db_value);
}
gtk_label_set_text (GTK_LABEL(DB_SLIDER(slider)->db_label), db_text);
@@ -148,7 +148,7 @@ db_slider_build (GtkWidget * slider, gchar * title, gfloat value)
GtkObject * adj;
- gchar * range_text;
+ gchar range_text [128];
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER(slider), vbox);
@@ -182,7 +182,7 @@ db_slider_build (GtkWidget * slider, gchar * title, gfloat value)
db_slider_value_changed_cb (NULL, slider);
- range_text = g_strdup_printf ("%s\n[%2.0f to %2.0f dB]",
+ snprintf (range_text, sizeof (range_text), "%s\n[%2.0f to %2.0f dB]",
title,
VALUE_TO_DB(DB_SLIDER(slider)->lower),
VALUE_TO_DB(DB_SLIDER(slider)->upper));
View
55 src/driver.c
@@ -71,81 +71,78 @@ static sw_driver * dialog_driver = &_driver_null;
static char * prefs_driver_key = "driver";
-char *
+const char *
pcmio_get_default_main_dev (void)
{
+ static char name [128];
GList * names = NULL, * gl;
if (dialog_driver->get_names)
names = dialog_driver->get_names ();
if ((gl = names) != NULL) {
- return (char *)gl->data;
+ strncpy (name, gl->data, sizeof (name));
+ return name;
}
return "Default";
}
-char *
+const char *
pcmio_get_default_monitor_dev (void)
{
+ static char name [128];
GList * names = NULL, * gl;
if (dialog_driver->get_names)
names = dialog_driver->get_names ();
if ((gl = names) != NULL) {
if ((gl = gl->next) != NULL) {
- return (char *)gl->data;
+ strncpy (name, gl->data, sizeof (name));
+ return name;
}
}
return "Default";
}
-char *
+const char *
pcmio_get_main_dev (void)
{
- char * main_dev;
+ static char main_dev [128];
- main_dev = prefs_get_string (dialog_driver->primary_device_key);
+ prefs_get_string (dialog_driver->primary_device_key, main_dev, sizeof (main_dev), "");
- if (main_dev == NULL) return pcmio_get_default_main_dev();
+ if (main_dev [0] == 0)
+ return pcmio_get_default_main_dev();
return main_dev;
}
-char *
+const char *
pcmio_get_monitor_dev (void)
{
- char * monitor_dev;
+ static char monitor_dev [128];
- monitor_dev = prefs_get_string (dialog_driver->monitor_device_key);
+ prefs_get_string (dialog_driver->monitor_device_key, monitor_dev, sizeof (monitor_dev), "");
- if (monitor_dev == NULL) return pcmio_get_default_monitor_dev ();
+ if (monitor_dev [0] == 0)
+ return pcmio_get_default_monitor_dev ();
return monitor_dev;
}
gboolean
pcmio_get_use_monitor (void)
{
- int * use_monitor;
-
- use_monitor = prefs_get_int (USE_MONITOR_KEY);
-
- if (use_monitor == NULL) return DEFAULT_USE_MONITOR;
- else return (*use_monitor != 0);
+ return prefs_get_int (USE_MONITOR_KEY, DEFAULT_USE_MONITOR);
}
int
pcmio_get_log_frags (void)
{
- int * log_frags;
-
- log_frags = prefs_get_int (dialog_driver->log_frags_key);
- if (log_frags == NULL) return DEFAULT_LOG_FRAGS;
- else return (*log_frags);
+ return prefs_get_int (dialog_driver->log_frags_key, DEFAULT_LOG_FRAGS);
}
extern GtkStyle * style_bw;
@@ -322,7 +319,7 @@ static void
pcmio_devname_reset_cb (GtkWidget * widget, gpointer data)
{
GtkWidget * dialog = GTK_WIDGET (data);
- char * main_dev, * monitor_dev;
+ const char * main_dev, * monitor_dev;
main_dev = pcmio_get_main_dev ();
monitor_dev = pcmio_get_monitor_dev ();
@@ -339,7 +336,7 @@ static void
pcmio_devname_default_cb (GtkWidget * widget, gpointer data)
{
GtkWidget * dialog = GTK_WIDGET (data);
- char * name;
+ const char * name;
if ((name = pcmio_get_default_main_dev ()) != NULL) {
gtk_entry_set_text (GTK_ENTRY(GTK_COMBO(main_combo)->entry), name);
@@ -764,7 +761,7 @@ device_read (sw_handle * handle, sw_audio_t * buf, size_t count)
}
ssize_t
-device_write (sw_handle * handle, sw_audio_t * buf, size_t count)
+device_write (sw_handle * handle, const sw_audio_t * buf, size_t count)
{
#ifdef DEBUG
printf ("device_write: %d from %d\n", count, offset);
@@ -818,7 +815,7 @@ device_close (sw_handle * handle)
void
init_devices (void)
{
- const char * driver;
+ char driver [64];
int k = 0;
memset (driver_table, 0, sizeof (driver_table));
@@ -833,13 +830,13 @@ init_devices (void)
if (driver_solaris->name != NULL)
driver_table [k++] = driver_solaris;
- driver = prefs_get_string (prefs_driver_key);
+ prefs_get_string (prefs_driver_key, driver, sizeof (driver), "");
/* Set a default in case preferences driver doesn't exist. */
current_driver = driver_table [0];
/* Switch to driver from preferences if possible. */
- if (driver != NULL)
+ if (driver [0] != 0)
for (k = 0 ; driver_table [k] != NULL ; k++)
if (strcmp (driver, driver_table [k]->name) == 0)
current_driver = driver_table [k];
View
12 src/driver.h
@@ -45,13 +45,13 @@ struct _sw_driver {
void (*setup) (sw_handle * handle, sw_format * format);
int (*wait) (sw_handle * handle);
ssize_t (*read) (sw_handle * handle, sw_audio_t * buf, size_t count);
- ssize_t (*write) (sw_handle * handle, sw_audio_t * buf, size_t count);
+ ssize_t (*write) (sw_handle * handle, const sw_audio_t * buf, size_t count);
sw_framecount_t (*offset) (sw_handle * handle);
void (*reset) (sw_handle * handle);
void (*flush) (sw_handle * handle);
void (*drain) (sw_handle * handle);
void (*close) (sw_handle * handle);
-
+
char * primary_device_key;
char * monitor_device_key;
char * log_frags_key;
@@ -76,20 +76,20 @@ ssize_t
device_read (sw_handle * handle, sw_audio_t * buf, size_t count);
ssize_t
-device_write (sw_handle * handle, sw_audio_t * buf, size_t count);
+device_write (sw_handle * handle, const sw_audio_t * buf, size_t count);
/* As far as I'm aware the method
* used to monitor latency in OSS and Solaris etc. is different to that which
* ALSA uses, and different again from JACK and PortAudio.
- *
+ *
* Basically, when the device is written to, the driver is also told what the
* offset into the file is for that bit of sound.
- *
+ *
* Then, when the GUI thread goes to draw the cursor, it asks the driver
* what the offset of the sound that's currently coming out of the speaker is
* and draws it there (which may be a little behind or ahead of where the
* user is scrubbing) -- hence the sound and the vision are kept in sync.
- *
+ *
* However, this is all currently disabled, and going to change, as its not
* properly monitoring the latency of multiple files being played
* simultaneously; plus it may have to change with respect to ALSA and JACK and
View
4 src/driver_alsa.c
@@ -126,7 +126,7 @@ static sw_handle *
alsa_device_open (int monitoring, int flags)
{
int err;
- char * alsa_pcm_name;
+ const char * alsa_pcm_name;
snd_pcm_t * pcm_handle;
sw_handle * handle = &alsa_handle;
snd_pcm_stream_t stream;
@@ -322,7 +322,7 @@ alsa_device_read (sw_handle * handle, sw_audio_t * buf, size_t count)
}
static ssize_t
-alsa_device_write (sw_handle * handle, sw_audio_t * buf, size_t count)
+alsa_device_write (sw_handle * handle, const sw_audio_t * buf, size_t count)
{
snd_pcm_t * pcm_handle = (snd_pcm_t *)handle->custom_data;
snd_pcm_uframes_t uframes;
View
10 src/driver_oss.c
@@ -97,7 +97,7 @@ oss_get_names (void)
static sw_handle *
oss_open (int monitoring, int flags)
{
- char * dev_name;
+ const char * dev_name;
int dev_dsp;
sw_handle * handle = &oss_handle;
int i;
@@ -178,7 +178,7 @@ oss_setup (sw_handle * handle, sw_format * format)
#ifdef DEBUG
g_print ("Got %d frags of size 2^%d\n", nfrags, fragsize);
#endif
-
+
bits = 16 ;
if ((error = ioctl (dev_dsp, SOUND_PCM_WRITE_BITS, &bits)) != 0) {
perror ("open_dsp_device 4 ");
@@ -281,7 +281,7 @@ oss_read (sw_handle * handle, sw_audio_t * buf, size_t count)
if (need_bswap) {
unsigned char * ucptr = (unsigned char *)bbuf;
unsigned char temp;
-
+
for (i = 0; i < count; i++) {
temp = ucptr[2 * i];
ucptr[2 * i] = ucptr [2 * i + 1];
@@ -299,7 +299,7 @@ oss_read (sw_handle * handle, sw_audio_t * buf, size_t count)
#define PLAYBACK_SCALE (32768 / SW_AUDIO_T_MAX)
static ssize_t
-oss_write (sw_handle * handle, sw_audio_t * buf, size_t count)
+oss_write (sw_handle * handle, const sw_audio_t * buf, size_t count)
{
gint16 * bbuf;
size_t byte_count;
@@ -331,7 +331,7 @@ oss_write (sw_handle * handle, sw_audio_t * buf, size_t count)
if (need_bswap) {
unsigned char * ucptr = (unsigned char *)bbuf;
unsigned char temp;
-
+
for (i = 0; i < count; i++) {
temp = ucptr[2 * i];
ucptr[2 * i] = ucptr [2 * i + 1];
View
4 src/driver_pulseaudio.c
@@ -96,7 +96,7 @@ pulse_setup (sw_handle * handle, sw_format * format)
fprintf(stderr, __FILE__": pulse_setup(): The maximum number of channels supported is %d, while %d have been requested.\n", PA_CHANNELS_MAX, format->channels);
return;
}
-
+
ss.format = PA_SAMPLE_FLOAT32;
ss.rate = format->rate;
ss.channels = format->channels;
@@ -144,7 +144,7 @@ pulse_read (sw_handle * handle, sw_audio_t * buf, size_t count)
}
static ssize_t
-pulse_write (sw_handle * handle, sw_audio_t * buf, size_t count)
+pulse_write (sw_handle * handle, const sw_audio_t * buf, size_t count)
{
struct pa_simple * pa ;
int error;
View
2 src/driver_solaris.c
@@ -87,7 +87,7 @@ solaris_setup (sw_handle * handle, sw_format * format)
}
static ssize_t
-solaris_write (sw_handle * handle, void * buf, size_t count)
+solaris_write (sw_handle * handle, const void * buf, size_t count)
{
return write (handle->driver_fd, buf, count);
}
View
121 src/file_dialogs.c
@@ -235,11 +235,11 @@ try_sample_load (char * pathname)
#endif
if (sample == NULL)
- sample = sndfile_sample_load (pathname, TRUE);
-
+ sample = sndfile_sample_load (pathname, TRUE);
+
if (sample != NULL)
recent_manager_add_item (pathname);
-
+
return sample;
}
@@ -261,7 +261,7 @@ sample_load (char * pathname)
}
} else {
prefs_set_string (LAST_LOAD_KEY, pathname);
-
+
return try_sample_load (pathname);
}
}
@@ -274,12 +274,12 @@ sample_load_cb(GtkWidget * widget, gpointer data)
{
GtkWidget *dialog;
- gchar *load_current_file;
+ gchar load_current_file [512];
gint win_width, win_height;
GSList *filenames, *list;
-
+
filenames = list = NULL;
-
+
win_width = gdk_screen_width () / 2;
win_height = gdk_screen_height () / 2;
@@ -289,42 +289,40 @@ sample_load_cb(GtkWidget * widget, gpointer data)
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
-
+
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
gtk_widget_set_size_request (dialog, win_width, win_height);
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
-
+
sweep_set_window_icon (GTK_WINDOW(dialog));
attach_window_close_accel(GTK_WINDOW(dialog));
-
- load_current_file = prefs_get_string (LAST_LOAD_KEY);
-
- if (load_current_file) {
+
+ prefs_get_string (LAST_LOAD_KEY, load_current_file, sizeof (load_current_file), "");
+
+ if (load_current_file [0]) {
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER(dialog), load_current_file);
-
- g_free(load_current_file);
}
-
+
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
-
- filenames = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(dialog));
-
+
+ filenames = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(dialog));
+
for (list = filenames; list; list = list->next) {
if (list->data) {
sample_load ((gchar *)list->data);
g_free (list->data);
- }
+ }
}
-
+
if (filenames)
g_slist_free(filenames);
-
+
} else {
/* do nothing so exit */
sample_bank_remove(NULL);
}
-
+
gtk_widget_destroy (dialog);
}
@@ -358,7 +356,7 @@ sample_revert_cb (GtkWidget * widget, gpointer data)
sw_view * view = (sw_view *)data;
sw_sample * sample;
char buf[512];
-
+
sample = view->sample;
snprintf (buf, sizeof (buf),
@@ -437,7 +435,7 @@ file_guess_method (sw_sample * sample, char * pathname)
for (i = 0; i < count ; i++) {
info.format = i ;
sf_command (NULL, SFC_GET_FORMAT_MAJOR, &info, sizeof (info)) ;
-
+
if (!g_strncasecmp (ext, info.extension, SW_DIR_LEN)) {
sample->file_method = SWEEP_FILE_METHOD_LIBSNDFILE;
sample->file_format = info.format;
@@ -477,7 +475,7 @@ file_guess_method (sw_sample * sample, char * pathname)
}
guess_raw:
-
+
if (sample->file_method == SWEEP_FILE_METHOD_BY_EXTENSION) {
sample->file_method = SWEEP_FILE_METHOD_LIBSNDFILE;
#if defined (SNDFILE_1)
@@ -488,7 +486,7 @@ file_guess_method (sw_sample * sample, char * pathname)
}
return;
-}
+}
typedef struct {
sw_sample * sample;
@@ -535,11 +533,10 @@ static void
overwrite_cancel_cb (GtkWidget * widget, gpointer data)
{
save_as_data * sd = (save_as_data *)data;
- gchar * msg;
+ gchar msg [1024];
- msg = g_strdup_printf (_("Save as %s cancelled"), g_basename (sd->pathname));
+ snprintf (msg, sizeof (msg), _("Save as %s cancelled"), g_basename (sd->pathname));
sample_set_tmp_message (sd->sample, msg);
- g_free (msg);
g_free (sd);
}
@@ -687,11 +684,10 @@ sample_save_as_cb(GtkWidget * widget, gpointer data)
save_as_data * sd;
char buf[512];
- char * last_save;
win_width = gdk_screen_width () / 2;
win_height = gdk_screen_height () / 2;
-
+
sample = view->sample;
dialog = gtk_file_chooser_dialog_new (_("Sweep: Save file"),
@@ -700,63 +696,62 @@ sample_save_as_cb(GtkWidget * widget, gpointer data)
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
NULL);
-
-
+
+
//gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
attach_window_close_accel(GTK_WINDOW(dialog));
sweep_set_window_icon (GTK_WINDOW(dialog));
-
+
save_options = gtk_hbox_new (TRUE, 1);
frame = gtk_frame_new (_("Save Options"));
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
gtk_box_pack_start (GTK_BOX (save_options), frame, TRUE, TRUE, 4);
-
+
hbox = gtk_hbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
gtk_container_add (GTK_CONTAINER (frame), hbox);
gtk_widget_show (hbox);
-
+
label = gtk_label_new (_("Determine File Type:"));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
-
+
option_menu = gtk_option_menu_new ();
gtk_box_pack_start (GTK_BOX (hbox), option_menu, TRUE, TRUE, 0);
gtk_widget_show (option_menu);
-
+
save_menu = create_save_menu (sample);
gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), save_menu);
-
+
gtk_widget_show (frame);
/* pack the containing save_options hbox into the save-dialog */
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
save_options, FALSE, FALSE, 0);
gtk_widget_show (save_options);
-
+
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
gtk_widget_set_size_request (dialog, win_width, win_height);
-
+
if (strcmp (g_path_get_dirname(sample->pathname), ".") == 0) {
+ char last_save [512];
- last_save = prefs_get_string (LAST_SAVE_KEY);
+ prefs_get_string (LAST_SAVE_KEY, last_save, sizeof (last_save), "");
- if (last_save != NULL) {
+ if (last_save [0]) {
gchar * last_save_dir = g_dirname (last_save);
-
+
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog),
- last_save_dir);
+ last_save_dir);
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(dialog),
sample->pathname);
g_free (last_save_dir);
- g_free (last_save);
-
- }
+ }
} else {
- retval = gtk_file_chooser_set_filename (GTK_FILE_CHOOSER(dialog),
+ retval = gtk_file_chooser_set_filename (GTK_FILE_CHOOSER(dialog),
sample->pathname);
/* FIXME: bug (local only?) causes gtk_file_chooser_set_filename
to fail silently in some cases*/
@@ -765,9 +760,9 @@ sample_save_as_cb(GtkWidget * widget, gpointer data)
//printf("sample->pathname: %s\n", sample->pathname);
}
-
+
retval = gtk_dialog_run (GTK_DIALOG (dialog));
-
+
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
//printf("filename post: %s\n", filename);
sample = view->sample;
@@ -776,9 +771,9 @@ sample_save_as_cb(GtkWidget * widget, gpointer data)
sd->pathname = filename;
if (retval == GTK_RESPONSE_ACCEPT) {
-
+
if (!sweep_dir_exists (filename)) {
- g_free (sd);
+ g_free (sd);
g_free (filename);
return;
}
@@ -795,7 +790,7 @@ sample_save_as_cb(GtkWidget * widget, gpointer data)
}
} else {
/* file exists */
-
+
if (access(filename, W_OK) == -1) {
sweep_perror (errno, _("You are not allowed to write to\n%s"), filename);
} else {
@@ -809,20 +804,18 @@ sample_save_as_cb(GtkWidget * widget, gpointer data)
}
/* FIXME: wrapped this due to the above gtk_file_chooser_set_filename problem */
} else if (sd->pathname != NULL) {
- gchar * msg;
+ gchar msg [1024];
- msg = g_strdup_printf (_("Save as %s cancelled"), g_basename (sd->pathname));
+ snprintf (msg, sizeof (msg), _("Save as %s cancelled"), g_basename (sd->pathname));
sample_set_tmp_message (sd->sample, msg);
- g_free (msg);
-
} else {
-
+
g_free (sd);
g_free (filename);
}
gtk_widget_destroy (dialog);
-
-
+
+
}
static void
@@ -860,7 +853,7 @@ sample_save_cb (GtkWidget * widget, gpointer data)
sw_view * view = (sw_view *)data;
sw_sample * sample;
char buf[512];
-
+
sample = view->sample;
if (sample->last_mtime == 0 ||
@@ -871,7 +864,7 @@ sample_save_cb (GtkWidget * widget, gpointer data)
_("%s\n has changed on disk.\n\n"
"Are you sure you want to save?"),
sample->pathname);
-
+
question_dialog_new (sample, _("File modified"), buf,
_("Save"), _("Don't save"),
G_CALLBACK (sample_save_ok_cb), view, NULL, NULL,
View
24 src/file_sndfile1.c → src/file_sndfile.c
@@ -54,8 +54,6 @@
extern GtkStyle * style_wb;
-#if defined (SNDFILE_1)
-
#include "../pixmaps/libsndfile.xpm"
typedef struct {
@@ -67,7 +65,7 @@ typedef struct {
typedef struct {
gboolean saving; /* loading or saving ? */
sw_sample * sample;
- gchar * pathname;
+ gchar pathname [512];
SF_INFO * sfinfo;
GtkWidget * ok_button;
} sndfile_save_options;
@@ -379,6 +377,7 @@ create_sndfile_encoding_options_dialog (sndfile_save_options * so)
samplerate_chooser_set_rate (entry, sample->sounddata->format->rate);
} else {
+ char temp [32];
hbox = gtk_hbox_new (FALSE, 0);
gtk_table_attach (GTK_TABLE(table), hbox, 0, 1, 1, 2,
GTK_FILL|GTK_EXPAND, GTK_SHRINK, 0, 0);
@@ -393,8 +392,8 @@ create_sndfile_encoding_options_dialog (sndfile_save_options * so)
GTK_FILL|GTK_EXPAND, GTK_SHRINK, 0, 0);
gtk_widget_show (hbox);
- label = gtk_label_new (g_strdup_printf ("%d Hz",
- sample->sounddata->format->rate));
+ snprintf (temp, sizeof (temp), "%d Hz", sample->sounddata->format->rate);
+ label = gtk_label_new (temp);
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
}
@@ -483,7 +482,7 @@ sndfile_save_options_dialog (sw_sample * sample, gchar * pathname)
sfinfo->format = sample->file_format;
- so->pathname = g_strdup (pathname);
+ snprintf (so->pathname, sizeof (so->pathname), "%s", pathname);
so->sfinfo = sfinfo;
dialog = create_sndfile_encoding_options_dialog (so);
@@ -514,16 +513,14 @@ sndfile_load_options_dialog_ok_cb (GtkWidget * widget, gpointer data)
{
sndfile_save_options * so = (sndfile_save_options *)data;
sw_sample * sample = so->sample;
- gchar * pathname = so->pathname;
SF_INFO * sfinfo = so->sfinfo;
GtkWidget * dialog;
dialog = gtk_widget_get_toplevel (widget);
gtk_widget_destroy (dialog);
- _sndfile_sample_load (sample, pathname, sfinfo, TRUE);
+ _sndfile_sample_load (sample, so->pathname, sfinfo, TRUE);
- g_free (so->pathname);
g_free (so);
}
@@ -610,7 +607,7 @@ _sndfile_sample_load (sw_sample * sample, gchar * pathname, SF_INFO * sfinfo,
{
SNDFILE * sndfile;
char buf[128];
- gchar * message;
+ gchar message [256];
gboolean isnew = (sample == NULL);
@@ -644,7 +641,7 @@ _sndfile_sample_load (sw_sample * sample, gchar * pathname, SF_INFO * sfinfo,
so = g_malloc0 (sizeof(*so));
so->saving = FALSE;
so->sample = sample;
- so->pathname = g_strdup (pathname);
+ snprintf (so->pathname, sizeof (so->pathname), "%s", pathname);
so->sfinfo = sfinfo;
sfinfo->format = (SF_FORMAT_RAW | SF_FORMAT_PCM_S8);
@@ -664,9 +661,8 @@ _sndfile_sample_load (sw_sample * sample, gchar * pathname, SF_INFO * sfinfo,
} else {
if (errno == 0) {
- message = g_strdup_printf ("%s:\n%s", pathname, buf);
+ snprintf (message, sizeof (message), "%s:\n%s", pathname, buf);
info_dialog_new (buf, NULL, message);
- g_free (message);
} else {
/* We've already got the error string so no need to call
* sweep_sndfile_perror() here */
@@ -939,5 +935,3 @@ sndfile_sample_save (sw_sample * sample, gchar * pathname)
return 0;
}
-
-#endif
View
126 src/file_speex.c
@@ -302,7 +302,7 @@ process_header(ogg_packet *op, int enh_enabled, int * frame_size, int * rate,
if (*channels == -1)
*channels = header->nb_channels;
-#ifdef DEBUG
+#ifdef DEBUG
fprintf (stderr, "Decoding %d Hz audio using %s mode",
*rate, mode->modeName);
@@ -384,7 +384,7 @@ sample_load_speex_data (sw_op_instance * inst)
ogg_sync_init (&oy);
speex_bits_init (&bits);
-
+
while (active && remaining > 0) {
g_mutex_lock (sample->ops_mutex);
@@ -481,7 +481,7 @@ sample_load_speex_data (sw_op_instance * inst)
}
remaining -= n;
-
+
percent = (file_length - remaining) * 100 / file_length;
sample_set_progress_percent (sample, percent);
}
@@ -808,10 +808,10 @@ speex_sample_save_thread (sw_op_instance * inst)
while(!eos){
int result = ogg_stream_flush (&os, &og);
if (result == 0) break;
-
+
n = fwrite (og.header, 1, og.header_len, outfile);
n += fwrite (og.body, 1, og.body_len, outfile);
-
+
if (fflush (outfile) == 0) {
bytes_written += n;
} else {
@@ -858,7 +858,7 @@ speex_sample_save_thread (sw_op_instance * inst)
while (!eos) {
g_mutex_lock (sample->ops_mutex);
-
+
if (sample->edit_state == SWEEP_EDIT_STATE_CANCEL) {
active = FALSE;
}
@@ -875,12 +875,12 @@ speex_sample_save_thread (sw_op_instance * inst)
for (i = 0; i < so->framepack; i++) {
if (remaining > 0) {
len = MIN (remaining, frame_size);
-
+
d = &((sw_audio_t *)sample->sounddata->data)
[run_total * format->channels];
-
+
memcpy (input, d, sizeof (sw_audio_t) * len * format->channels);
-
+
/* rip channel 0 out, in required format */
for (j = 0; j < len * format->channels; j++) {
input[j] *= 32767.0;
@@ -889,9 +889,9 @@ speex_sample_save_thread (sw_op_instance * inst)
if (format->channels == 2)
speex_encode_stereo (input, len, &bits);
speex_encode (st, input, &bits);
-
+
remaining -= len;
-
+
run_total += len;
percent = run_total / cframes;
sample_set_progress_percent (sample, percent);
@@ -919,15 +919,15 @@ speex_sample_save_thread (sw_op_instance * inst)
/* weld the packet into the bitstream */
ogg_stream_packetin(&os,&op);
-
+
/* write out pages (if any) */
while(!eos){
int result=ogg_stream_pageout(&os,&og);
if(result==0)break;
-
+
n = fwrite (og.header, 1, og.header_len, outfile);
n += fwrite (og.body, 1, og.body_len, outfile);
-
+
if (fflush (outfile) == 0) {
bytes_written += n;
} else {
@@ -970,7 +970,7 @@ speex_sample_save_thread (sw_op_instance * inst)
average_bitrate =
8.0/1000.0*((double)bytes_written/((double)nr_frames/(double)format->rate));
-
+
info_dialog_new (_("Speex encoding results"), xifish_xpm,
"Encoding of %s succeeded.\n\n"
"%s written, %s audio\n"
@@ -1045,7 +1045,7 @@ speex_save_options_dialog_ok_cb (GtkWidget * widget, gpointer data)
const gchar * text;
gboolean use_br;
- GtkObject * adj;
+ GtkObject * adj;
int mode, features, quality, bitrate, complexity, framepack;
gboolean rem_encode;
long serialno;
@@ -1137,7 +1137,7 @@ speex_save_options_dialog_ok_cb (GtkWidget * widget, gpointer data)
so->serialno = serialno;
- sample->file_info = so;
+ sample->file_info = so;
speex_sample_save (sample, pathname);
}
@@ -1339,64 +1339,40 @@ speex_encode_options_reset_cb (GtkWidget * widget, gpointer data)
GtkWidget * dialog;
GtkObject * adj;
- int * i, features, quality, complexity, framepack;
+ int features, quality, complexity, framepack;
dialog = gtk_widget_get_toplevel (widget);
/* Mode menu */
speex_encode_options_mode_auto_cb (widget, data);
/* Features menu */
- i = prefs_get_int (FEATURES_KEY);
-
- if (i == NULL) {
- features = DEFAULT_FEATURES;
- } else {
- features = *i;
- }
+ features = prefs_get_int (FEATURES_KEY, DEFAULT_FEATURES);
speex_encode_options_set_features (dialog, features);
/* Quality */
adj = GTK_OBJECT(g_object_get_data (G_OBJECT(dialog), "quality_adj"));
-
- i = prefs_get_int (QUALITY_KEY);
-
- if (i == NULL) {
- quality = DEFAULT_QUALITY;
- } else {
- quality = *i;
- }
-
+
+ quality = prefs_get_int (QUALITY_KEY, DEFAULT_QUALITY);
+
gtk_adjustment_set_value (GTK_ADJUSTMENT(adj), (float)quality);
/* Complexity */
adj = GTK_OBJECT(g_object_get_data (G_OBJECT(dialog), "complexity_adj"));
-
- i = prefs_get_int (COMPLEXITY_KEY);
-
- if (i == NULL) {
- complexity = DEFAULT_COMPLEXITY;
- } else {
- complexity = *i;
- }
-
+
+ complexity = prefs_get_int (COMPLEXITY_KEY, DEFAULT_COMPLEXITY);
+
gtk_adjustment_set_value (GTK_ADJUSTMENT(adj), (float)complexity);
/* Framepack */
adj = GTK_OBJECT(g_object_get_data (G_OBJECT(dialog), "framepack_adj"));
-
- i = prefs_get_int (FRAMEPACK_KEY);
-
- if (i == NULL) {
- framepack = DEFAULT_FRAMEPACK;
- } else {
- framepack = *i;
- }
-
+
+ framepack = prefs_get_int (FRAMEPACK_KEY, DEFAULT_FRAMEPACK);
+
gtk_adjustment_set_value (GTK_ADJUSTMENT(adj), (float)framepack);
speex_encode_options_update_cb (widget, data);
@@ -1406,9 +1382,9 @@ static void
speex_encode_options_default_cb (GtkWidget * widget, gpointer data)
{
GtkWidget * dialog;
- GtkObject * quality_adj;
- GtkObject * complexity_adj;
- GtkObject * framepack_adj;
+ GtkObject * quality_adj;
+ GtkObject * complexity_adj;
+ GtkObject * framepack_adj;
dialog = gtk_widget_get_toplevel (widget);
@@ -1457,11 +1433,10 @@ static gboolean
randomise_serialno (gpointer data)
{
GtkWidget * entry = (GtkWidget *)data;
- gchar * new_text;
+ gchar new_text [256];
- new_text = g_strdup_printf ("%ld", random ());
+ snprintf (new_text, sizeof (new_text), "%ld", random ());
gtk_entry_set_text (GTK_ENTRY (entry), new_text);
- g_free (new_text);
return TRUE;
}
@@ -1512,7 +1487,7 @@ create_speex_encoding_options_dialog (sw_sample * sample, char * pathname)
GtkWidget * notebook;
- GtkWidget * checkbutton;
+ GtkWidget * checkbutton;
GtkObject * quality_adj;
GtkWidget * quality_hscale;
GtkObject * complexity_adj;
@@ -1529,7 +1504,7 @@ create_speex_encoding_options_dialog (sw_sample * sample, char * pathname)
/* GtkStyle * style; */
int i;
- long * l;
+ long l;
dialog = gtk_dialog_new ();
gtk_window_set_title (GTK_WINDOW(dialog),
@@ -1565,7 +1540,7 @@ create_speex_encoding_options_dialog (sw_sample * sample, char * pathname)
/* filename */
-
+
/* worth changing this over to pango?
style = gtk_style_new ();
@@ -1577,7 +1552,7 @@ create_speex_encoding_options_dialog (sw_sample * sample, char * pathname)
label = gtk_label_new (g_basename (pathname));
gtk_box_pack_start (GTK_BOX(vbox), label, TRUE, FALSE, 0);
gtk_widget_show (label);
-
+
/* gtk_widget_pop_style (); */
notebook = gtk_notebook_new ();
@@ -1611,7 +1586,7 @@ create_speex_encoding_options_dialog (sw_sample * sample, char * pathname)
menuitem =
gtk_menu_item_new_with_label (_(mode_choices[i].name));
gtk_menu_append (GTK_MENU(menu), menuitem);
- g_object_set_data (G_OBJECT(menuitem), "default",
+ g_object_set_data (G_OBJECT(menuitem), "default",
GINT_TO_POINTER(mode_choices[i].number));
gtk_widget_show (menuitem);
@@ -1620,7 +1595,7 @@ create_speex_encoding_options_dialog (sw_sample * sample, char * pathname)
dialog);
}
gtk_option_menu_set_menu (GTK_OPTION_MENU(option_menu), menu);
-
+
g_object_set_data (G_OBJECT(dialog), "mode_menu", option_menu);
button = gtk_button_new_with_label (_("Auto"));
@@ -1629,13 +1604,13 @@ create_speex_encoding_options_dialog (sw_sample * sample, char * pathname)
G_CALLBACK(speex_encode_options_mode_auto_cb),
sample);
gtk_widget_show (button);
-
+
tooltips = gtk_tooltips_new ();
gtk_tooltips_set_tip (tooltips, button,
_("Automatically select the encoding mode based on "
"the sampling rate of the file."),
NULL);
-
+
separator = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX(vbox), separator, FALSE, TRUE, 4);
gtk_widget_show (separator);
@@ -1652,7 +1627,7 @@ create_speex_encoding_options_dialog (sw_sample * sample, char * pathname)
menuitem =
gtk_menu_item_new_with_label (_(feature_choices[i].name));
gtk_menu_append (GTK_MENU(menu), menuitem);
- g_object_set_data (G_OBJECT(menuitem), "default",
+ g_object_set_data (G_OBJECT(menuitem), "default",
GINT_TO_POINTER(feature_choices[i].number));
gtk_widget_show (menuitem);
@@ -1667,7 +1642,7 @@ create_speex_encoding_options_dialog (sw_sample * sample, char * pathname)
}
}
gtk_option_menu_set_menu (GTK_OPTION_MENU(option_menu), menu);
-
+
g_object_set_data (G_OBJECT(dialog), "features_menu", option_menu);
@@ -1701,7 +1676,7 @@ create_speex_encoding_options_dialog (sw_sample * sample, char * pathname)
{
/* How sucky ... we create a vbox in order to center the hscale within
- * its allocation, thus actually lining it up with its label ...
+ * its allocation, thus actually lining it up with its label ...
*/
GtkWidget * vbox_pants;
@@ -1816,7 +1791,7 @@ create_speex_encoding_options_dialog (sw_sample * sample, char * pathname)
{
/* How sucky ... we create a vbox in order to center the hscale within
- * its allocation, thus actually lining it up with its label ...
+ * its allocation, thus actually lining it up with its label ...
*/
GtkWidget * vbox_pants;
@@ -1997,13 +1972,16 @@ create_speex_encoding_options_dialog (sw_sample * sample, char * pathname)
g_object_set_data (G_OBJECT (dialog), "rem_serialno_chb", checkbutton);
- l = prefs_get_long (SERIALNO_KEY);
+ l = prefs_get_long (SERIALNO_KEY, 0);
- if (l == NULL) {
+ if (l == 0) {
randomise_serialno (entry);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton), FALSE);
} else {
- gtk_entry_set_text (GTK_ENTRY(entry), g_strdup_printf ("%ld", *l));
+ char temp [128];
+
+ snprintf (temp, sizeof (temp), "%ld", l);
+ gtk_entry_set_text (GTK_ENTRY(entry), temp);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton), TRUE);
}
@@ -2045,7 +2023,7 @@ create_speex_encoding_options_dialog (sw_sample * sample, char * pathname)
gtk_container_add (GTK_CONTAINER(ebox), vbox);
gtk_container_set_border_width (GTK_CONTAINER(vbox), 8);
gtk_widget_show (vbox);
-
+
label =
gtk_label_new (_("Speex is a high quality speech codec designed for\n"
"voice over IP (VoIP) and file-based compression.\n"
View
127 src/file_vorbis.c
@@ -32,7 +32,7 @@
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
@@ -43,7 +43,7 @@
* - Neither the name of the Xiph.org Foundation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -119,8 +119,8 @@ extern GtkStyle * style_bw;
typedef struct _sw_metadata sw_metadata;
struct _sw_metadata {
- char * name;
- char * content;
+ char name [128];
+ char content [512];
};
static sw_metadata *
@@ -139,8 +139,8 @@ vorbis_metadata_from_str (char * str)
if (str[i] == '=') {
str[i] = '\0';
meta = g_malloc (sizeof (sw_metadata));
- meta->name = g_strdup (str);
- meta->content = g_strdup (&str[i+1]);
+ snprintf (meta->name, sizeof (meta->name), "%s", str);
+ snprintf (meta->content, sizeof (meta->content), "%s", str + i +1);
break;
}
}
@@ -204,11 +204,11 @@ sample_load_vorbis_data (sw_op_instance * inst)
d[j*channels + i] = pcm[i][j];
}
}
-
+
d += (n * channels);
remaining -= n;
-
+
run_total += n;
percent = run_total / cframes;
sample_set_progress_percent (sample, percent);
@@ -519,13 +519,13 @@ vorbis_sample_save_thread (sw_op_instance * inst)
while (!eos) {
g_mutex_lock (sample->ops_mutex);
-
+
if (sample->edit_state == SWEEP_EDIT_STATE_CANCEL) {
active = FALSE;
}
if (active == FALSE || remaining <= 0) {
- /* Tell the library we're at end of stream so that it can handle
+ /* Tell the library we're at end of stream so that it can handle
* the last frame and mark end of stream in the output properly
*/
vorbis_analysis_wrote (&vd, 0);
@@ -596,7 +596,7 @@ vorbis_sample_save_thread (sw_op_instance * inst)
}
/* clean up and exit. vorbis_info_clear() must be called last */
-
+
ogg_stream_clear(&os);
vorbis_block_clear(&vb);
vorbis_dsp_clear(&vd);
@@ -626,7 +626,7 @@ vorbis_sample_save_thread (sw_op_instance * inst)
average_bitrate =
8.0/1000.0*((double)bytes_written/((double)nr_frames/(double)format->rate));
-
+
info_dialog_new (_("Ogg Vorbis encoding results"), xifish_xpm,
"Encoding of %s succeeded.\n\n"
"%s written, %s audio\n"
@@ -702,7 +702,7 @@ vorbis_save_options_dialog_ok_cb (GtkWidget * widget, gpointer data)
const gchar * text;
gboolean use_abr;
- GtkObject * quality_adj;
+ GtkObject * quality_adj;
gfloat quality = -1.0;
long max_bitrate = -1, nominal_bitrate = -1, min_bitrate = -1;
gboolean rem_encode;
@@ -718,7 +718,7 @@ vorbis_save_options_dialog_ok_cb (GtkWidget * widget, gpointer data)
checkbutton =
GTK_WIDGET(g_object_get_data (G_OBJECT(dialog), "abr_chb"));
use_abr =
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(checkbutton));
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(checkbutton));
if (use_abr) {
entry = GTK_WIDGET(g_object_get_data (G_OBJECT(dialog),
@@ -809,7 +809,7 @@ vorbis_save_options_dialog_ok_cb (GtkWidget * widget, gpointer data)
so->serialno = serialno;
- sample->file_info = so;
+ sample->file_info = so;
vorbis_sample_save (sample, pathname);
}
@@ -848,67 +848,56 @@ vorbis_encode_options_reset_cb (GtkWidget * widget, gpointer data)
GtkWidget * checkbutton;
GtkWidget * entry;
- int * i;
gboolean use_abr;
- GtkObject * quality_adj;
- float * q, quality;
- long * l, bitrate;
+ GtkObject * quality_adj;
+ float quality;
+ long l, bitrate;
+ char temp [64];
dialog = gtk_widget_get_toplevel (widget);
/* Quality */
quality_adj =
GTK_OBJECT(g_object_get_data (G_OBJECT(dialog), "quality_adj"));
-
- q = prefs_get_float (QUALITY_KEY);
-
- if (q == NULL) {
- quality = DEFAULT_QUALITY;
- } else {
- quality = *q;
- }
-
+
+ quality = prefs_get_float (QUALITY_KEY, DEFAULT_QUALITY);
+
gtk_adjustment_set_value (GTK_ADJUSTMENT(quality_adj), quality);
/* Nominal bitrate */
entry = GTK_WIDGET(g_object_get_data (G_OBJECT(dialog),
"nominal_bitrate_entry"));
- l = prefs_get_long (NOMINAL_KEY);
- if (l == NULL) {
- bitrate = DEFAULT_NOMINAL;
- } else {
- bitrate = *l;
- }
- gtk_entry_set_text (GTK_ENTRY (entry), g_strdup_printf ("%ld", bitrate));
+ bitrate = prefs_get_long (NOMINAL_KEY, DEFAULT_NOMINAL);
+ snprintf (temp, sizeof (temp), "%ld", bitrate);
+ gtk_entry_set_text (GTK_ENTRY (entry), temp);
/* Max bitrate */
entry = GTK_WIDGET(g_object_get_data (G_OBJECT(dialog),
"max_bitrate_entry"));
- l = prefs_get_long (MAXIMUM_KEY);
- if (l != NULL && (*l != -1)) {
- gtk_entry_set_text (GTK_ENTRY (entry), g_strdup_printf ("%ld", *l));
+ l = prefs_get_long (MAXIMUM_KEY, 0);
+ if (l) {
+ char temp [64];
+ snprintf (temp, sizeof (temp), "%ld", l);
+ gtk_entry_set_text (GTK_ENTRY (entry), temp);
}
/* Min bitrate */
-
+
entry = GTK_WIDGET(g_object_get_data (G_OBJECT(dialog),
"min_bitrate_entry"));
- l = prefs_get_long (MINIMUM_KEY);
- if (l != NULL && (*l != -1)) {
- gtk_entry_set_text (GTK_ENTRY (entry), g_strdup_printf ("%ld", *l));
+ l = prefs_get_long (MINIMUM_KEY, 0);
+ if (l) {
+ char temp [128];
+ snprintf (temp, sizeof (temp), "%ld", l);
+ gtk_entry_set_text (GTK_ENTRY (entry), temp);
}
/* Use ABR */
- i = prefs_get_int (ABR_KEY);
- if (i == NULL) {
- use_abr = FALSE;
- } else {
- use_abr = (gboolean) *i;
- }
+ use_abr = prefs_get_int (ABR_KEY, FALSE);
checkbutton =
GTK_WIDGET(g_object_get_data (G_OBJECT(dialog), "abr_chb"));
@@ -918,11 +907,12 @@ vorbis_encode_options_reset_cb (GtkWidget * widget, gpointer data)
static void
vorbis_encode_options_default_cb (GtkWidget * widget, gpointer data)
{
+ char temp [128];
GtkWidget * dialog;
GtkWidget * checkbutton;
GtkWidget * entry;
- GtkObject * quality_adj;
+ GtkObject * quality_adj;
dialog = gtk_widget_get_toplevel (widget);
@@ -936,8 +926,8 @@ vorbis_encode_options_default_cb (GtkWidget * widget, gpointer data)
entry = GTK_WIDGET(g_object_get_data (G_OBJECT(dialog),
"nominal_bitrate_entry"));
- gtk_entry_set_text (GTK_ENTRY (entry),
- g_strdup_printf ("%ld", DEFAULT_NOMINAL));
+ snprintf (temp, sizeof (temp), "%ld", DEFAULT_NOMINAL);
+ gtk_entry_set_text (GTK_ENTRY (entry), temp);
/* Max bitrate */
@@ -946,7 +936,7 @@ vorbis_encode_options_default_cb (GtkWidget * widget, gpointer data)
gtk_entry_set_text (GTK_ENTRY (entry), "");
/* Min bitrate */
-
+
entry = GTK_WIDGET(g_object_get_data (G_OBJECT(dialog),
"min_bitrate_entry"));
gtk_entry_set_text (GTK_ENTRY (entry), "");
@@ -971,7 +961,7 @@ metadata_table_add_row (GtkWidget * table, int row, char * title, char * tip)
gtk_table_attach (GTK_TABLE(table), hbox, 0, 1, row, row+1,
GTK_FILL, GTK_SHRINK, 0, 0);
gtk_widget_show (hbox);
-
+
label = gtk_label_new (title);
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
@@ -1005,11 +995,10 @@ static gboolean
randomise_serialno (gpointer data)
{
GtkWidget * entry = (GtkWidget *)data;
- gchar * new_text;
+ gchar new_text [128];
- new_text = g_strdup_printf ("%ld", random ());
+ snprintf (new_text, sizeof (new_text), "%ld", random ());
gtk_entry_set_text (GTK_ENTRY (entry), new_text);
- g_free (new_text);
return TRUE;
}
@@ -1054,15 +1043,15 @@ create_vorbis_encoding_options_dialog (sw_sample * sample, char * pathname)
GtkWidget * notebook;
- GtkWidget * checkbutton;
+ GtkWidget * checkbutton;
GtkWidget * frame;
GtkObject * quality_adj;
GtkWidget * quality_hscale;
GtkWidget * table;
GtkWidget * entry;
GtkTooltips * tooltips;
- long * l;
+ long l;
#ifdef DEVEL_CODE /* metadata */
int t; /* table row */
@@ -1121,7 +1110,7 @@ create_vorbis_encoding_options_dialog (sw_sample * sample, char * pathname)
label = gtk_label_new (g_basename (pathname));
gtk_box_pack_start (GTK_BOX(hbox), label, TRUE, FALSE, 0);
gtk_widget_show (label);
-
+
/* gtk_widget_pop_style ();*/
notebook = gtk_notebook_new ();
@@ -1156,7 +1145,7 @@ create_vorbis_encoding_options_dialog (sw_sample * sample, char * pathname)
{
/* How sucky ... we create a vbox in order to center the hscale within
- * its allocation, thus actually lining it up with its label ...
+ * its allocation, thus actually lining it up with its label ...
*/
GtkWidget * vbox_pants;
@@ -1202,7 +1191,7 @@ create_vorbis_encoding_options_dialog (sw_sample * sample, char * pathname)
NULL);
g_object_set_data (G_OBJECT(checkbutton), "quality_widget", hbox);
-
+
frame = gtk_frame_new (_("Bitrate management engine"));
gtk_box_pack_start (GTK_BOX(vbox), frame, TRUE, TRUE, 4);
gtk_container_set_border_width (GTK_CONTAINER(frame), 12);
@@ -1228,7 +1217,7 @@ create_vorbis_encoding_options_dialog (sw_sample * sample, char * pathname)
gtk_table_attach (GTK_TABLE(table), hbox, 0, 1, 0, 1,
GTK_FILL|GTK_EXPAND, GTK_SHRINK, 0, 0);
gtk_widget_show (hbox);
-
+
label = gtk_label_new (_("Nominal bitrate (ABR):"));
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
@@ -1257,7 +1246,7 @@ create_vorbis_encoding_options_dialog (sw_sample * sample, char * pathname)
gtk_table_attach (GTK_TABLE(table), hbox, 0, 1, 1, 2,
GTK_FILL|GTK_EXPAND, GTK_SHRINK, 0, 0);
gtk_widget_show (hbox);
-
+
label = gtk_label_new (_("Minimum bitrate:"));
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
@@ -1287,7 +1276,7 @@ create_vorbis_encoding_options_dialog (sw_sample * sample, char * pathname)
gtk_table_attach (GTK_TABLE(table), hbox, 0, 1, 2, 3,
GTK_FILL|GTK_EXPAND, GTK_SHRINK, 0, 0);
gtk_widget_show (hbox);
-
+
label = gtk_label_new (_("Maximum bitrate:"));
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
@@ -1510,13 +1499,15 @@ create_vorbis_encoding_options_dialog (sw_sample * sample, char * pathname)
g_object_set_data (G_OBJECT (dialog), "rem_serialno_chb", checkbutton);
- l = prefs_get_long (SERIALNO_KEY);
+ l = prefs_get_long (SERIALNO_KEY, 0);
- if (l == NULL) {
+ if (l == 0) {
randomise_serialno (entry);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton), FALSE);
} else {
- gtk_entry_set_text (GTK_ENTRY(entry), g_strdup_printf ("%ld", *l));
+ char temp [128];
+ snprintf (temp, sizeof (temp), "%ld", l);
+ gtk_entry_set_text (GTK_ENTRY(entry), temp);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton), TRUE);
}
@@ -1558,7 +1549,7 @@ create_vorbis_encoding_options_dialog (sw_sample * sample, char * pathname)
gtk_container_add (GTK_CONTAINER(ebox), vbox);
gtk_container_set_border_width (GTK_CONTAINER(vbox), 8);
gtk_widget_show (vbox);
-
+
label =
gtk_label_new (_("Ogg Vorbis is a high quality general purpose\n"
"perceptual audio codec. It is free, open and\n"
View
22 src/main.c
@@ -62,14 +62,14 @@ static gint
initial_sample_load (gpointer data)
{
char * arg = (char *)data;
- gchar * pathname;
+ gchar pathname [512];
if (!strncmp (g_dirname (arg), ".", 1)) {
- pathname = g_strdup_printf ("%s/%s", g_get_current_dir(), arg);
+ snprintf (pathname, sizeof (pathname), "%s/%s", g_get_current_dir(), arg);
} else {
- pathname = arg;
+ snprintf (pathname, sizeof (pathname), "%s", arg);
}
-
+
sample_load (pathname);
return FALSE;
@@ -129,7 +129,7 @@ main (int argc, char *argv[])
g_thread_init (NULL);
-
+
/* must be done before g_idle_add / g_timeout_add */
sweep_timeouts_init ();
@@ -145,7 +145,7 @@ main (int argc, char *argv[])
argv[i] = NULL;
} else if ((strcmp (argv[i], "--ignore-failed-lock") == 0)) {
ignore_failed_tdb_lock = TRUE;
- argv[i] = NULL;
+ argv[i] = NULL;
#ifdef DEVEL_CODE
} else if (argv[i][0] == '-' && argv[i][1] != '\0') {
@@ -170,7 +170,7 @@ main (int argc, char *argv[])
if (show_help) {
g_print (_("Usage: %s [option ...] [files ...]\n"), argv[0]);
- g_print (_("Valid options are:\n"));
+ g_print (_("Valid options are:\n"));
g_print (_(" -h --help Output this help.\n"));
g_print (_(" -v --version Output version info.\n"));
g_print (_(" --display <display> Use the designated X display.\n"));
@@ -186,12 +186,12 @@ main (int argc, char *argv[])
}
srandom ((unsigned int)time(NULL));
-
+
if (no_files) {
g_idle_add ((GSourceFunc)initial_sample_ask, NULL);
}
-
+
/* initialise preferences */
prefs_init ();
@@ -210,13 +210,13 @@ main (int argc, char *argv[])
/* init playback subsystem */
init_playback ();
-
+
gtk_main ();
/* close preferences database */
prefs_close ();
-
+
/* save key bindings */
save_accels ();
View
10 src/notes.c
@@ -99,21 +99,21 @@ noteplay_setup (GtkWidget *subsubmenu, sw_view * view,
{
GtkWidget *menuitem;
int k;
- gchar * tmpchar;
+ gchar tmpchar [256];
for (k = 0 ; k < sizeof (notes) / sizeof (notes [0]) ; k++) {
menuitem = gtk_menu_item_new_with_label (_(notes [k].name));
gtk_menu_append (GTK_MENU(subsubmenu), menuitem);
gtk_menu_set_accel_group(GTK_MENU(subsubmenu), accel_group);
g_signal_connect (G_OBJECT(menuitem), "activate",
G_CALLBACK(play_view_note_cb), view);
- tmpchar = g_strdup_printf("<Sweep-View>/Playback/Play Note/%s",
+ snprintf (tmpchar, sizeof (tmpchar), "<Sweep-View>/Playback/Play Note/%s",
notes[k].accel_basename);
-
+
gtk_menu_item_set_accel_path (GTK_MENU_ITEM(menuitem), tmpchar);
gtk_accel_map_add_entry ( tmpchar, notes[k].accel_key, 0);
- g_object_set_data (G_OBJECT(menuitem), "default",
+ g_object_set_data (G_OBJECT(menuitem), "default",
GINT_TO_POINTER(k));
gtk_widget_show (menuitem);
}
@@ -129,7 +129,7 @@ play_view_note_cb (GtkWidget * widget, gpointer data)
sw_framecount_t mouse_offset;
int k;
float pitch;
-
+
/* Retrieve the pitch. */
k = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(widget), "default"));
pitch = notes[k].pitch;
View
12 src/paste_dialogs.c
@@ -164,7 +164,7 @@ create_paste_dialog (sw_sample * sample, gboolean xfade)
GtkTooltips * tooltips;
- gchar * title, * common_slider_title;
+ gchar title [600], * common_slider_title;
sw_time_t duration;
char buf[16];
@@ -201,12 +201,11 @@ create_paste_dialog (sw_sample * sample, gboolean xfade)
/* Source */
- title = g_strdup_printf ("%s: %s", _("Source"), _("Clipboard"));
+ snprintf (title, sizeof (title), "%s: %s", _("Source"), _("Clipboard"));
frame = gtk_frame_new (title);
gtk_container_set_border_width (GTK_CONTAINER(frame), 8);
gtk_box_pack_start (GTK_BOX(hbox), frame, TRUE, TRUE, 0);
gtk_widget_show (frame);
- g_free (title);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER(frame), vbox);
@@ -226,7 +225,7 @@ create_paste_dialog (sw_sample * sample, gboolean xfade)
slider = db_slider_new (_("End gain"), 1.0, 0.0, 2.0);
gtk_box_pack_start (GTK_BOX(hbox2), slider, TRUE, TRUE, 2);
gtk_widget_show (slider);
-
+
g_object_set_data (G_OBJECT(dialog), "src_slider2", slider);
}
@@ -239,13 +238,12 @@ create_paste_dialog (sw_sample * sample, gboolean xfade)
/* Destination */
- title = g_strdup_printf ("%s: %s", _("Destination"),
+ snprintf (title, sizeof (title), "%s: %s", _("Destination"),
g_basename (sample->pathname));
frame = gtk_frame_new (title);
gtk_container_set_border_width (GTK_CONTAINER(frame), 8);
gtk_box_pack_start (GTK_BOX(hbox), frame, TRUE, TRUE, 0);
gtk_widget_show (frame);
- g_free (title);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER(frame), vbox);
@@ -352,7 +350,7 @@ create_paste_dialog (sw_sample * sample, gboolean xfade)
sample_set_edit_state (sample, SWEEP_EDIT_STATE_BUSY);
sample_set_edit_mode (sample, SWEEP_EDIT_MODE_FILTER);
sample_set_progress_percent (sample, 0);
-
+
if (!GTK_WIDGET_VISIBLE(dialog)) {
gtk_widget_show (dialog);
} else {
View
4 src/pcmio.h
@@ -33,10 +33,10 @@
#define LOGFRAGS_TO_FRAGS(l) (1 << ((int)(floor((l)) - 1)))
-char *
+const char *
pcmio_get_main_dev (void);
-char *
+const char *
pcmio_get_monitor_dev (void);
gboolean
View
9 src/play.c
@@ -646,7 +646,7 @@ play_head_update_device (sw_head * head)
static gchar *
generate_demo_filename (void)
{
- return g_strdup_printf ("/tmp/sweep-demo-%d.au", getpid ());
+ return erikd ("/tmp/sweep-demo-%d.au", getpid ());
}
#endif
@@ -750,12 +750,9 @@ play_heads (GList ** heads, sw_handle * handle)
static gboolean
monitor_active (void)
{
- int * use_monitor;
+ int use_monitor = prefs_get_int (USE_MONITOR_KEY, 0);
- use_monitor = prefs_get_int (USE_MONITOR_KEY);
-
- if (use_monitor == NULL) return 0;
- else return (*use_monitor != 0);
+ return (use_monitor != 0);
}
static void
View
112 src/preferences.c
@@ -18,6 +18,18 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+/*
+ * Currently use Samba's TDB (Tiny DataBase) for preferences storage. This
+ * should probably be replaced at some time.
+ *
+ * The two problem with is are:
+ * - Its API TDB not const correct ie it requires that the const correct API
+ * for preferences needs to cast away const internally.
+ * - Samba uses Talloc for memory management and the TDB API is therefore a
+ * little alloction happy. For instance, *every* tdb_fetch() call returns
+ * a pointer than the *caller* needs to free.
+ */
+
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
@@ -48,9 +60,9 @@ gboolean ignore_failed_tdb_lock = FALSE;
void
prefs_init ()
{
- G_CONST_RETURN char * prefs_path;
+ G_CONST_RETURN const char * prefs_path;
struct stat sbuf;
-
+
prefs_path = g_get_home_dir ();
prefs_path = g_strconcat (prefs_path, "/.sweep", NULL);
@@ -111,15 +123,15 @@ prefs_init ()
prefs_tdb = tdb_open (prefs_path, 0, 0, O_RDWR | O_CREAT, FILE_MODE);
if (prefs_tdb == NULL) {
-
+
if (ignore_failed_tdb_lock == TRUE)
{
prefs_tdb = tdb_open (prefs_path, 0, TDB_NOLOCK, O_RDWR | O_CREAT, FILE_MODE);
if (prefs_tdb != NULL) {
fprintf(stderr, "Warning: couldn't get lock to ~/.sweep/preferences.tdb.\n"
" opened without locking\n");
return;
- }
+ }
}
perror (_("Error opening ~/.sweep/preferences.tdb"));
exit (1);
@@ -135,123 +147,117 @@ prefs_close (void)
}
int
-prefs_delete (char * key)
+prefs_delete (const char * key)
{
TDB_DATA key_data;
if (prefs_tdb == NULL)