[med-svn] [SCM] aghermann branch, master, updated. 06bda7dfaa687aaf0708a024d192024e2cd58421

Andrei Zavada johnhommer at gmail.com
Thu Jan 24 00:43:45 UTC 2013


The following commit has been merged in the master branch:
commit 6bc36a05c679303088e714c55365314fae72904d
Author: Andrei Zavada <johnhommer at gmail.com>
Date:   Tue Jan 15 00:16:00 2013 +0200

    patterns WIP

diff --git a/src/ui/sf/sf-construct.cc b/src/ui/sf/sf-construct.cc
index d7c1e53..f03c414 100644
--- a/src/ui/sf/sf-construct.cc
+++ b/src/ui/sf/sf-construct.cc
@@ -419,7 +419,9 @@ SScoringFacilityWidgets (SExpDesignUI& _p)
 		G_CONNECT_1 (ePatternChannel, changed);
 
 	G_CONNECT_1 (daPatternSelection, draw);
-	G_CONNECT_2( daPatternSelection, scroll, event);
+	G_CONNECT_2 (daPatternSelection, scroll, event);
+	G_CONNECT_1 (daPatternField, draw);
+	G_CONNECT_2 (daPatternField, scroll, event);
 	G_CONNECT_1 (bPatternSave, clicked);
 	G_CONNECT_1 (bPatternDiscard, clicked);
 
diff --git a/src/ui/sf/sf-montage.cc b/src/ui/sf/sf-montage.cc
index b3d11d5..0f5010f 100644
--- a/src/ui/sf/sf-montage.cc
+++ b/src/ui/sf/sf-montage.cc
@@ -276,7 +276,8 @@ draw_page( cairo_t *cr,
 						me-ma, ma, y0, signal_display_scale);
 					aghui::cairo_draw_signal(
 						cr, env_l, 0, env_l.size(),
-						me-ma, ma, y0, signal_display_scale, 1, aghui::TDrawSignalDirection::Backward, true);
+						me-ma, ma, y0, signal_display_scale,
+						1, aghui::TDrawSignalDirection::backward, true);
 					cairo_close_path( cr);
 					cairo_fill( cr);
 					cairo_stroke( cr);
