marlin r1336 - trunk/marlin



Author: iain
Date: Tue Nov  4 12:32:45 2008
New Revision: 1336
URL: http://svn.gnome.org/viewvc/marlin?rev=1336&view=rev

Log:
Conflicts:

	marlin/marlin-jack-play.c


Modified:
   trunk/marlin/marlin-jack-play.c
   trunk/marlin/marlin-jack-record.c

Modified: trunk/marlin/marlin-jack-play.c
==============================================================================
--- trunk/marlin/marlin-jack-play.c	(original)
+++ trunk/marlin/marlin-jack-play.c	Tue Nov  4 12:32:45 2008
@@ -538,12 +538,25 @@
 	priv = GET_PRIVATE (jack);
 
 	if (priv->sample == NULL) {
-		
-		g_warning ("No sample to play");
+		if (error && *error != NULL) {
+			*error = g_error_new (MARLIN_JACK_ERROR,
+					      MARLIN_JACK_ERROR_NO_SAMPLE,
+					      "No sample to play");
+		} else {
+			g_warning ("No sample to play");
+		}
+
 		return FALSE;
 	}
 
 	if (jack_activate (priv->client)) {
+		if (error && *error != NULL) {
+			*error = g_error_new (MARLIN_JACK_ERROR,
+					      MARLIN_JACK_ERROR_NO_SERVER,
+					      "Jack activate returned an error");
+		} else {
+			g_warning ("Jack activate returned an error");
+		}
 		return FALSE;
 	}
 
@@ -565,6 +578,14 @@
 				  jack_port_name (pd->playback),
 				  ports[i])) {
 			marlin_sample_read_unlock (priv->sample);
+			if (error && *error != NULL) {
+				*error = g_error_new (MARLIN_JACK_ERROR,
+						      MARLIN_JACK_ERROR_NO_SERVER,
+						      "Jack connect returned an error");
+			} else {
+				g_warning ("Jack connect returned an error");
+			}
+
 			return FALSE;
 		}
 
@@ -596,6 +617,7 @@
 	priv->position = priv->start;
 	priv->mode = MARLIN_JACK_PLAY_MODE_PREROLLING;
 
+	/* Start the idle process to fill the ring buffer with data */
 	priv->writer_id = g_idle_add (process_writer, jack);
 
 	return TRUE;

Modified: trunk/marlin/marlin-jack-record.c
==============================================================================
--- trunk/marlin/marlin-jack-record.c	(original)
+++ trunk/marlin/marlin-jack-record.c	Tue Nov  4 12:32:45 2008
@@ -2,7 +2,7 @@
 /*
  *  Authors: Iain Holmes <iain gnome org>
  *
- *  Copyright 2002 - 2007 Iain Holmes
+ *  Copyright 2002 - 2008 Iain Holmes
  *
  *  This file is free software; you can redistribute it and/or
  *  modify it under the terms of version 2 of the GNU General Public
@@ -84,7 +84,7 @@
 
 	MarlinJackRecordMode mode;
 
-	guint channels; 
+	guint channels;
 
 	guint rate, jrate;
 
@@ -116,7 +116,7 @@
 
 	g_free (priv->port_data);
 }
-		
+
 static void
 setup_ports (MarlinJackRecord *jack)
 {
@@ -185,7 +185,6 @@
 		GParamSpec       *pspec,
 		MarlinJackRecord *jack)
 {
-#if 0
 	MarlinJackRecordPrivate *priv = jack->priv;
 
 	if (strcmp (pspec->name, "sample_rate") == 0) {
@@ -205,7 +204,6 @@
 		setup_ports (jack);
 		return;
 	}
-#endif
 }
 
 static void
@@ -215,8 +213,9 @@
 	MarlinJackRecordPrivate *priv;
 
 	priv = GET_PRIVATE (jack);
-	
+
 	if (priv->sample) {
+		free_ports ((MarlinJackRecord *) jack);
 		g_signal_handler_disconnect (priv->sample,
 					     priv->sample_notify_id);
 		g_object_unref (priv->sample);
@@ -232,6 +231,7 @@
 	setup_ports ((MarlinJackRecord *) jack);
 }
 
+/* recording process simply copies the data from jack into the ring buffer. */
 static void
 process_recording (MarlinJackRecord *jack,
 		   jack_nframes_t   nframes)
@@ -250,6 +250,7 @@
 		i_buf = jack_port_get_buffer (pd->record, nframes);
 		bytes_avail = nframes * frame_size;
 
+		/* Write the data into the ringbuffer */
 		if (jack_ringbuffer_write (pd->rb, (void *) i_buf,
 					   bytes_avail) < bytes_avail) {
 			/* Not sure what to do with this... signal? */
@@ -269,7 +270,7 @@
 	case MARLIN_JACK_RECORD_MODE_RECORDING:
 		process_recording (jack, nframes);
 		break;
-		
+
 	default:
 		break;
 	}
@@ -290,6 +291,7 @@
 
 	priv = jack->priv;
 