diff --git a/src/ui/sf/sf-patterns.cc b/src/ui/sf/sf-patterns.cc
index bc48b0c..11fb626 100644
--- a/src/ui/sf/sf-patterns.cc
+++ b/src/ui/sf/sf-patterns.cc
@@ -64,30 +64,36 @@ void
 aghui::SScoringFacility::SFindDialog::
 search()
 {
-	if ( field_channel && thing.size() > 0 ) {
-		if ( !(Pp == Pp2) || field_channel != field_channel_saved) {
-			Pp2 = Pp;
-			field_channel_saved = field_channel;
-		}
-		cpattern = new pattern::CPattern<TFloat>
-			({thing, field_channel->samplerate()},
-			 context_before, context_after,
-			 Pp);
-		diff_line =
-		  (cpattern->do_search(
+	if ( unlikely (not field_channel or thing.size() == 0) )
+		return;
+
+	if ( !(Pp == Pp2) || field_channel != field_channel_saved) {
+		Pp2 = Pp;
+		field_channel_saved = field_channel;
+	}
+	cpattern = new pattern::CPattern<TFloat>
+		({thing, field_channel->samplerate()},
+		 context_before, context_after,
+		 Pp);
+	diff_line =
+		(cpattern->do_search(
 			field_channel->signal_envelope( Pp.env_tightness).first,
 			field_channel->signal_envelope( Pp.env_tightness).second,
 			field_channel->signal_bandpass( Pp.bwf_ffrom, Pp.bwf_fupto, Pp.bwf_order),
 			field_channel->signal_dzcdf( Pp.dzcdf_step, Pp.dzcdf_sigma, Pp.dzcdf_smooth),
 			increment * samplerate),
-		   cpattern->diff);
-
-		delete cpattern;
-		cpattern = nullptr;
-
-		gtk_widget_set_visible( (GtkWidget*)_p.daPatternField, TRUE);
-		gtk_widget_set_visible( (GtkWidget*)_p.bPatternSearch, FALSE);
-	}
+		 cpattern->diff);
+
+	delete cpattern;
+	cpattern = nullptr;
+
+	set_field_da_width( _p.total_pages() * 3);
+	field_display_scale =
+		agh::alg::calibrate_display_scale(
+			field_channel->psd.course, _p.total_pages(),
+			da_field_ht);
+	gtk_widget_set_visible( (GtkWidget*)_p.daPatternField, TRUE);
+	gtk_widget_set_visible( (GtkWidget*)_p.bPatternSearch, FALSE);
 }
 
 
@@ -113,12 +119,26 @@ aghui::SScoringFacility::SFindDialog::
 set_pattern_da_width( int width)
 {
 	g_object_set( (GObject*)_p.daPatternSelection,
-		      "width-request", da_wd = width,
-		      "height-request", da_ht,
+		      "width-request", da_thing_wd = width,
+		      "height-request", da_thing_ht,
 		      NULL);
 	g_object_set( (GObject*)_p.vpPatternSelection,
 		      "width-request", min( width+5, 600),
-		      "height-request", da_ht + 30,
+		      "height-request", da_thing_ht + 30,
+		      NULL);
+}
+
+void
+aghui::SScoringFacility::SFindDialog::
+set_field_da_width( int width)
+{
+	g_object_set( (GObject*)_p.daPatternField,
+		      "width-request", da_field_wd = width,
+		      "height-request", da_field_ht,
+		      NULL);
+	g_object_set( (GObject*)_p.vpPatternField,
+		      "width-request", min( width+5, 600),
+		      "height-request", da_thing_ht + 30,
 		      NULL);
 }
 
@@ -130,7 +150,7 @@ draw_thing( cairo_t *cr)
 {
 	if ( thing.size() == 0 ) {
 		set_pattern_da_width( 200);
-		aghui::cairo_put_banner( cr, da_wd, da_ht, "(no selection)");
+		aghui::cairo_put_banner( cr, da_thing_wd, da_thing_ht, "(no selection)");
 		enable_controls( false);
 		return;
 	} else {
@@ -144,14 +164,14 @@ draw_thing( cairo_t *cr)
 	for ( size_t i8 = 0; (float)i8 / 8 < seconds; ++i8 ) {
 		_p._p.CwB[SExpDesignUI::TColour::sf_ticks].set_source_rgba( cr);
 		cairo_set_line_width( cr, (i8%8 == 0) ? 1. : (i8%4 == 0) ? .6 : .3);
-		guint x = (float)i8/8 / seconds * da_wd;
+		guint x = (float)i8/8 / seconds * da_thing_wd;
 		cairo_move_to( cr, x, 0);
-		cairo_rel_line_to( cr, 0, da_ht);
+		cairo_rel_line_to( cr, 0, da_thing_ht);
 		cairo_stroke( cr);
 
 		if ( i8 % 8 == 0 ) {
 			_p._p.CwB[SExpDesignUI::TColour::sf_labels].set_source_rgba( cr);
-			cairo_move_to( cr, x + 5, da_ht-2);
+			cairo_move_to( cr, x + 5, da_thing_ht-2);
 			snprintf_buf( "%g", (float)i8/8);
 			cairo_show_text( cr, __buf__);
 			cairo_stroke( cr);
@@ -164,15 +184,15 @@ draw_thing( cairo_t *cr)
 	cairo_set_source_rgb( cr, 0., 0., 0.);
 	cairo_set_line_width( cr, .8);
 	aghui::cairo_draw_signal( cr, thing, 0, thing.size(),
-				  da_wd, 0, da_ht/3, display_scale);
+				  da_thing_wd, 0, da_thing_ht/3, thing_display_scale);
 	cairo_stroke( cr);
 
 	// lines marking out context
 	cairo_set_source_rgba( cr, 0.9, 0.9, 0.9, .5);
 	cairo_set_line_width( cr, 1.);
-	cairo_rectangle( cr, 0., 0., (float)context_before / thing.size() * da_wd, da_ht);
-	cairo_rectangle( cr, (float)(context_before + run) / thing.size() * da_wd, 0,
-			 (float)(context_after) / thing.size() * da_wd, da_ht);
+	cairo_rectangle( cr, 0., 0., (float)context_before / thing.size() * da_thing_wd, da_thing_ht);
+	cairo_rectangle( cr, (float)(context_before + run) / thing.size() * da_thing_wd, 0,
+			 (float)(context_after) / thing.size() * da_thing_wd, da_thing_ht);
 	cairo_fill( cr);
 	cairo_stroke( cr);
 
@@ -186,7 +206,7 @@ draw_thing( cairo_t *cr)
 			if ( sigproc::envelope( {thing, samplerate}, Pp.env_tightness,
 						1./samplerate,
 						&env_l, &env_u) == 0 ) {
-				aghui::cairo_put_banner( cr, da_wd, da_ht, "Selection is too short");
+				aghui::cairo_put_banner( cr, da_thing_wd, da_thing_ht, "Selection is too short");
 				enable_controls( false);
 				goto out;
 			}
@@ -194,9 +214,10 @@ draw_thing( cairo_t *cr)
 
 			_p._p.CwB[SExpDesignUI::TColour::sf_selection].set_source_rgba_contrasting( cr, .3);
 			aghui::cairo_draw_signal( cr, env_u, 0, env_u.size(),
-						  da_wd, 0, da_ht/3, display_scale);
+						  da_thing_wd, 0, da_thing_ht/2, thing_display_scale);
 			aghui::cairo_draw_signal( cr, env_l, 0, env_l.size(),
-						  da_wd, 0, da_ht/3, display_scale, 1, aghui::TDrawSignalDirection::Backward, true);
+						  da_thing_wd, 0, da_thing_ht/2, thing_display_scale, 1,
+						  aghui::TDrawSignalDirection::backward, true);
 			cairo_close_path( cr);
 			cairo_fill( cr);
 			cairo_stroke( cr);
@@ -205,7 +226,7 @@ draw_thing( cairo_t *cr)
 	      // target frequency
 		{
 			if ( Pp.bwf_ffrom >= Pp.bwf_fupto ) {
-				aghui::cairo_put_banner( cr, da_wd, da_ht, "Bad band-pass range");
+				aghui::cairo_put_banner( cr, da_thing_wd, da_thing_ht, "Bad band-pass range");
 				enable_controls( false);
 				goto out;
 			}
@@ -216,19 +237,19 @@ draw_thing( cairo_t *cr)
 			cairo_set_source_rgba( cr, 0.3, 0.3, 0.3, .5);
 			cairo_set_line_width( cr, 3.);
 			aghui::cairo_draw_signal( cr, course, 0, course.size(),
-						  da_wd, 0, da_ht/3, display_scale);
+						  da_thing_wd, 0, da_thing_ht/3, thing_display_scale);
 			cairo_stroke( cr);
 		}
 
 	      // dzcdf
 		{
 			if ( samplerate < 10 ) {
-				aghui::cairo_put_banner( cr, da_wd, da_ht, "Samplerate is too low");
+				aghui::cairo_put_banner( cr, da_thing_wd, da_thing_ht, "Samplerate is too low");
 				enable_controls( false);
 				goto out;
 			}
 			if ( Pp.dzcdf_step * 10 > pattern_length() ) { // require at least 10 dzcdf points
-				aghui::cairo_put_banner( cr, da_wd, da_ht, "Selection is too short");
+				aghui::cairo_put_banner( cr, da_thing_wd, da_thing_ht, "Selection is too short");
 				enable_controls( false);
 				goto out;
 			}
@@ -236,32 +257,15 @@ draw_thing( cairo_t *cr)
 
 			dzcdf = sigproc::dzcdf( sigproc::SSignalRef<TFloat> {thing, samplerate},
 						Pp.dzcdf_step, Pp.dzcdf_sigma, Pp.dzcdf_smooth);
-			float	dzcdf_display_scale = da_ht/4. / dzcdf.max();
+			float	dzcdf_display_scale = da_thing_ht/4. / dzcdf.max();
 
 			cairo_set_source_rgba( cr, 0.3, 0.3, 0.99, .8);
 			cairo_set_line_width( cr, 1.);
 			aghui::cairo_draw_signal( cr, dzcdf, 0, dzcdf.size(),
-						  da_wd, 0, da_ht/2-5, dzcdf_display_scale);
-			cairo_stroke( cr);
-			cairo_set_line_width( cr, .5);
-			cairo_rectangle( cr, 0, da_ht/2-5, da_wd, da_ht/2-4);
+						  da_thing_wd, 0, da_thing_ht/2-5, dzcdf_display_scale);
 			cairo_stroke( cr);
 		}
 	}
-
-	// report any occurrences
-	
-	//if ( last_find != (size_t)-1 ) {
-	// 	cairo_set_source_rgba( cr, 0.1, 0.1, 0.1, .9);
-	// 	cairo_set_line_width( cr, .7);
-	// 	aghui::cairo_draw_signal( cr, field_channel->signal_filtered,
-	// 				  last_find - context_before, last_find + run + context_after,
-	// 				  da_wd, 0, da_ht*2/3, display_scale);
-	// 	cairo_stroke( cr);
-	// }
-
-
-
 out:
 	;
 }
@@ -270,6 +274,11 @@ void
 aghui::SScoringFacility::SFindDialog::
 draw_field( cairo_t *cr)
 {
+	aghui::cairo_draw_signal(
+		cr,
+		field_channel->psd.course, 0, field_channel->psd.course.size(),
+		da_field_wd, 0., da_field_ht/2, field_display_scale);
+
 }
 
 
@@ -296,7 +305,7 @@ load_pattern( SScoringFacility::SChannel& field)
 						full_sample, 1) ];
 				// or _p.selection_*
 	samplerate = field.samplerate();
-	display_scale = field.signal_display_scale;
+	thing_display_scale = field.signal_display_scale;
 
 	set_pattern_da_width( full_sample / field.spp());
 