+	/* Write the data into a block */
 	block = marlin_channel_create_block (pd->channel);
 	ret = marlin_block_set_data (block, data, number_of_frames, &error);
 	if (ret == FALSE) {
@@ -297,6 +299,7 @@
 		return;
 	}
 
+	/* Add it to the block_list */
 	if (pd->block_list == NULL) {
 		pd->block_list = block;
 		pd->bl_end = block;
@@ -306,6 +309,7 @@
 	}
 }
 
+/* Reader function: Reads data from the ringbuffer and puts it in the sample */
 static gboolean
 process_reader (gpointer data)
 {
@@ -330,6 +334,7 @@
 			continue;
 		}
 
+		/* The amount of frames available will be fill a block */
 		if (pd->frames_in_data + frames > MARLIN_BLOCK_SIZE) {
 			guint32 needed, remain;
 			float *fd;
@@ -337,13 +342,16 @@
 			needed = MARLIN_BLOCK_SIZE - pd->frames_in_data;
 			remain = frames - needed;
 
+			/* Read from the ringbuffer into the next free space
+			   in the frame buffer */
 			fd = pd->data + pd->frames_in_data;
-			jack_ringbuffer_read (pd->rb, 
-					      (char *) fd,
+			jack_ringbuffer_read (pd->rb, (char *) fd,
 					      needed * sizeof (float));
+
+			/* Now we have a whole block, we can store it */
 			store_block (jack, pd, pd->data, MARLIN_BLOCK_SIZE);
 
-			memset (pd->data, 0, 
+			memset (pd->data, 0,
 				MARLIN_BLOCK_SIZE * sizeof (float));
 
 			if (remain > 0) {
@@ -399,10 +407,25 @@
 	priv = GET_PRIVATE (jack);
 
 	if (priv->sample == NULL) {
+		if (error && *error != NULL) {
+			*error = g_error_new (MARLIN_JACK_ERROR,
+					      MARLIN_JACK_ERROR_NO_SAMPLE,
+					      "No sample to record");
+		} else {
+			g_warning ("No sample to record");
+		}
+
 		return FALSE;
 	}
 
 	if (jack_activate (priv->client)) {
+		if (error && *error != NULL) {
+			*error = g_error_new (MARLIN_JACK_ERROR,
+					      MARLIN_JACK_ERROR_NO_SERVER,
+					      "Jack activate returned an error");
+		} else {
+			g_warning ("Jack activate returned an error");
+		}
 		return FALSE;
 	}
 
@@ -421,17 +444,26 @@
 
 		if (jack_connect (priv->client, ports[i],
 				  jack_port_name (pd->record))) {
+			if (error && *error != NULL) {
+				*error = g_error_new (MARLIN_JACK_ERROR,
+						      MARLIN_JACK_ERROR_NO_SERVER,
+						      "Jack connect returned an error");
+			} else {
+				g_warning ("Jack connect returned an error");
+			}
 			return FALSE;
 		}
-		
+
 		pd->rb = jack_ringbuffer_create (frame_size * DEFAULT_RB_SIZE);
-		
 		pd->channel = marlin_sample_get_channel (priv->sample, i);
 	}
 
 	free (ports);
 
 	priv->mode = MARLIN_JACK_RECORD_MODE_RECORDING;
+
+	/* Start an idle function to read from the ringbuffer and write data
+	   to a sample */
 	priv->reader_id = g_idle_add (process_reader, jack);
 
 	return TRUE;
@@ -457,7 +489,7 @@
 	priv = GET_PRIVATE (jack);
 
 	priv->mode = MARLIN_JACK_RECORD_MODE_STOPPED;
-	
+
 	jack_deactivate (priv->client);
 
 	g_source_remove (priv->reader_id);
@@ -470,7 +502,8 @@
 		jack_disconnect (priv->client,
 				 jack_port_name (pd->record), ports[i]);
 
-		store_block (MARLIN_JACK_RECORD (jack), pd, 
+		/* Store any extra data that might be there */
+		store_block (MARLIN_JACK_RECORD (jack), pd,
 			     pd->data, pd->frames_in_data);
 
 		/* Move the recorded data into the sample */
@@ -524,7 +557,7 @@
  *
  * Creates a new #MarlinJackRecord object.
  *
- * Return value: A #MarlinJackRecord object 
+ * Return value: A #MarlinJackRecord object
  */
 MarlinJackRecord *
 marlin_jack_record_new (const char *client_name,
@@ -546,8 +579,15 @@
 	priv->client = jack_client_open (client_name, options,
 					 &status, server_name);
 	if (priv->client == NULL) {
-		/* FIXME: Make error */
-		g_warning ("No jack record client");
+		/* Make error */
+		if (error && *error != NULL) {
+			*error = g_error_new (MARLIN_JACK_ERROR,
+					      MARLIN_JACK_ERROR_NO_SERVER,
+					      "Unable to run JACK server - JACK status was %d", status);
+		} else {
+			g_warning ("Unable to run JACK server - JACK status was %d");
+		}
+
 		g_object_unref (jack);
 		return NULL;
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]