@@ -369,7 +378,7 @@ load_pattern( const char *label, bool do_globally)
 				context_after  *= fac;
 			}
 
-			display_scale = field_channel->signal_display_scale;
+			thing_display_scale = field_channel->signal_display_scale;
 			W_V.up();
 
 			set_pattern_da_width( full_sample / field_channel->spp());
diff --git a/src/ui/sf/sf-patterns_cb.cc b/src/ui/sf/sf-patterns_cb.cc
index 8a1b968..4721f4c 100644
--- a/src/ui/sf/sf-patterns_cb.cc
+++ b/src/ui/sf/sf-patterns_cb.cc
@@ -54,16 +54,45 @@ daPatternSelection_scroll_event_cb( GtkWidget *wid, GdkEventScroll *event, gpoin
 	switch ( event->direction ) {
 	case GDK_SCROLL_UP:
 		if ( event->state & GDK_SHIFT_MASK )
-			FD.set_pattern_da_width( FD.da_wd + 10);
+			FD.set_pattern_da_width( FD.da_thing_wd + 10);
 		else
-			FD.display_scale *= 1.05;
+			FD.thing_display_scale *= 1.05;
 	    break;
 	case GDK_SCROLL_DOWN:
 		if ( event->state & GDK_SHIFT_MASK ) {
-			if ( FD.da_wd > 20 )
-				FD.set_pattern_da_width( FD.da_wd - 10);
+			if ( FD.da_thing_wd > 20 )
+				FD.set_pattern_da_width( FD.da_thing_wd - 10);
 		} else
-			FD.display_scale /= 1.05;
+			FD.thing_display_scale /= 1.05;
+	    break;
+	default:
+	    break;
+	}
+
+	gtk_widget_queue_draw( wid);
+
+	return TRUE;
+}
+
+gboolean
+daPatternField_scroll_event_cb( GtkWidget *wid, GdkEventScroll *event, gpointer userdata)
+{
+	auto& SF = *(SScoringFacility*)userdata;
+	auto& FD = SF.find_dialog;
+
+	switch ( event->direction ) {
+	case GDK_SCROLL_UP:
+		if ( event->state & GDK_SHIFT_MASK )
+			FD.set_field_da_width( FD.da_field_wd + 10);
+		else
+			FD.field_display_scale *= 1.05;
+	    break;
+	case GDK_SCROLL_DOWN:
+		if ( event->state & GDK_SHIFT_MASK ) {
+			if ( FD.da_field_wd > 20 )
+				FD.set_field_da_width( FD.da_field_wd - 10);
+		} else
+			FD.field_display_scale /= 1.05;
 	    break;
 	default:
 	    break;
diff --git a/src/ui/sf/sf-phasediff.cc b/src/ui/sf/sf-phasediff.cc
index 57a311f..7a3b2bc 100644
--- a/src/ui/sf/sf-phasediff.cc
+++ b/src/ui/sf/sf-phasediff.cc
@@ -134,23 +134,17 @@ draw( cairo_t* cr, int wd, int ht)
 	cairo_stroke( cr);
 
 	if ( channel1 == channel2 ) {
-		cairo_move_to( cr, 5, 15);
-		cairo_show_text( cr, "Same channel");
-		cairo_stroke( cr);
+		aghui::cairo_put_banner( cr, wd, ht, "Same channel");
 		return;
 	}
 
 	if ( course.size() == 0 ) {
-		cairo_move_to( cr, 5, 15);
-		cairo_show_text( cr, "Huh?");
-		cairo_stroke( cr);
+		aghui::cairo_put_banner( cr, wd, ht, "Huh?");
 		return;
 	}
 
 	if ( channel1->samplerate() != channel2->samplerate() ) {
-		cairo_move_to( cr, 5, 15);
-		cairo_show_text( cr, "Incompatible channels (different samplerate)");
-		cairo_stroke( cr);
+		aghui::cairo_put_banner( cr, wd, ht, "Incompatible channels (different samplerate)");
 		return;
 	}
 
diff --git a/src/ui/sf/sf.hh b/src/ui/sf/sf.hh
index 48b5ef6..878dc20 100644
--- a/src/ui/sf/sf.hh
+++ b/src/ui/sf/sf.hh
@@ -547,7 +547,8 @@ class SScoringFacility
 		bool	draw_details:1;
 		void draw_thing( cairo_t*);
 		void draw_field( cairo_t*);
-		float	display_scale;
+		float	thing_display_scale,
+			field_display_scale;
 
 	      // widgets
 		SUIVarCollection
@@ -559,9 +560,12 @@ class SScoringFacility
 		void enable_controls( bool);
 
 		static const int
-			da_ht = 280;
-		int	da_wd;
+			da_thing_ht = 220,
+			da_field_ht = 230;
+		int	da_thing_wd,
+			da_field_wd;
 		void set_pattern_da_width( int);
+		void set_field_da_width( int);
 
 		SScoringFacility&
 			_p;
diff --git a/src/ui/sf/sf_cb.hh b/src/ui/sf/sf_cb.hh
index 94066b5..d456ebf 100644
--- a/src/ui/sf/sf_cb.hh
+++ b/src/ui/sf/sf_cb.hh
@@ -152,6 +152,7 @@ void iSFScoreClear_activate_cb( GtkMenuItem*, gpointer);
 void ePatternList_changed_cb( GtkComboBox*, gpointer);
 void ePatternChannel_changed_cb( GtkComboBox*, gpointer);
 gboolean daPatternField_draw_cb( GtkWidget*, cairo_t*, gpointer);
+gboolean daPatternField_scroll_event_cb( GtkWidget*, GdkEventScroll*, gpointer);
 gboolean daPatternSelection_draw_cb( GtkWidget*, cairo_t*, gpointer);
 gboolean daPatternSelection_scroll_event_cb( GtkWidget*, GdkEventScroll*, gpointer);
 void bPatternSearch_clicked_cb( GtkButton*, gpointer);
diff --git a/src/ui/ui.hh b/src/ui/ui.hh
index 8aed21a..5fc15b6 100644
--- a/src/ui/ui.hh
+++ b/src/ui/ui.hh
@@ -121,14 +121,15 @@ void gtk_cell_layout_set_renderer( GtkComboBox*);
 
 
 
-enum TDrawSignalDirection { Forward, Backward };
+enum TDrawSignalDirection { forward, backward };
+
 void
-cairo_draw_signal( cairo_t *cr,
-		   const valarray<TFloat>& signal,
+cairo_draw_signal( cairo_t*,
+		   const valarray<TFloat>&,
 		   ssize_t start, ssize_t end,
 		   size_t da_wd, double hdisp, double vdisp, float display_scale,
 		   unsigned short decimate = 1,
-		   TDrawSignalDirection direction = TDrawSignalDirection::Forward,
+		   TDrawSignalDirection direction = TDrawSignalDirection::forward,
 		   bool continue_path = false);
 
 inline void
@@ -137,7 +138,7 @@ cairo_draw_signal( cairo_t *cr,
 		   ssize_t start, ssize_t end,
 		   size_t width, double hdisp, double vdisp, float display_scale,
 		   unsigned short decimate = 1,
-		   TDrawSignalDirection direction = TDrawSignalDirection::Forward,
+		   TDrawSignalDirection direction = TDrawSignalDirection::forward,
 		   bool continue_path = false)
 {
 	valarray<TFloat> tmp (end - start); // avoid copying other rows, cols

-- 
Sleep experiment manager



More information about the debian-med-commit mailing list