[med-svn] [aghermann] 15/23: some thorough ICM under ui/ with little apparent effect

andrei zavada hmmr-guest at alioth.debian.org
Sat Aug 17 18:05:42 UTC 2013


This is an automated email from the git hooks/post-receive script.

hmmr-guest pushed a commit to branch master
in repository aghermann.

commit e183518457d7fa74184a2b378fea2dd48c797e88
Author: Andrei Zavada <johnhommer at gmail.com>
Date:   Sun Aug 11 03:02:01 2013 +0300

    some thorough ICM under ui/ with little apparent effect
    
    1. Remove GString* __ss__; from ui/globals.cc.
    2. Make snprintf_buf a function returning const char* (not a macro).
    3. Do away with g_string_*.
    4. Better use namespaces (arguably better) under ui.
    5. Move SManagedColor to ui++.hh.
---
 src/aghermann/globals.cc                           |    9 +-
 src/aghermann/ica/ica.hh                           |    8 +-
 src/aghermann/main.cc                              |   60 ++++---
 src/aghermann/ui/Makefile.am                       |    5 +-
 src/aghermann/ui/forward-decls.hh                  |    2 +-
 src/aghermann/ui/globals.cc                        |   39 +++++
 src/aghermann/ui/globals.hh                        |   29 ++--
 src/aghermann/ui/mf/mf-construct.cc                |    4 +-
 src/aghermann/ui/mf/mf.cc                          |   49 +++---
 src/aghermann/ui/mf/mf_cb.cc                       |   27 +--
 src/aghermann/ui/misc.cc                           |   97 +++++++++++
 src/aghermann/ui/misc.hh                           |   28 +++-
 src/aghermann/ui/mw/Makefile.am                    |    1 +
 src/aghermann/ui/mw/admit-one.cc                   |  122 +-------------
 src/aghermann/ui/mw/admit-one_cb.cc                |  144 ++++++++++++++++
 src/aghermann/ui/mw/construct.cc                   |    9 +-
 src/aghermann/ui/mw/loadsave.cc                    |    6 +-
 src/aghermann/ui/mw/mainmenu_cb.cc                 |    4 +-
 src/aghermann/ui/mw/measurements.cc                |   37 +++--
 src/aghermann/ui/mw/measurements_cb.cc             |    4 +-
 src/aghermann/ui/mw/mw.cc                          |   64 ++++----
 src/aghermann/ui/mw/populate.cc                    |   49 +++---
 src/aghermann/ui/mw/simulations.cc                 |   10 +-
 src/aghermann/ui/mw/simulations_cb.cc              |   15 +-
 src/aghermann/ui/mw/splash.cc                      |   19 +--
 src/aghermann/ui/mw/widgets.hh                     |    2 +-
 src/aghermann/ui/sf/channel.cc                     |   53 +++---
 src/aghermann/ui/sf/construct.cc                   |    6 +-
 src/aghermann/ui/sf/d/artifacts-construct.cc       |    6 +-
 .../ui/sf/d/artifacts-simple-construct.cc          |    6 +-
 src/aghermann/ui/sf/d/artifacts-simple.cc          |    9 +-
 src/aghermann/ui/sf/d/artifacts.cc                 |   11 +-
 src/aghermann/ui/sf/d/filters-construct.cc         |    6 +-
 src/aghermann/ui/sf/d/filters.cc                   |    8 +-
 src/aghermann/ui/sf/d/patterns-construct.cc        |    5 +-
 src/aghermann/ui/sf/d/patterns-draw.cc             |   63 +++----
 src/aghermann/ui/sf/d/patterns-profiles.cc         |   23 +--
 src/aghermann/ui/sf/d/patterns-profiles_cb.cc      |    2 -
 src/aghermann/ui/sf/d/patterns.cc                  |   36 ++--
 src/aghermann/ui/sf/d/phasediff-construct.cc       |    6 +-
 src/aghermann/ui/sf/d/phasediff.cc                 |   26 +--
 src/aghermann/ui/sf/hypnogram.cc                   |    9 +-
 src/aghermann/ui/sf/ica.cc                         |   27 +--
 src/aghermann/ui/sf/montage-overlays.cc            |   48 +++---
 src/aghermann/ui/sf/montage.cc                     |  127 +++++++-------
 src/aghermann/ui/sf/montage_cb.cc                  |   98 ++++++-----
 src/aghermann/ui/sf/sf.cc                          |   90 +++++-----
 src/aghermann/ui/sf/sf_cb.cc                       |    2 +-
 src/aghermann/ui/sm/sm-construct.cc                |    3 +-
 src/aghermann/ui/sm/sm.cc                          |   53 +++---
 src/aghermann/ui/sm/sm_cb.cc                       |    4 +-
 src/aghermann/ui/ui++.cc                           |   63 +++++++
 src/aghermann/ui/ui++.hh                           |  125 ++++++++++++--
 src/aghermann/ui/{libcommon.cc => ui.cc}           |  173 +++-----------------
 src/aghermann/ui/ui.hh                             |   88 +---------
 src/common/lang.hh                                 |    2 -
 src/common/libcommon.cc                            |  132 +++++++--------
 src/common/string.hh                               |   44 +++--
 src/tools/edfhed-gtk.cc                            |    2 +-
 59 files changed, 1194 insertions(+), 1005 deletions(-)

diff --git a/src/aghermann/globals.cc b/src/aghermann/globals.cc
index b7be0be..fed13a9 100644
--- a/src/aghermann/globals.cc
+++ b/src/aghermann/globals.cc
@@ -48,17 +48,12 @@ init()
 		rng = gsl_rng_alloc( T);
 	}
 
+#ifdef _OPENMP
       // 2. omp
 	{
-#ifdef _OPENMP
 		agh::global::num_procs = omp_get_max_threads();
-		// if ( agh::global::num_procs > 1 )
-		// 	printf( "This host is SMP-capable (omp_get_max_threads() returns %d)\n", agh::global::num_procs);
-		// else
-		// 	printf( "This host is not SMP-capable\n");
-#endif
-
 	}
+#endif
 }
 
 
diff --git a/src/aghermann/ica/ica.hh b/src/aghermann/ica/ica.hh
index 3d840f5..ae22a35 100644
--- a/src/aghermann/ica/ica.hh
+++ b/src/aghermann/ica/ica.hh
@@ -9,8 +9,8 @@
  *         License:  GPL
  */
 
-#ifndef _AGH_ICA_HH
-#define _AGH_ICA_HH
+#ifndef _AGH_ICA_ICA_HH
+#define _AGH_ICA_ICA_HH
 
 #include <valarray>
 #include <vector>
@@ -43,7 +43,7 @@ to_vecva( const itpp::Mat<T>& rv)
 		ret.emplace_back( rv.cols());
 		memcpy( &ret.back()[0], &v(0), sizeof(T) * rv.cols());
 	}
-	return ret;
+	return move(ret);
 }
 
 template <class Tl, class Tr>
@@ -58,7 +58,7 @@ to_va( const itpp::Mat<Tr>& rv, int row)
 	else
 		for ( int c = 0; c < rv.cols(); ++c )
 			ret[c] = rv(row, c);
-	return ret;
+	return move(ret);
 }
 
 template <class Titpp, class T>
diff --git a/src/aghermann/main.cc b/src/aghermann/main.cc
index 758d228..2d410f6 100644
--- a/src/aghermann/main.cc
+++ b/src/aghermann/main.cc
@@ -12,7 +12,7 @@
 
 
 #ifdef _OPENMP
-#include <omp.h>
+# include <omp.h>
 #endif
 
 #include <gtk/gtk.h>
@@ -24,16 +24,17 @@
 #include "ui/ui.hh"
 #include "ui/sm/sm.hh"
 
-
+using namespace agh;
 
 static UniqueResponse
-message_received_cb( UniqueApp         *,
-                     UniqueCommand      command,
-                     UniqueMessageData *message,
-                     guint              time_,
-                     gpointer           )
+message_received_cb(
+	UniqueApp*,
+	const UniqueCommand      command,
+	UniqueMessageData       *message,
+	const guint              time_,
+	gpointer)
 {
-	if ( agh::ui::__main_window__ == NULL )
+	if ( ui::global::main_window == NULL )
 		return UNIQUE_RESPONSE_OK;
 
 	UniqueResponse res;
@@ -41,8 +42,12 @@ message_received_cb( UniqueApp         *,
 	switch ( command ) {
 	case UNIQUE_ACTIVATE:
 		// move the main window to the screen that sent us the command
-		gtk_window_set_screen( agh::ui::__main_window__, unique_message_data_get_screen( message));
-		gtk_window_present_with_time( agh::ui::__main_window__, time_);
+		gtk_window_set_screen(
+			ui::global::main_window,
+			unique_message_data_get_screen( message));
+		gtk_window_present_with_time(
+			ui::global::main_window,
+			time_);
 		res = UNIQUE_RESPONSE_OK;
 	    break;
 	default:
@@ -84,35 +89,38 @@ main( int argc, char **argv)
 			return -1;
 		}
 
-		agh::global::init();
-		agh::CExpDesign ED (explicit_session); // essentially a very thoughtful no-op
-		agh::global::fini();
+		global::init();
+		CExpDesign ED (explicit_session); // essentially a very thoughtful no-op
+		global::fini();
 
 	} else {
-
 		gtk_init( &argc, &argv);
 
 		// don't let user get us started twice
-		agh::ui::__unique_app__ =
-			unique_app_new_with_commands( "com.johnhommer.Aghermann", NULL,
-						      "fafa", 1,
-						      NULL);
-		if ( unique_app_is_running( agh::ui::__unique_app__) ) {
+		ui::global::unique_app =
+			unique_app_new_with_commands(
+				"com.johnhommer.Aghermann",
+				NULL, "fafa", 1, NULL);
+		if ( unique_app_is_running( ui::global::unique_app) ) {
 			printf( "There is unique app, switching to it now\n");
-			unique_app_send_message( agh::ui::__unique_app__, UNIQUE_ACTIVATE, NULL);
+			unique_app_send_message( ui::global::unique_app, UNIQUE_ACTIVATE, NULL);
 		} else {
-			g_signal_connect( agh::ui::__unique_app__, "message-received",
-					  (GCallback)message_received_cb,
-					  NULL);
+			g_signal_connect(
+				ui::global::unique_app, "message-received",
+				(GCallback)message_received_cb,
+				NULL);
 
 			agh::global::init();
 
-			if ( agh::ui::prepare_for_expdesign() ) {
-				agh::ui::pop_ok_message( NULL, "UI failed to initialize", "Your install is broken.");
+			if ( ui::prepare_for_expdesign() ) {
+				ui::pop_ok_message(
+					NULL,
+					"UI failed to initialize",
+					"Your install is broken.");
 				return 2;
 			}
 
-			agh::ui::SSessionChooser chooser (argv[optind]);
+			ui::SSessionChooser chooser (argv[optind]);
 			// implicit read sessionrc, run
 
 			gtk_main();
diff --git a/src/aghermann/ui/Makefile.am b/src/aghermann/ui/Makefile.am
index 84dac2a..dd17719 100644
--- a/src/aghermann/ui/Makefile.am
+++ b/src/aghermann/ui/Makefile.am
@@ -10,10 +10,13 @@ noinst_LIBRARIES := liba.a
 
 liba_a_SOURCES := \
 	forward-decls.hh \
+	globals.cc \
 	globals.hh \
-	libcommon.cc \
+	misc.cc \
 	misc.hh \
+	ui++.cc \
 	ui++.hh \
+	ui.cc \
 	ui.hh
 
 if DO_PCH
diff --git a/src/aghermann/ui/forward-decls.hh b/src/aghermann/ui/forward-decls.hh
index dfa05de..03d7a97 100644
--- a/src/aghermann/ui/forward-decls.hh
+++ b/src/aghermann/ui/forward-decls.hh
@@ -1,5 +1,5 @@
 /*
- *       File name:  ui/forward-decls.hh
+ *       File name:  aghermann/ui/forward-decls.hh
  *         Project:  Aghermann
  *          Author:  Andrei Zavada <johnhommer at gmail.com>
  * Initial version:  2010-09-03
diff --git a/src/aghermann/ui/globals.cc b/src/aghermann/ui/globals.cc
new file mode 100644
index 0000000..d23318d
--- /dev/null
+++ b/src/aghermann/ui/globals.cc
@@ -0,0 +1,39 @@
+/*
+ *       File name:  aghermann/ui/globals.cc
+ *         Project:  Aghermann
+ *          Author:  Andrei Zavada <johnhommer at gmail.com>
+ * Initial version:  2013-08-10
+ *
+ *         Purpose:  global UI-related variables
+ *
+ *         License:  GPL
+ */
+
+#include <gtk/gtk.h>
+#include "globals.hh"
+
+using namespace std;
+using namespace agh::ui;
+
+char	global::buf[AGH_BUF_SIZE];
+
+GdkDevice
+	*global::client_pointer;
+
+UniqueApp
+	*global::unique_app;
+
+GtkWindow
+	*global::main_window;
+
+double	global::hdpmm,
+	global::vdpmm;
+
+
+// Local Variables:
+// Mode: c++
+// indent-tabs-mode: 8
+// tab-width: 8
+// c-basic-offset: 8
+// End:
+
diff --git a/src/aghermann/ui/globals.hh b/src/aghermann/ui/globals.hh
index b5724a7..ed263d2 100644
--- a/src/aghermann/ui/globals.hh
+++ b/src/aghermann/ui/globals.hh
@@ -25,35 +25,30 @@ using namespace std;
 
 namespace agh {
 namespace ui {
+namespace global {
 
+// convenience assign-once vars
 extern UniqueApp
-	*__unique_app__;
+	*unique_app;
 
 extern GtkWindow
-	*__main_window__;
+	*main_window;
 
-// convenience assign-once vars
 extern GdkDevice
-	*__client_pointer__;
+	*client_pointer;
+
+extern double
+	hdpmm,
+	vdpmm;
 
 // quick tmp storage
 #define AGH_BUF_SIZE (1024*5)
 extern char
-	__buf__[AGH_BUF_SIZE];
-extern GString
-	*__ss__;
-
-extern double
-	__hdpmm__,
-	__vdpmm__;
-
-
-int prepare_for_expdesign();
-
-void set_unique_app_window( GtkWindow*);
+	buf[AGH_BUF_SIZE];
 
 }
-} // namespace agh::ui
+}
+} // namespace agh::ui::global
 
 #endif
 
diff --git a/src/aghermann/ui/mf/mf-construct.cc b/src/aghermann/ui/mf/mf-construct.cc
index 6ff7b75..5d15781 100644
--- a/src/aghermann/ui/mf/mf-construct.cc
+++ b/src/aghermann/ui/mf/mf-construct.cc
@@ -12,9 +12,11 @@
 #include "mf.hh"
 #include "mf_cb.hh"
 
+using namespace std;
+using namespace agh::ui;
 
 int
-agh::ui::SModelrunFacility::
+SModelrunFacility::
 construct_widgets()
 {
 	if ( !(AGH_GBGETOBJ3 (builder, GtkWindow,	wModelrunFacility)) ||
diff --git a/src/aghermann/ui/mf/mf.cc b/src/aghermann/ui/mf/mf.cc
index fdac7f7..43d679b 100644
--- a/src/aghermann/ui/mf/mf.cc
+++ b/src/aghermann/ui/mf/mf.cc
@@ -30,7 +30,7 @@ unsigned short __score_hypn_depth[8] = {
 }
 
 
-agh::ui::SModelrunFacility::
+SModelrunFacility::
 SModelrunFacility (agh::ach::CModelRun& csim, SExpDesignUI& parent)
       : csimulation (csim),
 // subject is known only by name, so look up his full object now
@@ -64,9 +64,10 @@ SModelrunFacility (agh::ach::CModelRun& csim, SExpDesignUI& parent)
 
 	gtk_window_set_title(
 		wModelrunFacility,
-		snprintf_buf( "Simulation: %s (%s) in %s (%s)",
-			      csim.subject(), csim.session(), csim.channel(),
-			      csim.P().display_name().c_str()));
+		snprintf_buf(
+			"Simulation: %s (%s) in %s (%s)",
+			csim.subject(), csim.session(), csim.channel(),
+			csim.P().display_name().c_str()));
 	gtk_window_set_default_size(
 		wModelrunFacility,
 		gdk_screen_get_width( gdk_screen_get_default()) * .80,
@@ -79,16 +80,17 @@ SModelrunFacility (agh::ach::CModelRun& csim, SExpDesignUI& parent)
 	gtk_scale_button_set_value( eMFSmooth, swa_smoothover);
 	update_infobar();
 
-	snprintf_buf( "### Simulation: %s (%s) in %s (%s)\n"
-		      "# sim start at p. %zu, end at p. %zu, baseline end at p. %zu,\n"
-		      "# %zu pp with SWA, %zu pp in bed;\n"
-		      "# SWA_L = %g, SWA[0] = %g, 100%% SWA = %g\n",
-		      csim.subject(),
-		      _p.AghD(), _p.AghH(), csim.P().display_name().c_str(),
-		      csim.sim_start(), csim.sim_end(), csim.baseline_end(),
-		      csim.pages_with_swa(), csim.pages_in_bed(),
-		      csim.SWA_L(), csim.SWA_0(), csim.SWA_100());
-	gtk_text_buffer_set_text( log_text_buffer, __buf__, -1);
+	snprintf_buf(
+		"### Simulation: %s (%s) in %s (%s)\n"
+		"# sim start at p. %zu, end at p. %zu, baseline end at p. %zu,\n"
+		"# %zu pp with SWA, %zu pp in bed;\n"
+		"# SWA_L = %g, SWA[0] = %g, 100%% SWA = %g\n",
+		csim.subject(),
+		_p.AghD(), _p.AghH(), csim.P().display_name().c_str(),
+		csim.sim_start(), csim.sim_end(), csim.baseline_end(),
+		csim.pages_with_swa(), csim.pages_in_bed(),
+		csim.SWA_L(), csim.SWA_0(), csim.SWA_100());
+	gtk_text_buffer_set_text( log_text_buffer, global::buf, -1);
 
 	for ( auto &tuple : eMFVx ) {
 		auto	jdst = gtk_spin_button_get_adjustment( tuple.first);
@@ -105,13 +107,13 @@ SModelrunFacility (agh::ach::CModelRun& csim, SExpDesignUI& parent)
 
 	gtk_button_set_label(
 		(GtkButton*)eMFSmooth,
-		(snprintf_buf( "Smooth: %zu", swa_smoothover), __buf__));
+		snprintf_buf( "Smooth: %zu", swa_smoothover));
 
 	gtk_widget_show_all( (GtkWidget*)wModelrunFacility);
 }
 
 
-agh::ui::SModelrunFacility::
+SModelrunFacility::
 ~SModelrunFacility()
 {
 	gtk_widget_destroy( (GtkWidget*)wModelrunFacility);
@@ -120,7 +122,7 @@ agh::ui::SModelrunFacility::
 
 
 void
-agh::ui::SModelrunFacility::
+SModelrunFacility::
 siman_param_printer( void *xp)
 {
 //	memcpy( __t_set.tunables, xp, __t_set.n_tunables * sizeof(double));
@@ -137,7 +139,7 @@ siman_param_printer( void *xp)
 
 
 void
-agh::ui::SModelrunFacility::
+SModelrunFacility::
 draw_timeline( cairo_t *cr)
 {
       // empirical SWA
@@ -213,14 +215,14 @@ draw_timeline( cairo_t *cr)
 
 
 
-size_t agh::ui::SModelrunFacility::swa_smoothover = 2;
+size_t SModelrunFacility::swa_smoothover = 2;
 
 
 
 
 
 void
-agh::ui::SModelrunFacility::
+SModelrunFacility::
 draw_episode( cairo_t *cr,
 	      const size_t ep,
 	      const size_t ep_start, const size_t ep_end,
@@ -342,7 +344,7 @@ draw_episode( cairo_t *cr,
 
 
 void
-agh::ui::SModelrunFacility::
+SModelrunFacility::
 draw_ticks( cairo_t *cr,
 	    size_t start, const size_t end)
 {
@@ -371,8 +373,7 @@ draw_ticks( cairo_t *cr,
 		cairo_move_to( cr,
 			       (float)(i-start)/(end-start) * da_wd_actual() + 2,
 			       da_ht - hypn_depth-lgd_margin + 14);
-		snprintf_buf_ts_h( (double)i/pph);
-		cairo_show_text( cr, __buf__);
+		cairo_show_text( cr, snprintf_buf_ts_h( (double)i/pph));
 		cairo_stroke( cr);
 	}
 }
@@ -385,7 +386,7 @@ draw_ticks( cairo_t *cr,
 
 
 void
-agh::ui::SModelrunFacility::
+SModelrunFacility::
 update_infobar()
 {
 	_suppress_Vx_value_changed = true;
diff --git a/src/aghermann/ui/mf/mf_cb.cc b/src/aghermann/ui/mf/mf_cb.cc
index 6fe545e..fde36db 100644
--- a/src/aghermann/ui/mf/mf_cb.cc
+++ b/src/aghermann/ui/mf/mf_cb.cc
@@ -9,6 +9,7 @@
  *         License:  GPL
  */
 
+#include <sstream>
 #include <cairo-svg.h>
 
 #include "aghermann/model/beersma.hh"
@@ -83,7 +84,7 @@ daMFProfile_button_press_event_cb(
 				snprintf_buf( "%s%s", fname_,
 					      g_str_has_suffix( fname_, ".svg") ? "" : ".svg");
 				g_free( fname_);
-				cairo_surface_t *cs = cairo_svg_surface_create( __buf__, MF.da_wd, MF.da_ht);
+				cairo_surface_t *cs = cairo_svg_surface_create( global::buf, MF.da_wd, MF.da_ht);
 				cairo_t *cr = cairo_create( cs);
 				MF.draw_timeline( cr);
 				cairo_destroy( cr);
@@ -152,7 +153,7 @@ daMFProfile_scroll_event_cb(
 
 
 namespace {
-agh::ui::SModelrunFacility *this_mf = nullptr;
+SModelrunFacility *this_mf = nullptr;
 void this_mf_siman_param_printer(void *xp)
 {
 	this_mf -> siman_param_printer(xp);
@@ -166,7 +167,7 @@ bMFRun_clicked_cb(
 {
 	auto& MF = *(SModelrunFacility*)userdata;
 
-	agh::ui::SBusyBlock bb (MF.wModelrunFacility);
+	SBusyBlock bb (MF.wModelrunFacility);
 
 	void (*fun)(void*) = (this_mf == nullptr)
 		? (this_mf = &MF, this_mf_siman_param_printer)
@@ -181,32 +182,32 @@ bMFRun_clicked_cb(
 
 	GtkTextIter iter;
 	if ( not MF._tunables_header_printed ) {
-		g_string_printf( __ss__, "#");
+		ostringstream ss;
+		ss << "#";
 		for ( size_t t = 0; t < MF.csimulation.tx.size(); ++t )
-			g_string_append_printf(
-				__ss__, "%s%s",
+			ss << agh::str::sasprintf(
+				"%s%s",
 				agh::ach::tunable_name(t).c_str(),
 				t < MF.csimulation.tx.size()-1 ? "\t" : "\n");
 		gtk_text_buffer_insert(
 			MF.log_text_buffer,
 			(gtk_text_buffer_get_end_iter( MF.log_text_buffer, &iter), &iter),
-			__ss__->str, -1);
+			ss.str().c_str(), -1);
 		MF._tunables_header_printed = true;
 	}
 
 	for ( size_t t = 0; t < MF.csimulation.tx.size(); ++t ) {
 		auto tg = min( t, (size_t)agh::ach::TTunable::_basic_tunables-1);
-		g_string_printf(
-			__ss__, agh::ach::stock[tg].fmt,
-			MF.csimulation.tx[t] * agh::ach::stock[tg].display_scale_factor);
 		snprintf_buf(
 			"%s%s",
-			__ss__->str,
+			agh::str::sasprintf(
+				agh::ach::stock[tg].fmt,
+				MF.csimulation.tx[t] * agh::ach::stock[tg].display_scale_factor).c_str(),
 			t < MF.csimulation.tx.size()-1 ? "\t" : "\n");
 		gtk_text_buffer_insert(
 			MF.log_text_buffer,
   			(gtk_text_buffer_get_end_iter( MF.log_text_buffer, &iter), &iter),
-			__buf__, -1);
+			global::buf, -1);
 	}
 	gtk_text_view_scroll_to_iter(
 		MF.lMFLog,
@@ -319,7 +320,7 @@ eMFClassicFit_toggled_cb(
 
 	gtk_label_set_markup(
 		MF.lMFClassicFit,
-		__buf__);
+		global::buf);
 }
 
 
diff --git a/src/aghermann/ui/misc.cc b/src/aghermann/ui/misc.cc
new file mode 100644
index 0000000..f2f3c7d
--- /dev/null
+++ b/src/aghermann/ui/misc.cc
@@ -0,0 +1,97 @@
+/*
+ *       File name:  aghermann/ui/misc.cc
+ *         Project:  Aghermann
+ *          Author:  Andrei Zavada <johnhommer at gmail.com>
+ * Initial version:  2013-08-10
+ *
+ *         Purpose:  general-purpose non-GTK+ functions
+ *
+ *         License:  GPL
+ */
+
+#include <math.h>
+#include "misc.hh"
+
+using namespace std;
+using namespace agh::ui;
+
+// these are intended for durations, not timestamps
+const char*
+agh::ui::
+snprintf_buf_ts_d( const double d_)
+{
+	if ( d_ < 1. )
+		snprintf_buf_ts_h( d_ * 24);
+	else {
+		unsigned m_ = lroundf(d_*24*60*60) / 60,
+			m = (m_ % 60),
+			h = (m_ / 60) % 24,
+			d = (m_ / 60 / 24);
+		if ( h % 24 == 0 && m % 60 == 0 )
+			snprintf_buf( "%ud", d);
+		else if ( m % 60 == 0 )
+			snprintf_buf( "%ud%uh", d, h);
+		else
+			snprintf_buf( "%ud%uh%um", d, h, m);
+	}
+	return global::buf;
+}
+
+const char*
+agh::ui::
+snprintf_buf_ts_h( const double h_)
+{
+	if ( h_ < 1. )
+		snprintf_buf_ts_m( h_ * 60);
+	else if ( h_ >= 24. )
+		snprintf_buf_ts_d( h_ / 24);
+	else {
+		unsigned m_ = lroundf( h_*60*60) / 60,
+			m = (m_ % 60),
+			h = (m_ / 60);
+		if ( m % 60 == 0 )
+			snprintf_buf( "%uh", h);
+		else
+			snprintf_buf( "%uh%um", h, m);
+	}
+	return global::buf;
+}
+
+const char*
+agh::ui::
+snprintf_buf_ts_m( const double m_)
+{
+	if ( m_ < 1. )
+		snprintf_buf_ts_s( m_ * 60);
+	else if ( m_ >= 60. )
+		snprintf_buf_ts_h( m_ / 60);
+	else {
+		unsigned s_ = lroundf( m_*60) / 60,
+			s = (s_ % 60),
+			m = (s_ / 60);
+		if ( s % 60 == 0 )
+			snprintf_buf( "%um", m);
+		else
+			snprintf_buf( "%um%us", m, s);
+	}
+	return global::buf;
+}
+
+const char*
+agh::ui::
+snprintf_buf_ts_s( const double s_)
+{
+	if ( s_ >= 60. )
+		snprintf_buf_ts_m( s_/60);
+	else
+		snprintf_buf( "%.2gs", s_);
+	return global::buf;
+}
+
+// Local Variables:
+// Mode: c++
+// indent-tabs-mode: 8
+// tab-width: 8
+// c-basic-offset: 8
+// End:
+
diff --git a/src/aghermann/ui/misc.hh b/src/aghermann/ui/misc.hh
index 99d72b2..221d24f 100644
--- a/src/aghermann/ui/misc.hh
+++ b/src/aghermann/ui/misc.hh
@@ -13,10 +13,12 @@
 #ifndef AGH_AGHERMANN_UI_MISC_H_
 #define AGH_AGHERMANN_UI_MISC_H_
 
+#include <stdio.h>
+#include <stdarg.h>
 #include "globals.hh"
 
 #if HAVE_CONFIG_H && !defined(VERSION)
-#  include "config.h"
+# include "config.h"
 #endif
 
 using namespace std;
@@ -24,12 +26,26 @@ using namespace std;
 namespace agh {
 namespace ui {
 
-#define snprintf_buf(...) (snprintf( __buf__, AGH_BUF_SIZE-1, __VA_ARGS__), __buf__)
+inline const char*
+snprintf_buf( const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
 
-void snprintf_buf_ts_d( double h);
-void snprintf_buf_ts_h( double h);
-void snprintf_buf_ts_m( double m);
-void snprintf_buf_ts_s( double s);
+inline const char*
+snprintf_buf( const char* fmt, ...)
+{
+	va_list ap;
+	va_start (ap, fmt);
+
+	vsnprintf( global::buf, AGH_BUF_SIZE-1, fmt, ap);
+	va_end (ap);
+
+	return global::buf;
+}
+
+
+const char* snprintf_buf_ts_d( double h);
+const char* snprintf_buf_ts_h( double h);
+const char* snprintf_buf_ts_m( double m);
+const char* snprintf_buf_ts_s( double s);
 
 }
 } // namespace agh::ui
diff --git a/src/aghermann/ui/mw/Makefile.am b/src/aghermann/ui/mw/Makefile.am
index 465fc77..a833d39 100644
--- a/src/aghermann/ui/mw/Makefile.am
+++ b/src/aghermann/ui/mw/Makefile.am
@@ -9,6 +9,7 @@ noinst_LIBRARIES = liba.a
 
 liba_a_SOURCES = \
 	admit-one.cc \
+	admit-one_cb.cc \
 	construct.cc \
 	loadsave.cc \
 	mainmenu_cb.cc \
diff --git a/src/aghermann/ui/mw/admit-one.cc b/src/aghermann/ui/mw/admit-one.cc
index e4d8b60..7a296a4 100644
--- a/src/aghermann/ui/mw/admit-one.cc
+++ b/src/aghermann/ui/mw/admit-one.cc
@@ -19,7 +19,7 @@ using namespace agh::ui;
 
 
 int
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 dnd_maybe_admit_one( const char* fname)
 {
 	try {
@@ -200,126 +200,6 @@ dnd_maybe_admit_one( const char* fname)
 }
 
 
-
-extern "C" {
-
-gboolean
-check_gtk_entry_nonempty_cb( GtkEditable*,
-			     // GdkEventKey *event,
-			     const gpointer  userdata)
-{
-	auto& ED = *(SExpDesignUI*)userdata;
-
-	gtk_widget_set_sensitive( (GtkWidget*)ED.bEdfImportAdmit, TRUE);
-
-	const gchar *e;
-	gchar *ee;
-
-	ee = NULL;
-	e = gtk_entry_get_text( ED.eEdfImportGroupEntry);
-	if ( !e || !*g_strchug( g_strchomp( ee = g_strdup( e))) ) {
-		gtk_widget_set_sensitive( (GtkWidget*)ED.bEdfImportAdmit, FALSE);
-	}
-	g_free( ee);
-
-	ee = NULL;
-	e = gtk_entry_get_text( ED.eEdfImportSessionEntry);
-	if ( !e || !*g_strchug( g_strchomp( ee = g_strdup( e))) ) {
-		gtk_widget_set_sensitive( (GtkWidget*)ED.bEdfImportAdmit, FALSE);
-	}
-	g_free( ee);
-
-	ee = NULL;
-	e = gtk_entry_get_text( ED.eEdfImportEpisodeEntry);
-	if ( !e || !*g_strchug( g_strchomp( ee = g_strdup( e))) ) {
-		gtk_widget_set_sensitive( (GtkWidget*)ED.bEdfImportAdmit, FALSE);
-	}
-	g_free( ee);
-
-	gtk_widget_queue_draw( (GtkWidget*)ED.bEdfImportAdmit);
-
-	return false;
-}
-
-
-
-
-void
-cMeasurements_drag_data_received_cb( const GtkWidget        *widget,
-				     GdkDragContext   *context,
-				     const gint              x,
-				     const gint              y,
-				     const GtkSelectionData *selection_data,
-				     const guint             info,
-				     const guint             time,
-				     const gpointer          userdata)
-{
-	auto& ED = *(SExpDesignUI*)userdata;
-
-	gchar **uris = gtk_selection_data_get_uris( selection_data);
-	if ( uris != NULL ) {
-
-		guint i = 0;
-		while ( uris[i] ) {
-			if ( strncmp( uris[i], "file://", 7) == 0 ) {
-				char *fname = g_filename_from_uri( uris[i], NULL, NULL);
-				int retval = ED.dnd_maybe_admit_one( fname);
-				g_free( fname);
-				if ( retval )
-					break;
-			}
-			++i;
-		}
-
-		// fear no shortcuts
-		ED.do_rescan_tree( true);
-
-		g_strfreev( uris);
-	}
-
-	gtk_drag_finish (context, TRUE, FALSE, time);
-}
-
-
-gboolean
-__attribute__ ((const))
-cMeasurements_drag_drop_cb( GtkWidget      *widget,
-			    GdkDragContext *context,
-			    gint            x,
-			    gint            y,
-			    guint           time,
-			    gpointer        userdata)
-{
-		//auto& ED = *(SExpDesignUI*)userdata;
-//	GdkAtom         target_type;
-//
-//      if ( context->targets ) {
-//              // Choose the best target type
-//              target_type = GDK_POINTER_TO_ATOM
-//                      (g_list_nth_data( context->targets, 0));
-//		unsigned i = g_list_length(context->targets);
-//		while ( i-- )
-//			printf( "%zu: %s\n", i, gdk_atom_name( GDK_POINTER_TO_ATOM (g_list_nth_data( context->targets, i))));
-//
-//		//Request the data from the source.
-//              gtk_drag_get_data(
-//                      widget,         // will receive 'drag-data-received' signal
-//                      context,        // represents the current state of the DnD
-//                      target_type,    // the target type we want
-//                      time);          // time stamp
-//
-//	} else { // No target offered by source => error
-//              return FALSE;
-//	}
-//
-		return  TRUE;
-}
-
-
-
-
-} // extern "C"
-
 // Local Variables:
 // Mode: c++
 // indent-tabs-mode: 8
diff --git a/src/aghermann/ui/mw/admit-one_cb.cc b/src/aghermann/ui/mw/admit-one_cb.cc
new file mode 100644
index 0000000..52e7f30
--- /dev/null
+++ b/src/aghermann/ui/mw/admit-one_cb.cc
@@ -0,0 +1,144 @@
+/*
+ *       File name:  aghermann/ui/mw/admit-one_cb.cc
+ *         Project:  Aghermann
+ *          Author:  Andrei Zavada <johnhommer at gmail.com>
+ * Initial version:  2013-08-11
+ *
+ *         Purpose:  SExpDesignUI edf import via dnd
+ *
+ *         License:  GPL
+ */
+
+
+#include "mw.hh"
+
+using namespace std;
+using namespace agh::ui;
+
+extern "C" {
+
+gboolean
+check_gtk_entry_nonempty_cb(
+	GtkEditable*,
+	const gpointer  userdata)
+{
+	auto& ED = *(SExpDesignUI*)userdata;
+
+	gtk_widget_set_sensitive( (GtkWidget*)ED.bEdfImportAdmit, TRUE);
+
+	const gchar *e;
+	gchar *ee;
+
+	ee = NULL;
+	e = gtk_entry_get_text( ED.eEdfImportGroupEntry);
+	if ( !e || !*g_strchug( g_strchomp( ee = g_strdup( e))) ) {
+		gtk_widget_set_sensitive( (GtkWidget*)ED.bEdfImportAdmit, FALSE);
+	}
+	g_free( ee);
+
+	ee = NULL;
+	e = gtk_entry_get_text( ED.eEdfImportSessionEntry);
+	if ( !e || !*g_strchug( g_strchomp( ee = g_strdup( e))) ) {
+		gtk_widget_set_sensitive( (GtkWidget*)ED.bEdfImportAdmit, FALSE);
+	}
+	g_free( ee);
+
+	ee = NULL;
+	e = gtk_entry_get_text( ED.eEdfImportEpisodeEntry);
+	if ( !e || !*g_strchug( g_strchomp( ee = g_strdup( e))) ) {
+		gtk_widget_set_sensitive( (GtkWidget*)ED.bEdfImportAdmit, FALSE);
+	}
+	g_free( ee);
+
+	gtk_widget_queue_draw( (GtkWidget*)ED.bEdfImportAdmit);
+
+	return false;
+}
+
+
+
+
+void
+cMeasurements_drag_data_received_cb(
+	const GtkWidget        *widget,
+	GdkDragContext         *context,
+	const gint              x,
+	const gint              y,
+	const GtkSelectionData *selection_data,
+	const guint             info,
+	const guint             time,
+	const gpointer          userdata)
+{
+	auto& ED = *(SExpDesignUI*)userdata;
+
+	gchar **uris = gtk_selection_data_get_uris( selection_data);
+	if ( uris != NULL ) {
+
+		guint i = 0;
+		while ( uris[i] ) {
+			if ( strncmp( uris[i], "file://", 7) == 0 ) {
+				char *fname = g_filename_from_uri( uris[i], NULL, NULL);
+				int retval = ED.dnd_maybe_admit_one( fname);
+				g_free( fname);
+				if ( retval )
+					break;
+			}
+			++i;
+		}
+
+		// fear no shortcuts
+		ED.do_rescan_tree( true);
+
+		g_strfreev( uris);
+	}
+
+	gtk_drag_finish (context, TRUE, FALSE, time);
+}
+
+
+gboolean
+__attribute__ ((const))
+cMeasurements_drag_drop_cb(
+	GtkWidget*,
+	GdkDragContext*,
+	gint x,
+	gint y,
+	guint time,
+	gpointer userdata)
+{
+		//auto& ED = *(SExpDesignUI*)userdata;
+//	GdkAtom         target_type;
+//
+//      if ( context->targets ) {
+//              // Choose the best target type
+//              target_type = GDK_POINTER_TO_ATOM
+//                      (g_list_nth_data( context->targets, 0));
+//		unsigned i = g_list_length(context->targets);
+//		while ( i-- )
+//			printf( "%zu: %s\n", i, gdk_atom_name( GDK_POINTER_TO_ATOM (g_list_nth_data( context->targets, i))));
+//
+//		//Request the data from the source.
+//              gtk_drag_get_data(
+//                      widget,         // will receive 'drag-data-received' signal
+//                      context,        // represents the current state of the DnD
+//                      target_type,    // the target type we want
+//                      time);          // time stamp
+//
+//	} else { // No target offered by source => error
+//              return FALSE;
+//	}
+//
+		return  TRUE;
+}
+
+
+
+} // extern "C"
+
+// Local Variables:
+// Mode: c++
+// indent-tabs-mode: 8
+// tab-width: 8
+// c-basic-offset: 8
+// End:
+
diff --git a/src/aghermann/ui/mw/construct.cc b/src/aghermann/ui/mw/construct.cc
index c118764..a933f5f 100644
--- a/src/aghermann/ui/mw/construct.cc
+++ b/src/aghermann/ui/mw/construct.cc
@@ -19,8 +19,7 @@ using namespace std;
 using namespace agh::ui;
 
 
-
-agh::ui::SExpDesignUIWidgets::
+SExpDesignUIWidgets::
 SExpDesignUIWidgets ()
 {
       // load glade
@@ -685,7 +684,7 @@ SExpDesignUIWidgets ()
 }
 
 
-agh::ui::SExpDesignUIWidgets::
+SExpDesignUIWidgets::
 ~SExpDesignUIWidgets ()
 {
 	g_object_unref( (GObject*)builder);
@@ -724,7 +723,7 @@ agh::ui::SExpDesignUIWidgets::
 
 
 void
-agh::ui::SExpDesignUIWidgets::
+SExpDesignUIWidgets::
 set_wMainWindow_interactive( const bool indeed, const bool flush)
 {
 	set_cursor_busy( not indeed, (GtkWidget*)wMainWindow);
@@ -749,7 +748,7 @@ set_wMainWindow_interactive( const bool indeed, const bool flush)
 }
 
 void
-agh::ui::SExpDesignUIWidgets::
+SExpDesignUIWidgets::
 set_controls_for_empty_experiment( bool indeed, const bool flush)
 {
 	indeed = not indeed;
diff --git a/src/aghermann/ui/mw/loadsave.cc b/src/aghermann/ui/mw/loadsave.cc
index 3ba67b9..43dee0e 100644
--- a/src/aghermann/ui/mw/loadsave.cc
+++ b/src/aghermann/ui/mw/loadsave.cc
@@ -23,7 +23,7 @@ using namespace agh::ui;
 
 namespace {
 
-forward_list<pair<const char*, agh::ui::SExpDesignUI::TColour>>
+forward_list<pair<const char*, SExpDesignUI::TColour>>
 saving_colors()
 {
 	using namespace agh::ui;
@@ -79,7 +79,7 @@ saving_colors()
 } // namespace
 
 int
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 load_settings()
 {
 	libconfig::Config conf;
@@ -152,7 +152,7 @@ load_settings()
 
 
 int
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 save_settings()
 {
 	libconfig::Config conf;
diff --git a/src/aghermann/ui/mw/mainmenu_cb.cc b/src/aghermann/ui/mw/mainmenu_cb.cc
index a2a8d38..5f6d111 100644
--- a/src/aghermann/ui/mw/mainmenu_cb.cc
+++ b/src/aghermann/ui/mw/mainmenu_cb.cc
@@ -395,10 +395,10 @@ bGlobalMontageResetAll_clicked_cb(
 
 	snprintf_buf( "find '%s' -name '.*.montage' -delete",
 		      ED.ED->session_dir().c_str());
-	if ( system( __buf__) )
+	if ( system( global::buf) )
 		pop_ok_message(
 			ED.wMainWindow,
-			"How strange!", "Command '%s' returned a non-zero status. This is weird.", __buf__);
+			"How strange!", "Command '%s' returned a non-zero status. This is weird.", global::buf);
 }
 
 
diff --git a/src/aghermann/ui/mw/measurements.cc b/src/aghermann/ui/mw/measurements.cc
index f6506b8..b754fba 100644
--- a/src/aghermann/ui/mw/measurements.cc
+++ b/src/aghermann/ui/mw/measurements.cc
@@ -21,9 +21,10 @@
 #include "mw.hh"
 
 using namespace std;
+using namespace agh::ui;
 
 bool
-agh::ui::SExpDesignUI::SSubjectPresentation::
+SExpDesignUI::SSubjectPresentation::
 get_episode_from_timeline_click( unsigned along)
 {
 	try {
@@ -42,7 +43,7 @@ get_episode_from_timeline_click( unsigned along)
 }
 
 void
-agh::ui::SExpDesignUI::SSubjectPresentation::
+SExpDesignUI::SSubjectPresentation::
 draw_timeline( const string& fname) const
 {
 	cairo_surface_t *cs =
@@ -58,13 +59,13 @@ draw_timeline( const string& fname) const
 
 
 void
-agh::ui::SExpDesignUI::SSubjectPresentation::
+SExpDesignUI::SSubjectPresentation::
 draw_timeline( cairo_t *cr) const
 {
 	bool have_episodes = cprofile && not cprofile->mm_list().empty();
 
 	if ( not have_episodes )
-		agh::ui::cairo_put_banner(
+		cairo_put_banner(
 			cr, 400, tl_height(), "(no episodes)", 24);
 
 	if ( have_episodes ) {
@@ -149,18 +150,19 @@ draw_timeline( cairo_t *cr) const
 
 			// episode start timestamp
 			time_t	dima = E.start_time();
-			strftime( __buf__, 79, "%F %T",
+			strftime( global::buf, 79, "%F %T",
 				  localtime( &dima));
-			g_string_printf( __ss__, "%s | %s",
-					 __buf__, E.name());
+			string ss = agh::str::sasprintf(
+				"%s | %s",
+				global::buf, E.name());
 			cairo_move_to( cr, tl_left_margin() + e_pixel_start + 2+1, 12+1);
 			cairo_set_source_rgb( cr, 0., 0., 0.);
-			cairo_show_text( cr, __ss__->str);
+			cairo_show_text( cr, ss.c_str());
 			cairo_stroke( cr);
 			// offset
 			cairo_move_to( cr, tl_left_margin() + e_pixel_start + 2, 12);
 			cairo_set_source_rgb( cr, 1., 1., 1.);
-			cairo_show_text( cr, __ss__->str);
+			cairo_show_text( cr, ss.c_str());
 			cairo_stroke( cr);
 
 			// highlight
@@ -261,9 +263,9 @@ draw_timeline( cairo_t *cr) const
 
 					snprintf_buf_ts_h( (clock_d - clock_d0 + 1) * 24 + clock_h);
 					cairo_text_extents_t extents;
-					cairo_text_extents( cr, __buf__, &extents);
+					cairo_text_extents( cr, global::buf, &extents);
 					cairo_move_to( cr, tl_left_margin() + x - extents.width/2, tl_height()-1);
-					cairo_show_text( cr, __buf__);
+					cairo_show_text( cr, global::buf);
 
 				} else {
 					cairo_move_to( cr, tl_left_margin() + x, tl_height() - 14);
@@ -293,14 +295,17 @@ draw_timeline( cairo_t *cr) const
 	cairo_select_font_face( cr, "sans", CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_NORMAL);
 	cairo_set_font_size( cr, 9);
 	cairo_set_source_rgb( cr, .1, .1, .1);
-	cairo_show_text( cr, snprintf_buf( "%c %d y.o.",
-					   csubject.gender_sign(),
-					   (int)csubject.age( *_p._p._AghDi)));
+	cairo_show_text(
+		cr,
+		snprintf_buf(
+			"%c %d y.o.",
+			csubject.gender_sign(),
+			(int)csubject.age( *_p._p._AghDi)));
 }
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 modify_active_profile_scale( const GdkScrollDirection d)
 {
 	auto fac = (d == GDK_SCROLL_DOWN) ? 1/scroll_factor : scroll_factor;
@@ -313,7 +318,7 @@ modify_active_profile_scale( const GdkScrollDirection d)
 }
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 modify_profile_scales( const GdkScrollDirection d)
 {
 	auto fac = (d == GDK_SCROLL_DOWN) ? 1/scroll_factor : scroll_factor;
diff --git a/src/aghermann/ui/mw/measurements_cb.cc b/src/aghermann/ui/mw/measurements_cb.cc
index 5396808..19dfbc6 100644
--- a/src/aghermann/ui/mw/measurements_cb.cc
+++ b/src/aghermann/ui/mw/measurements_cb.cc
@@ -1,5 +1,5 @@
 /*
- *       File name:  aghermann/ui/mw/mw-measurements_cb.cc
+ *       File name:  aghermann/ui/mw/measurements_cb.cc
  *         Project:  Aghermann
  *          Author:  Andrei Zavada <johnhommer at gmail.com>
  * Initial version:  2011-06-29
@@ -291,7 +291,7 @@ iSubjectTimelineResetMontage_activate_cb(
 
 	if ( system( exec.c_str()) )
 		pop_ok_message(
-			ED.wMainWindow, "Wow", "Command '%s' returned a non-zero status. This is weird.", __buf__);
+			ED.wMainWindow, "Wow", "Command '%s' returned a non-zero status. This is weird.", global::buf);
 }
 
 
diff --git a/src/aghermann/ui/mw/mw.cc b/src/aghermann/ui/mw/mw.cc
index be903ca..2f5e20d 100644
--- a/src/aghermann/ui/mw/mw.cc
+++ b/src/aghermann/ui/mw/mw.cc
@@ -30,9 +30,7 @@ using namespace std;
 using namespace agh::ui;
 
 
-
-
-agh::ui::SExpDesignUI::SSubjectPresentation::
+SExpDesignUI::SSubjectPresentation::
 SSubjectPresentation (agh::CSubject& _j,
 		      SGroupPresentation& parent)
       : csubject (_j),
@@ -47,7 +45,7 @@ SSubjectPresentation (agh::CSubject& _j,
 
 
 agh::SProfileParamSet
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 make_active_profile_paramset() const
 {
 	switch ( display_profile_type ) {
@@ -70,7 +68,7 @@ make_active_profile_paramset() const
 
 
 void
-agh::ui::SExpDesignUI::SSubjectPresentation::
+SExpDesignUI::SSubjectPresentation::
 create_cprofile()
 {
 	if ( cprofile )
@@ -89,7 +87,7 @@ create_cprofile()
 	}
 }
 
-agh::ui::SExpDesignUI::SSubjectPresentation::
+SExpDesignUI::SSubjectPresentation::
 ~SSubjectPresentation ()
 {
 	if ( cprofile )
@@ -100,7 +98,7 @@ agh::ui::SExpDesignUI::SSubjectPresentation::
 
 
 
-agh::ui::SExpDesignUI::SSubjectPresentation*
+SExpDesignUI::SSubjectPresentation*
 __attribute__ ((pure))
 SExpDesignUI::
 subject_presentation_by_csubject( const agh::CSubject& j)
@@ -115,16 +113,16 @@ subject_presentation_by_csubject( const agh::CSubject& j)
 
 
 const array<unsigned, 4>
-	agh::ui::SExpDesignUI::FFTPageSizeValues = {{4, 20, 30, 60}};
+	SExpDesignUI::FFTPageSizeValues = {{4, 20, 30, 60}};
 const array<double, 3>
-	agh::ui::SExpDesignUI::FFTBinSizeValues = {{.1, .25, .5}};
+	SExpDesignUI::FFTBinSizeValues = {{.1, .25, .5}};
 
-double agh::ui::SExpDesignUI::scroll_factor = 1.05;
+double SExpDesignUI::scroll_factor = 1.05;
 
 using agh::confval::SValidator;
 
-agh::ui::SExpDesignUI::
-SExpDesignUI (agh::ui::SSessionChooser *parent,
+SExpDesignUI::
+SExpDesignUI (SSessionChooser *parent,
 	      const string& dir)
       : // let ED and cgroups be initialized after the UI gets constructed
 	// so we could entertain the user with progress_indicator
@@ -219,7 +217,7 @@ SExpDesignUI (agh::ui::SSessionChooser *parent,
 	ED = new agh::CExpDesign (sure_dir,
 				  bind( &SExpDesignUI::sb_main_progress_indicator, this,
 					placeholders::_1, placeholders::_2, placeholders::_3,
-					agh::ui::TGtkRefreshMode::gtk));
+					ui::TGtkRefreshMode::gtk));
 	load_artifact_detection_profiles();
 	if ( global_artifact_detection_profiles.empty() )
 		global_artifact_detection_profiles["default"] = metrics::mc::SArtifactDetectionPP ();
@@ -316,7 +314,7 @@ SExpDesignUI (agh::ui::SSessionChooser *parent,
 }
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 load_artifact_detection_profiles()
 {
 	FILE *domien = fopen( (ED->session_dir() + "/.AD_profiles").c_str(), "r");
@@ -356,7 +354,7 @@ load_artifact_detection_profiles()
 }
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 save_artifact_detection_profiles() const
 {
 	// libconfig::Config conf;
@@ -390,7 +388,7 @@ save_artifact_detection_profiles() const
 
 size_t
 __attribute__ ((pure))
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 figure_pagesize_item()
 {
 	size_t i = 0;
@@ -400,7 +398,7 @@ figure_pagesize_item()
 }
 size_t
 __attribute__ ((pure))
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 figure_binsize_item()
 {
 	size_t i = 0;
@@ -411,7 +409,7 @@ figure_binsize_item()
 
 
 
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 ~SExpDesignUI ()
 {
 	if ( dl_pid > 0 )
@@ -433,17 +431,17 @@ agh::ui::SExpDesignUI::
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 do_rescan_tree( const bool with_update)
 {
-	agh::ui::SBusyBlock bb (wMainWindow);
+	ui::SBusyBlock bb (wMainWindow);
 
 	depopulate( false);
 	ED -> sync();
 	if ( with_update )
 		ED -> scan_tree( bind (&SExpDesignUI::sb_main_progress_indicator, this,
 				       placeholders::_1, placeholders::_2, placeholders::_3,
-				       agh::ui::TGtkRefreshMode::gdk));
+				       ui::TGtkRefreshMode::gdk));
 	else
 		ED -> scan_tree();
 	populate( false);
@@ -451,13 +449,13 @@ do_rescan_tree( const bool with_update)
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 do_purge_computed()
 {
-	agh::ui::SBusyBlock bb (wMainWindow);
+	SBusyBlock bb (wMainWindow);
 
 	if ( ED->purge_cached_profiles() ) {
-		fprintf( stderr, "Command '%s' returned a non-zero status. This is suspicious.\n", __buf__);
+		fprintf( stderr, "Command '%s' returned a non-zero status. This is suspicious.\n", ui::global::buf);
 		sb_message( "Failed to purge cache files. This is odd.");
 	}
 
@@ -466,7 +464,7 @@ do_purge_computed()
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 do_detect_ultradian_cycle( agh::CRecording& M)
 {
 	gsl_siman_params_t siman_params;
@@ -492,7 +490,7 @@ do_detect_ultradian_cycle( agh::CRecording& M)
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 adjust_op_freq_spinbuttons()
 {
 	suppress_redraw = true;
@@ -516,7 +514,7 @@ adjust_op_freq_spinbuttons()
 
 
 double
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 calculate_profile_scale()
 {
 	double	avg_profile_height = 0.;
@@ -555,7 +553,7 @@ calculate_profile_scale()
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 show_changelog()
 {
 	gtk_widget_show_all( (GtkWidget*)wAbout);
@@ -567,7 +565,7 @@ show_changelog()
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 sb_message( const string& msg) const
 {
 	gtk_statusbar_pop( sbMainStatusBar, sbMainContextIdGeneral);
@@ -575,7 +573,7 @@ sb_message( const string& msg) const
 }
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 sb_clear() const
 {
 	gtk_statusbar_pop( sbMainStatusBar, sbMainContextIdGeneral);
@@ -584,16 +582,16 @@ sb_clear() const
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 sb_main_progress_indicator( const string& current,
 			    const size_t n, const size_t i,
-			    const agh::ui::TGtkRefreshMode mode)
+			    const TGtkRefreshMode mode)
 {
 	sb_message( agh::str::sasprintf( "(%zu of %zu) %s", i, n, current.c_str()));
 
 	switch ( mode ) {
 	case TGtkRefreshMode::gtk:
-		agh::ui::gtk_flush();  // this brings down the whole of GTK if called from a callback
+		gtk_flush();  // this brings down the whole of GTK if called from a callback
 		break;
 	case TGtkRefreshMode::gdk:
 		gdk_window_process_all_updates(); // this, however, fails to do the update if called *not* from a callback
diff --git a/src/aghermann/ui/mw/populate.cc b/src/aghermann/ui/mw/populate.cc
index 8f77063..3045c13 100644
--- a/src/aghermann/ui/mw/populate.cc
+++ b/src/aghermann/ui/mw/populate.cc
@@ -11,6 +11,7 @@
 
 
 #include <cstring>
+#include <sstream>
 
 #include "aghermann/expdesign/primaries.hh"
 #include "aghermann/model/beersma.hh"
@@ -23,7 +24,7 @@ using namespace agh::ui;
 
 
 int
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 populate( bool do_load)
 {
 	printf( "\nSExpDesignUI::populate():\n");
@@ -84,7 +85,7 @@ populate( bool do_load)
 		snprintf_buf( "Smooth: %zu", smooth_profile));
 
 	if ( AghTT.empty() )
-		agh::ui::pop_ok_message(
+		pop_ok_message(
 			wMainWindow,
 			"No EEG channels",
 			"There are no EEG channels found in any recordings in the tree.");
@@ -174,7 +175,7 @@ populate( bool do_load)
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 depopulate( bool do_save)
 {
 	if ( do_save )
@@ -209,7 +210,7 @@ depopulate( bool do_save)
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 populate_mSessions()
 {
 	g_signal_handler_block( eMsmtSession, eMsmtSession_changed_cb_handler_id);
@@ -231,7 +232,7 @@ populate_mSessions()
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 populate_mChannels()
 {
 	g_signal_handler_block( eMsmtChannel, eMsmtChannel_changed_cb_handler_id);
@@ -264,7 +265,7 @@ populate_mChannels()
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 __reconnect_channels_combo()
 {
 	gtk_combo_box_set_model( eMsmtChannel, (GtkTreeModel*)mEEGChannels);
@@ -280,7 +281,7 @@ __reconnect_channels_combo()
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 __reconnect_sessions_combo()
 {
 	gtk_combo_box_set_model( eMsmtSession, (GtkTreeModel*)mSessions);
@@ -305,7 +306,7 @@ annotation_type_s( const sigfile::SAnnotation::TType t)
 }
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 populate_mGlobalAnnotations()
 {
 	gtk_tree_store_clear( mGlobalAnnotations);
@@ -368,7 +369,7 @@ populate_mGlobalAnnotations()
 									snprintf_buf( "%u-%u", pages.a + 1, pages.z + 1);
 								gtk_tree_store_append( mGlobalAnnotations, &iter_a, &iter_e);
 								gtk_tree_store_set( mGlobalAnnotations, &iter_a,
-										    1, __buf__,
+										    1, global::buf,
 										    2, A.channel(),
 										    3, annotation_type_s(A.type),
 										    4, A.label.c_str(),
@@ -387,7 +388,7 @@ populate_mGlobalAnnotations()
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 populate_mGlobalADProfiles()
 {
 	gtk_list_store_clear( mGlobalADProfiles);
@@ -404,7 +405,7 @@ populate_mGlobalADProfiles()
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 populate_1()
 {
 	if ( ED->groups.empty() )
@@ -469,7 +470,7 @@ populate_1()
       // walk again thoroughly, set timeline drawing area length
 	for ( auto &G : groups ) {
 	      // convert avg episode times
-		g_string_assign( __ss__, "");
+		ostringstream ss;
 		for ( auto &E : AghEE ) {
 			pair<float, float>& avge = G.cjgroup().avg_episode_times[*_AghDi][E];
 			unsigned seconds, h0, m0, s0, h9, m9, s9;
@@ -482,18 +483,20 @@ populate_1()
 			m9  = seconds % 3600 / 60;
 			s9  = seconds % 60;
 
-			g_string_append_printf( __ss__,
-						"       <i>%s</i> %02d:%02d:%02d ~ %02d:%02d:%02d",
-						E.c_str(),
-						h0 % 24, m0, s0,
-						h9 % 24, m9, s9);
+			ss << agh::str::sasprintf(
+				"       <i>%s</i> %02d:%02d:%02d ~ %02d:%02d:%02d",
+				E.c_str(),
+				h0 % 24, m0, s0,
+				h9 % 24, m9, s9);
 		}
 
-		gchar *g_escaped = g_markup_escape_text( G.name(), -1);
-		snprintf_buf( "<b>%s</b> (%zu) %s", g_escaped, G.size(), __ss__->str);
-		g_free( g_escaped);
+		{
+			gchar *g_escaped = g_markup_escape_text( G.name(), -1);
+			snprintf_buf( "<b>%s</b> (%zu) %s", g_escaped, G.size(), ss.str().c_str());
+			g_free( g_escaped);
+		}
 
-		GtkExpander *expander = (GtkExpander*)gtk_expander_new( __buf__);
+		GtkExpander *expander = (GtkExpander*)gtk_expander_new( global::buf);
 		gtk_expander_set_use_markup( expander, TRUE);
 		g_object_set( (GObject*)expander,
 			      "visible", TRUE,
@@ -600,7 +603,7 @@ populate_1()
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 sort_subjects()
 {
 	for ( auto Gi = groups.begin(); Gi != groups.end(); ++Gi )
@@ -609,7 +612,7 @@ sort_subjects()
 
 
 bool
-agh::ui::SExpDesignUI::SSubjectPresentation::
+SExpDesignUI::SSubjectPresentation::
 operator<( const SSubjectPresentation& rv) const
 {
 	if ( _p._p.sort_segregate and csubject.gender != rv.csubject.gender )
diff --git a/src/aghermann/ui/mw/simulations.cc b/src/aghermann/ui/mw/simulations.cc
index 65b628e..fd24b03 100644
--- a/src/aghermann/ui/mw/simulations.cc
+++ b/src/aghermann/ui/mw/simulations.cc
@@ -13,10 +13,11 @@
 #include "mw.hh"
 
 using namespace std;
+using namespace agh::ui;
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 populate_2()
 {
 	gtk_tree_store_clear( mSimulations);
@@ -67,7 +68,7 @@ populate_2()
 					// status (put CF here)
 					snprintf_buf( "CF = %g", M.cf);
 					gtk_tree_store_set( mSimulations, &iter_h,
-							    1, __buf__,
+							    1, global::buf,
 							    msimulations_modref_col, &M,
 							    -1);
 
@@ -78,7 +79,7 @@ populate_2()
 						snprintf_buf( td.fmt,
 							      M.tx[t] * td.display_scale_factor);
 						gtk_tree_store_set( mSimulations, &iter_h,
-								    2+t, __buf__, -1);
+								    2+t, global::buf, -1);
 					}
 				}
 			}
@@ -121,13 +122,14 @@ populate_2()
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 cleanup_2()
 {
 	ED->remove_untried_modruns();
 	//populate( false);
 }
 
+
 // Local Variables:
 // Mode: c++
 // indent-tabs-mode: 8
diff --git a/src/aghermann/ui/mw/simulations_cb.cc b/src/aghermann/ui/mw/simulations_cb.cc
index 5613976..4ae7496 100644
--- a/src/aghermann/ui/mw/simulations_cb.cc
+++ b/src/aghermann/ui/mw/simulations_cb.cc
@@ -141,9 +141,10 @@ iSimulationsRunBatch_activate_cb(
 			       size_t i, size_t n)
 			{
 				ED.sb_message(
-					snprintf_buf( "(%zu of %zu) Running simulation in channel %s (%s) for %s (session %s) ...",
-						      i, n, H.c_str(), T.display_name().c_str(),
-						      J.id.c_str(), D.c_str()));
+					snprintf_buf(
+						"(%zu of %zu) Running simulation in channel %s (%s) for %s (session %s) ...",
+						i, n, H.c_str(), T.display_name().c_str(),
+						J.id.c_str(), D.c_str()));
 				gtk_flush();
 			};
 		CExpDesign::TModelRunFilterFun filter =
@@ -188,10 +189,10 @@ iSimulationsReportGenerate_activate_cb(
 			GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
 			NULL);
 	if ( gtk_dialog_run( f_chooser) == GTK_RESPONSE_ACCEPT ) {
-		g_string_assign( __ss__, gtk_file_chooser_get_filename( (GtkFileChooser*)f_chooser));
-		if ( !g_str_has_suffix( __ss__->str, ".tsv") && !g_str_has_suffix( __ss__->str, ".TSV") )
-			g_string_append_printf( __ss__, ".tsv");
-		ED.ED->export_all_modruns( {__ss__->str});
+		string selected = gtk_file_chooser_get_filename( (GtkFileChooser*)f_chooser);
+		if ( not agh::str::has_suffix( selected, ".tsv", agh::str::TStrCmpCaseOption::insensitive) )
+			selected += ".tsv";
+		ED.ED->export_all_modruns( selected);
 	}
 	gtk_widget_destroy( (GtkWidget*)f_chooser);
 }
diff --git a/src/aghermann/ui/mw/splash.cc b/src/aghermann/ui/mw/splash.cc
index 8be2c9a..c93dff0 100644
--- a/src/aghermann/ui/mw/splash.cc
+++ b/src/aghermann/ui/mw/splash.cc
@@ -18,8 +18,7 @@
 #include "mw.hh"
 
 using namespace std;
-
-
+using namespace agh::ui;
 
 
 namespace {
@@ -30,7 +29,7 @@ bDownload_clicked_cb(
 	GtkButton*,
 	const gpointer userdata)
 {
-	auto& ED = *(agh::ui::SExpDesignUI*)userdata;
+	auto& ED = *(SExpDesignUI*)userdata;
 	ED.try_download();
 }
 
@@ -39,18 +38,18 @@ download_process_child_exited_cb(
 	VteTerminal *terminal,
 	const gpointer userdata)
 {
-	auto& ED = *(agh::ui::SExpDesignUI*)userdata;
+	auto& ED = *(SExpDesignUI*)userdata;
 	ED.set_wMainWindow_interactive( true, true);
 	int exit_status = vte_terminal_get_child_exit_status( terminal);
 	if ( exit_status != 0 )
-		agh::ui::pop_ok_message(
+		pop_ok_message(
 			ED.wMainWindow,
 			"Download failed",
 			"Exit status %d. Try again next time.", exit_status);
 	ED.dl_pid = -1;
-	ED.ED->scan_tree( bind (&agh::ui::SExpDesignUI::sb_main_progress_indicator, &ED,
+	ED.ED->scan_tree( bind (&SExpDesignUI::sb_main_progress_indicator, &ED,
 				placeholders::_1, placeholders::_2, placeholders::_3,
-				agh::ui::TGtkRefreshMode::gdk));
+				TGtkRefreshMode::gdk));
 	ED.populate( false);
 }
 
@@ -61,7 +60,7 @@ download_process_child_exited_cb(
 
 
 void
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 show_empty_experiment_blurb()
 {
 	gtk_container_foreach( (GtkContainer*)cMeasurements,
@@ -111,7 +110,7 @@ show_empty_experiment_blurb()
 
 
 int
-agh::ui::SExpDesignUI::
+SExpDesignUI::
 try_download()
 {
 	gtk_container_foreach( (GtkContainer*)cMeasurements,
@@ -148,7 +147,7 @@ try_download()
 		&dl_pid,
 		&Error); // GError **error);
 	if ( Error ) {
-		agh::ui::pop_ok_message(
+		pop_ok_message(
 			wMainWindow,
 			"Error",
 			"%s\n", Error->message);
diff --git a/src/aghermann/ui/mw/widgets.hh b/src/aghermann/ui/mw/widgets.hh
index 30bd4a0..70386c3 100644
--- a/src/aghermann/ui/mw/widgets.hh
+++ b/src/aghermann/ui/mw/widgets.hh
@@ -17,7 +17,7 @@
 #include "libsigfile/page.hh" // for various enums
 #include "libmetrics/bands.hh"
 #include "aghermann/model/achermann-tunable.hh"
-#include "aghermann/ui/ui.hh"  // for SManagedColor
+#include "aghermann/ui/ui++.hh"  // for SManagedColor
 
 #if HAVE_CONFIG_H && !defined(VERSION)
 #  include "config.h"
diff --git a/src/aghermann/ui/sf/channel.cc b/src/aghermann/ui/sf/channel.cc
index abe79cf..ff1160a 100644
--- a/src/aghermann/ui/sf/channel.cc
+++ b/src/aghermann/ui/sf/channel.cc
@@ -23,14 +23,15 @@
 #include "d/patterns.hh"
 
 using namespace std;
+using namespace agh::ui;
 
 pattern::SPatternPPack<TFloat>
-	agh::ui::SScoringFacility::SChannel::pattern_params =
+	SScoringFacility::SChannel::pattern_params =
 		{.25,  0., 1.5, 1,  .1, .5, 3};
 
 using agh::confval::SValidator;
 
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 SChannel (agh::CRecording& r,
 	  SScoringFacility& parent,
 	  size_t y0,
@@ -161,7 +162,7 @@ SChannel (agh::CRecording& r,
 
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 get_signal_original()
 {
 	signal_original =
@@ -175,7 +176,7 @@ get_signal_original()
 }
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 get_signal_filtered()
 {
 	signal_filtered =
@@ -190,7 +191,7 @@ get_signal_filtered()
 
 
 list<sigfile::SAnnotation*>
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 in_annotations( const double time) const
 {
 	// select this channel's annotations
@@ -206,7 +207,7 @@ in_annotations( const double time) const
 
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 get_psd_course()
 {
 	//psd_profile.compute();
@@ -222,7 +223,7 @@ get_psd_course()
 }
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 get_psd_in_bands()
 {
 	crecording.psd_profile.compute();
@@ -251,7 +252,7 @@ get_psd_in_bands()
 
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 get_swu_course()
 {
 	//swu_profile.compute();
@@ -268,7 +269,7 @@ get_swu_course()
 
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 get_mc_course()
 {
 	//mc_profile.compute();
@@ -286,7 +287,7 @@ get_mc_course()
 
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 get_raw_profile()
 {
 	raw_profile = sigproc::raw_signal_profile<TFloat>(
@@ -296,7 +297,7 @@ get_raw_profile()
 
 
 tuple<metrics::TType, valarray<TFloat>&>
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 which_profile( const metrics::TType metric)
 {
 	switch ( schannel().type() ) {
@@ -322,13 +323,13 @@ which_profile( const metrics::TType metric)
 
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 get_spectrum( const size_t p)
 {
 	spectrum = crecording.psd_profile.spectrum( p);
 }
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 get_spectrum()
 {
 	spectrum = crecording.psd_profile.spectrum( _p.cur_page());
@@ -340,7 +341,7 @@ get_spectrum()
 
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 update_profile_display_scales()
 {
 	psd.display_scale =
@@ -365,7 +366,7 @@ update_profile_display_scales()
 
 
 float
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 calculate_dirty_percent()
 {
 	size_t total = 0; // in samples
@@ -378,7 +379,7 @@ calculate_dirty_percent()
 
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 detect_artifacts( const metrics::mc::SArtifactDetectionPP& P)
 {
 	auto marked =
@@ -405,7 +406,7 @@ detect_artifacts( const metrics::mc::SArtifactDetectionPP& P)
 
 
 pair<double, double>
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 mark_flat_regions_as_artifacts( const double minsize, const double pad)
 {
 	double	total_before = artifacts.total();
@@ -451,7 +452,7 @@ mark_flat_regions_as_artifacts( const double minsize, const double pad)
 
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 mark_region_as_artifact( const bool do_mark)
 {
 	if ( do_mark )
@@ -480,7 +481,7 @@ mark_region_as_artifact( const bool do_mark)
 }
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 mark_region_as_annotation( const string& label,
 			   const sigfile::SAnnotation::TType type)
 {
@@ -493,7 +494,7 @@ mark_region_as_annotation( const string& label,
 
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 mark_region_as_pattern()
 {
 	if ( _p.patterns_d().import_from_selection( *this) == 0 )
@@ -503,7 +504,7 @@ mark_region_as_pattern()
 
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 update_channel_menu_items( const double x)
 {
 	_p.suppress_redraw = true;
@@ -560,7 +561,7 @@ update_channel_menu_items( const double x)
 }
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 update_power_menu_items()
 {
 	_p.suppress_redraw = true;
@@ -578,7 +579,7 @@ update_power_menu_items()
 
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 selectively_enable_selection_menu_items()
 {
 	bool findable =
@@ -588,7 +589,7 @@ selectively_enable_selection_menu_items()
 
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 put_selection( const size_t a, const size_t e)
 {
 	selection_start = a, selection_end = e;
@@ -598,7 +599,7 @@ put_selection( const size_t a, const size_t e)
 }
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 put_selection( const double a, const double e)
 {
 	selection_start_time = a, selection_end_time = e;
@@ -608,7 +609,7 @@ put_selection( const double a, const double e)
 }
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 _put_selection()
 {
 	if ( selection_end_time - selection_start_time > 1. ) {
diff --git a/src/aghermann/ui/sf/construct.cc b/src/aghermann/ui/sf/construct.cc
index 82b57cb..010d4ae 100644
--- a/src/aghermann/ui/sf/construct.cc
+++ b/src/aghermann/ui/sf/construct.cc
@@ -17,9 +17,9 @@
 #include "sf_cb.hh"
 
 using namespace std;
+using namespace agh::ui;
 
-
-agh::ui::SScoringFacilityWidgets::
+SScoringFacilityWidgets::
 SScoringFacilityWidgets ()
 {
 	builder = gtk_builder_new();
@@ -354,7 +354,7 @@ SScoringFacilityWidgets ()
 
 
 
-agh::ui::SScoringFacilityWidgets::
+SScoringFacilityWidgets::
 ~SScoringFacilityWidgets ()
 {
 	// destroy toplevels
diff --git a/src/aghermann/ui/sf/d/artifacts-construct.cc b/src/aghermann/ui/sf/d/artifacts-construct.cc
index a3c26c2..4e57cad 100644
--- a/src/aghermann/ui/sf/d/artifacts-construct.cc
+++ b/src/aghermann/ui/sf/d/artifacts-construct.cc
@@ -16,9 +16,9 @@
 #include "artifacts.hh"
 
 using namespace std;
+using namespace agh::ui;
 
-
-agh::ui::SArtifactsDialogWidgets::
+SArtifactsDialogWidgets::
 SArtifactsDialogWidgets ()
 {
 	builder = gtk_builder_new();
@@ -78,7 +78,7 @@ SArtifactsDialogWidgets ()
 }
 
 
-agh::ui::SArtifactsDialogWidgets::
+SArtifactsDialogWidgets::
 ~SArtifactsDialogWidgets ()
 {
 	gtk_widget_destroy( (GtkWidget*)wSFAD);
diff --git a/src/aghermann/ui/sf/d/artifacts-simple-construct.cc b/src/aghermann/ui/sf/d/artifacts-simple-construct.cc
index 6c420db..e9d2d4d 100644
--- a/src/aghermann/ui/sf/d/artifacts-simple-construct.cc
+++ b/src/aghermann/ui/sf/d/artifacts-simple-construct.cc
@@ -16,9 +16,9 @@
 #include "artifacts-simple.hh"
 
 using namespace std;
+using namespace agh::ui;
 
-
-agh::ui::SArtifactsSimpleDialogWidgets::
+SArtifactsSimpleDialogWidgets::
 SArtifactsSimpleDialogWidgets ()
 {
 	builder = gtk_builder_new();
@@ -33,7 +33,7 @@ SArtifactsSimpleDialogWidgets ()
 }
 
 
-agh::ui::SArtifactsSimpleDialogWidgets::
+SArtifactsSimpleDialogWidgets::
 ~SArtifactsSimpleDialogWidgets ()
 {
 	gtk_widget_destroy( (GtkWidget*)wSFADS);
diff --git a/src/aghermann/ui/sf/d/artifacts-simple.cc b/src/aghermann/ui/sf/d/artifacts-simple.cc
index be65353..77727f1 100644
--- a/src/aghermann/ui/sf/d/artifacts-simple.cc
+++ b/src/aghermann/ui/sf/d/artifacts-simple.cc
@@ -12,9 +12,10 @@
 #include "artifacts-simple.hh"
 
 using namespace std;
+using namespace agh::ui;
 
-agh::ui::SScoringFacility::SArtifactsSimpleDialog&
-agh::ui::SScoringFacility::
+SScoringFacility::SArtifactsSimpleDialog&
+SScoringFacility::
 artifacts_simple_d()
 {
 	if ( not _artifacts_simple_d )
@@ -23,8 +24,8 @@ artifacts_simple_d()
 }
 
 
-agh::ui::SScoringFacility::SArtifactsSimpleDialog::
-SArtifactsSimpleDialog (agh::ui::SScoringFacility& p_)
+SScoringFacility::SArtifactsSimpleDialog::
+SArtifactsSimpleDialog (SScoringFacility& p_)
       : min_size (0.5),
 	pad (),
 	_p (p_)
diff --git a/src/aghermann/ui/sf/d/artifacts.cc b/src/aghermann/ui/sf/d/artifacts.cc
index b36200b..a2fb5fb 100644
--- a/src/aghermann/ui/sf/d/artifacts.cc
+++ b/src/aghermann/ui/sf/d/artifacts.cc
@@ -12,9 +12,10 @@
 #include "artifacts.hh"
 
 using namespace std;
+using namespace agh::ui;
 
-agh::ui::SScoringFacility::SArtifactsDialog&
-agh::ui::SScoringFacility::
+SScoringFacility::SArtifactsDialog&
+SScoringFacility::
 artifacts_d()
 {
 	if ( not _artifacts_d )
@@ -23,8 +24,8 @@ artifacts_d()
 }
 
 
-agh::ui::SScoringFacility::SArtifactsDialog::
-SArtifactsDialog (agh::ui::SScoringFacility& p_)
+SScoringFacility::SArtifactsDialog::
+SArtifactsDialog (SScoringFacility& p_)
       : using_channel (nullptr),
 	_p (p_)
 {
@@ -52,7 +53,7 @@ SArtifactsDialog (agh::ui::SScoringFacility& p_)
 
 // maybe it's not needed in GTK+ 3?
 void
-agh::ui::SScoringFacility::SArtifactsDialog::
+SScoringFacility::SArtifactsDialog::
 populate_mSFADProfiles()
 {
 	g_signal_handler_block( eSFADProfiles, eSFADProfiles_changed_cb_handler_id);
diff --git a/src/aghermann/ui/sf/d/filters-construct.cc b/src/aghermann/ui/sf/d/filters-construct.cc
index 19c434b..d434f30 100644
--- a/src/aghermann/ui/sf/d/filters-construct.cc
+++ b/src/aghermann/ui/sf/d/filters-construct.cc
@@ -16,8 +16,10 @@
 #include "filters.hh"
 
 using namespace std;
+using namespace agh::ui;
 
-agh::ui::SFiltersDialogWidgets::
+
+SFiltersDialogWidgets::
 SFiltersDialogWidgets ()
 {
 	builder = gtk_builder_new();
@@ -43,7 +45,7 @@ SFiltersDialogWidgets ()
 	G_CONNECT_2 (eSFFilterLowPassCutoff, value, changed);
 }
 
-agh::ui::SFiltersDialogWidgets::
+SFiltersDialogWidgets::
 ~SFiltersDialogWidgets ()
 {
 	// destroy toplevels
diff --git a/src/aghermann/ui/sf/d/filters.cc b/src/aghermann/ui/sf/d/filters.cc
index 016b3c4..f809230 100644
--- a/src/aghermann/ui/sf/d/filters.cc
+++ b/src/aghermann/ui/sf/d/filters.cc
@@ -13,10 +13,10 @@
 #include "filters.hh"
 
 using namespace std;
+using namespace agh::ui;
 
-
-agh::ui::SScoringFacility::SFiltersDialog&
-agh::ui::SScoringFacility::
+SScoringFacility::SFiltersDialog&
+SScoringFacility::
 filters_d()
 {
 	if ( not _filters_d )
@@ -24,7 +24,7 @@ filters_d()
 	return *_filters_d;
 }
 
-agh::ui::SScoringFacility::SFiltersDialog::
+SScoringFacility::SFiltersDialog::
 SFiltersDialog (SScoringFacility& p_)
       : _p (p_)
 {
diff --git a/src/aghermann/ui/sf/d/patterns-construct.cc b/src/aghermann/ui/sf/d/patterns-construct.cc
index f061463..40a7ed8 100644
--- a/src/aghermann/ui/sf/d/patterns-construct.cc
+++ b/src/aghermann/ui/sf/d/patterns-construct.cc
@@ -14,8 +14,9 @@
 #include "patterns.hh"
 
 using namespace std;
+using namespace agh::ui;
 
-agh::ui::SPatternsDialogWidgets::
+SPatternsDialogWidgets::
 SPatternsDialogWidgets (SScoringFacility& SF)
 {
 	builder = gtk_builder_new();
@@ -141,7 +142,7 @@ SPatternsDialogWidgets (SScoringFacility& SF)
 	G_CONNECT_1 (wSFFD, hide);
 }
 
-agh::ui::SPatternsDialogWidgets::
+SPatternsDialogWidgets::
 ~SPatternsDialogWidgets ()
 {
 	// destroy toplevels
diff --git a/src/aghermann/ui/sf/d/patterns-draw.cc b/src/aghermann/ui/sf/d/patterns-draw.cc
index 713f6aa..36d33c3 100644
--- a/src/aghermann/ui/sf/d/patterns-draw.cc
+++ b/src/aghermann/ui/sf/d/patterns-draw.cc
@@ -14,10 +14,11 @@
 #include "patterns.hh"
 
 using namespace std;
+using namespace agh::ui;
 
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 set_thing_da_width( const int width)
 {
 	static int scrollbar_width = 15;
@@ -28,7 +29,7 @@ set_thing_da_width( const int width)
 }
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 set_field_da_width( const int width)
 {
 	static int scrollbar_width = 15;
@@ -41,11 +42,11 @@ set_field_da_width( const int width)
 
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 draw_thing( cairo_t *cr)
 {
 	if ( current_pattern == patterns.end() ) {
-		agh::ui::cairo_put_banner( cr, da_thing_wd, da_thing_ht, "(make a selection)");
+		cairo_put_banner( cr, da_thing_wd, da_thing_ht, "(make a selection)");
 		return;
 	}
 
@@ -75,9 +76,9 @@ draw_thing( cairo_t *cr)
 	int	zeroline = da_thing_ht/2;
 	cairo_set_source_rgb( cr, 0., 0., 0.);
 	cairo_set_line_width( cr, .8);
-	agh::ui::cairo_draw_signal( cr, current_pattern->thing, 0, current_pattern->thing.size(),
-				  da_thing_wd, 0, zeroline,
-				  thing_display_scale);
+	cairo_draw_signal( cr, current_pattern->thing, 0, current_pattern->thing.size(),
+			   da_thing_wd, 0, zeroline,
+			   thing_display_scale);
 	cairo_stroke( cr);
 
 	// lines marking out context
@@ -96,19 +97,22 @@ draw_thing( cairo_t *cr)
 			dzcdf;
 	      // envelope
 		{
-			if ( sigproc::envelope( {current_pattern->thing, current_pattern->samplerate}, Pp2.env_scope,
-						1./current_pattern->samplerate,
-						&env_l, &env_u) == 0 ) {
-				agh::ui::cairo_put_banner( cr, da_thing_wd, da_thing_ht, "Pattern is too short for this envelope scope");
+			if ( 0 == sigproc::envelope(
+				     {current_pattern->thing, current_pattern->samplerate}, Pp2.env_scope,
+				     1./current_pattern->samplerate,
+				     &env_l, &env_u) ) {
+				cairo_put_banner( cr, da_thing_wd, da_thing_ht, "Pattern is too short for this envelope scope");
 				goto out;
 			}
 
 			_p._p.CwB[SExpDesignUI::TColour::sf_selection].set_source_rgba_contrasting( cr, .3);
-			agh::ui::cairo_draw_signal( cr, env_u, 0, env_u.size(),
-						  da_thing_wd, 0, zeroline, thing_display_scale);
-			agh::ui::cairo_draw_signal( cr, env_l, 0, env_l.size(),
-						  da_thing_wd, 0, zeroline, thing_display_scale,
-						  1, agh::ui::TDrawSignalDirection::backward);
+			cairo_draw_signal(
+				cr, env_u, 0, env_u.size(),
+				da_thing_wd, 0, zeroline, thing_display_scale);
+			cairo_draw_signal(
+				cr, env_l, 0, env_l.size(),
+				da_thing_wd, 0, zeroline, thing_display_scale,
+				1, TDrawSignalDirection::backward);
 			cairo_close_path( cr);
 			cairo_fill( cr);
 			cairo_stroke( cr);
@@ -116,7 +120,7 @@ draw_thing( cairo_t *cr)
 	      // target frequency
 		{
 			if ( Pp2.bwf_ffrom >= Pp2.bwf_fupto ) {
-				agh::ui::cairo_put_banner( cr, da_thing_wd, da_thing_ht, "Bad band-pass range");
+				cairo_put_banner( cr, da_thing_wd, da_thing_ht, "Bad band-pass range");
 				goto out;
 			}
 			target_freq = exstrom::band_pass(
@@ -125,19 +129,20 @@ draw_thing( cairo_t *cr)
 
 			cairo_set_source_rgba( cr, 0.3, 0.3, 0.3, .5);
 			cairo_set_line_width( cr, 3.);
-			agh::ui::cairo_draw_signal( cr, target_freq, 0, target_freq.size(),
-						  da_thing_wd, 0, zeroline, thing_display_scale);
+			cairo_draw_signal(
+				cr, target_freq, 0, target_freq.size(),
+				da_thing_wd, 0, zeroline, thing_display_scale);
 			cairo_stroke( cr);
 		}
 
 	      // dzcdf
 		{
 			if ( current_pattern->samplerate < 10 ) {
-				agh::ui::cairo_put_banner( cr, da_thing_wd, da_thing_ht, "Samplerate is too low");
+				cairo_put_banner( cr, da_thing_wd, da_thing_ht, "Samplerate is too low");
 				goto out;
 			}
 			if ( Pp2.dzcdf_step * 10 > current_pattern->pattern_length() ) { // require at least 10 dzcdf points
-				agh::ui::cairo_put_banner( cr, da_thing_wd, da_thing_ht, "Selection is too short for DZCDF");
+				cairo_put_banner( cr, da_thing_wd, da_thing_ht, "Selection is too short for DZCDF");
 				goto out;
 			}
 
@@ -147,8 +152,9 @@ draw_thing( cairo_t *cr)
 
 			cairo_set_source_rgba( cr, 0.3, 0.3, 0.99, .8);
 			cairo_set_line_width( cr, 1.);
-			agh::ui::cairo_draw_signal( cr, dzcdf, 0, dzcdf.size(),
-						  da_thing_wd, 0, zeroline, dzcdf_display_scale);
+			cairo_draw_signal(
+				cr, dzcdf, 0, dzcdf.size(),
+				da_thing_wd, 0, zeroline, dzcdf_display_scale);
 			cairo_stroke( cr);
 		}
 	}
@@ -157,7 +163,7 @@ out:
 }
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 draw_field( cairo_t *cr)
 {
       // field
@@ -168,13 +174,13 @@ draw_field( cairo_t *cr)
 	field_profile_type = get<0>(profile_with_corrected_type);
 	auto& profile = get<1>(profile_with_corrected_type);
 	if ( field_profile_type == metrics::TType::raw )
-		agh::ui::cairo_draw_envelope(
+		cairo_draw_envelope(
 			cr,
 			profile, 0, profile.size(),
 			da_field_wd, 0., da_field_ht/4,
 			field_display_scale);
 	else {
-		agh::ui::cairo_draw_signal(
+		cairo_draw_signal(
 			cr,
 			profile, 0, profile.size(),
 			da_field_wd, 0., da_field_ht/2,
@@ -188,7 +194,7 @@ draw_field( cairo_t *cr)
 
       // occurrences
 	if ( occurrences.size() > 500 )
-		agh::ui::cairo_put_banner(
+		cairo_put_banner(
 			cr, da_field_wd, da_field_ht / .75, "Too many; reduce strictness?");
 	else if ( occurrences.size() > 0 ) {
 		cairo_set_line_width( cr, 1.);
@@ -207,7 +213,7 @@ draw_field( cairo_t *cr)
 			cairo_stroke( cr);
 		}
 	} else
-		agh::ui::cairo_put_banner(
+		cairo_put_banner(
 			cr, da_field_wd, da_field_ht / .75, "Nothing found");
 
       // diff line with degree of criteria attainment
@@ -237,6 +243,7 @@ draw_field( cairo_t *cr)
 #undef KEKE
 }
 
+
 // Local Variables:
 // Mode: c++
 // indent-tabs-mode: 8
diff --git a/src/aghermann/ui/sf/d/patterns-profiles.cc b/src/aghermann/ui/sf/d/patterns-profiles.cc
index 4b12b87..422fd40 100644
--- a/src/aghermann/ui/sf/d/patterns-profiles.cc
+++ b/src/aghermann/ui/sf/d/patterns-profiles.cc
@@ -16,10 +16,11 @@
 #include "patterns.hh"
 
 using namespace std;
+using namespace agh::ui;
 
 
 int
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 import_from_selection( SScoringFacility::SChannel& field)
 {
 	// double check, possibly redundant after due check in callback
@@ -28,7 +29,7 @@ import_from_selection( SScoringFacility::SChannel& field)
 	if ( run == 0 )
 		return -1;
 	if ( run_time > 60. ) {
-		agh::ui::pop_ok_message(
+		pop_ok_message(
 			(GtkWindow*)wSFFD,
 			"<b>Selection greater than a minute</b>",
 			"This is surely the single occurrence, I tell you!");
@@ -36,7 +37,7 @@ import_from_selection( SScoringFacility::SChannel& field)
 	}
 	if ( run_time > 10. and
 	     GTK_RESPONSE_YES !=
-	     agh::ui::pop_question(
+	     pop_question(
 		     (GtkWindow*)wSFFD,
 		     "<b>The selection is greater than 10 sec</b>",
 		     "Sure to proceed with search?") )
@@ -114,7 +115,7 @@ make_subject_patterns_location( const agh::CExpDesign& ED, const agh::CSubject&
 
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 load_patterns()
 {
 	patterns.clear();
@@ -141,7 +142,7 @@ load_patterns()
 
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 populate_combo()
 {
 	g_signal_handler_block( eSFFDPatternList, eSFFDPatternList_changed_cb_handler_id);
@@ -151,9 +152,10 @@ populate_combo()
 		GtkTreeIter iter, current_pattern_iter;
 		for ( auto I = patterns.begin(); I != patterns.end(); ++I ) {
 			gtk_list_store_append( mSFFDPatterns, &iter);
-			gtk_list_store_set( mSFFDPatterns, &iter,
-					    0, snprintf_buf( "%s %s", origin_markers[I->origin], I->name.c_str()),
-					    -1);
+			gtk_list_store_set(
+				mSFFDPatterns, &iter,
+				0, snprintf_buf( "%s %s", origin_markers[I->origin], I->name.c_str()),
+				-1);
 			if ( I == current_pattern )
 				current_pattern_iter = iter;
 		}
@@ -168,7 +170,7 @@ populate_combo()
 
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 save_patterns()
 {
 	for ( auto& P : patterns )
@@ -193,7 +195,7 @@ save_patterns()
 
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 discard_current_pattern()
 {
 	if ( current_pattern == patterns.end() )
@@ -206,7 +208,6 @@ discard_current_pattern()
 }
 
 
-
 // Local Variables:
 // Mode: c++
 // indent-tabs-mode: 8
diff --git a/src/aghermann/ui/sf/d/patterns-profiles_cb.cc b/src/aghermann/ui/sf/d/patterns-profiles_cb.cc
index 372ebc2..a89ec8c 100644
--- a/src/aghermann/ui/sf/d/patterns-profiles_cb.cc
+++ b/src/aghermann/ui/sf/d/patterns-profiles_cb.cc
@@ -12,12 +12,10 @@
 #include <sys/time.h>
 
 #include "aghermann/ui/misc.hh"
-
 #include "patterns.hh"
 
 
 using namespace std;
-
 using namespace agh::ui;
 
 
diff --git a/src/aghermann/ui/sf/d/patterns.cc b/src/aghermann/ui/sf/d/patterns.cc
index 97fcfc0..e48d233 100644
--- a/src/aghermann/ui/sf/d/patterns.cc
+++ b/src/aghermann/ui/sf/d/patterns.cc
@@ -14,9 +14,11 @@
 #include "patterns.hh"
 
 using namespace std;
+using namespace agh::ui;
 
-agh::ui::SScoringFacility::SPatternsDialog&
-agh::ui::SScoringFacility::
+
+SScoringFacility::SPatternsDialog&
+SScoringFacility::
 patterns_d()
 {
 	if ( not _patterns_d )
@@ -24,7 +26,7 @@ patterns_d()
 	return *_patterns_d;
 }
 
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 SPatternsDialog (SScoringFacility& parent)
       : SPatternsDialogWidgets (parent),
 	Pp2 {.25,  0., 1.5, 1,  .1, .5, 3},
@@ -55,7 +57,7 @@ SPatternsDialog (SScoringFacility& parent)
 	load_patterns();
 }
 
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 ~SPatternsDialog ()
 {
 	save_patterns();
@@ -68,7 +70,7 @@ agh::ui::SScoringFacility::SPatternsDialog::
 
 
 list<pattern::SPattern<TFloat>>::iterator
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 pattern_by_idx( size_t idx)
 {
 	size_t i = 0;
@@ -84,7 +86,7 @@ pattern_by_idx( size_t idx)
 
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 search()
 {
 	assert (field_channel and current_pattern != patterns.end());
@@ -108,7 +110,7 @@ search()
 
 
 size_t
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 find_occurrences()
 {
 	if ( unlikely (current_pattern == patterns.end()) )
@@ -132,7 +134,7 @@ find_occurrences()
 
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 occurrences_to_annotations( sigfile::SAnnotation::TType t)
 {
 	for ( size_t o = 0; o < occurrences.size(); ++o )
@@ -145,14 +147,14 @@ occurrences_to_annotations( sigfile::SAnnotation::TType t)
 }
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 save_annotations()
 {
 	saved_annotations = field_channel->annotations;
 }
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 restore_annotations()
 {
 	field_channel->annotations = saved_annotations;
@@ -163,7 +165,7 @@ restore_annotations()
 
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 setup_controls_for_find()
 {
 	bool	have_any = current_pattern != patterns.end();
@@ -185,7 +187,7 @@ setup_controls_for_find()
 }
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 setup_controls_for_wait()
 {
 	gtk_widget_set_visible( (GtkWidget*)cSFFDSearchButton, FALSE);
@@ -203,7 +205,7 @@ setup_controls_for_wait()
 }
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 setup_controls_for_tune()
 {
 	gtk_widget_set_visible( (GtkWidget*)cSFFDSearchButton, FALSE);
@@ -223,7 +225,7 @@ setup_controls_for_tune()
 
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 set_profile_manage_buttons_visibility()
 {
 	bool	have_any = current_pattern != patterns.end(),
@@ -236,7 +238,7 @@ set_profile_manage_buttons_visibility()
 
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 preselect_channel( const int h) const
 {
 	if ( h < 0 ) {
@@ -250,7 +252,7 @@ preselect_channel( const int h) const
 
 
 size_t
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 nearest_occurrence( const double x) const
 {
 	double shortest = INFINITY;
@@ -269,7 +271,7 @@ nearest_occurrence( const double x) const
 
 
 void
-agh::ui::SScoringFacility::SPatternsDialog::
+SScoringFacility::SPatternsDialog::
 update_field_check_menu_items()
 {
 	suppress_redraw = true;
diff --git a/src/aghermann/ui/sf/d/phasediff-construct.cc b/src/aghermann/ui/sf/d/phasediff-construct.cc
index adca325..707a087 100644
--- a/src/aghermann/ui/sf/d/phasediff-construct.cc
+++ b/src/aghermann/ui/sf/d/phasediff-construct.cc
@@ -14,8 +14,10 @@
 #include "phasediff.hh"
 
 using namespace std;
+using namespace agh::ui;
 
-agh::ui::SPhasediffDialogWidgets::
+
+SPhasediffDialogWidgets::
 SPhasediffDialogWidgets (SScoringFacility& SF)
 {
 	builder = gtk_builder_new();
@@ -67,7 +69,7 @@ SPhasediffDialogWidgets (SScoringFacility& SF)
 }
 
 
-agh::ui::SPhasediffDialogWidgets::
+SPhasediffDialogWidgets::
 ~SPhasediffDialogWidgets ()
 {
 	gtk_widget_destroy( (GtkWidget*)wSFPD);
diff --git a/src/aghermann/ui/sf/d/phasediff.cc b/src/aghermann/ui/sf/d/phasediff.cc
index e30da54..37f0ed1 100644
--- a/src/aghermann/ui/sf/d/phasediff.cc
+++ b/src/aghermann/ui/sf/d/phasediff.cc
@@ -15,9 +15,11 @@
 #include "phasediff.hh"
 
 using namespace std;
+using namespace agh::ui;
 
-agh::ui::SScoringFacility::SPhasediffDialog&
-agh::ui::SScoringFacility::phasediff_d()
+
+SScoringFacility::SPhasediffDialog&
+SScoringFacility::phasediff_d()
 {
 	if ( not _phasediff_d )
 		_phasediff_d = new SScoringFacility::SPhasediffDialog(*this);
@@ -25,8 +27,8 @@ agh::ui::SScoringFacility::phasediff_d()
 }
 
 
-agh::ui::SScoringFacility::SPhasediffDialog::
-SPhasediffDialog (agh::ui::SScoringFacility& parent)
+SScoringFacility::SPhasediffDialog::
+SPhasediffDialog (SScoringFacility& parent)
       : SPhasediffDialogWidgets (parent),
 	channel1 (nullptr),
 	channel2 (nullptr),
@@ -46,7 +48,7 @@ SPhasediffDialog (agh::ui::SScoringFacility& parent)
 
 
 void
-agh::ui::SScoringFacility::SPhasediffDialog::
+SScoringFacility::SPhasediffDialog::
 update_course()
 {
 	if ( channel1->samplerate() != channel2->samplerate() )
@@ -80,8 +82,8 @@ update_course()
 	}
 }
 
-const agh::ui::SScoringFacility::SChannel*
-agh::ui::SScoringFacility::SPhasediffDialog::
+const SScoringFacility::SChannel*
+SScoringFacility::SPhasediffDialog::
 channel_from_cbox( GtkComboBox *cbox)
 {
 	GtkTreeIter iter;
@@ -100,7 +102,7 @@ channel_from_cbox( GtkComboBox *cbox)
 
 
 void
-agh::ui::SScoringFacility::SPhasediffDialog::
+SScoringFacility::SPhasediffDialog::
 preselect_channel( GtkComboBox *cbox, const string& ch)
 {
 	GtkTreeModel *model = gtk_combo_box_get_model( cbox);
@@ -127,7 +129,7 @@ preselect_channel( GtkComboBox *cbox, const string& ch)
 
 
 void
-agh::ui::SScoringFacility::SPhasediffDialog::
+SScoringFacility::SPhasediffDialog::
 draw( cairo_t* cr, const int wd, const int ht)
 {
 	auto& SF = _p;
@@ -139,17 +141,17 @@ draw( cairo_t* cr, const int wd, const int ht)
 	cairo_stroke( cr);
 
 	if ( channel1 == channel2 ) {
-		agh::ui::cairo_put_banner( cr, wd, ht, "Same channel");
+		cairo_put_banner( cr, wd, ht, "Same channel");
 		return;
 	}
 
 	if ( course.size() == 0 ) {
-		agh::ui::cairo_put_banner( cr, wd, ht, "Huh?");
+		cairo_put_banner( cr, wd, ht, "Huh?");
 		return;
 	}
 
 	if ( channel1->samplerate() != channel2->samplerate() ) {
-		agh::ui::cairo_put_banner( cr, wd, ht, "Incompatible channels (different samplerate)");
+		cairo_put_banner( cr, wd, ht, "Incompatible channels (different samplerate)");
 		return;
 	}
 
diff --git a/src/aghermann/ui/sf/hypnogram.cc b/src/aghermann/ui/sf/hypnogram.cc
index 62882e6..c898e6c 100644
--- a/src/aghermann/ui/sf/hypnogram.cc
+++ b/src/aghermann/ui/sf/hypnogram.cc
@@ -17,6 +17,7 @@
 #include "sf.hh"
 
 using namespace std;
+using namespace agh::ui;
 
 
 namespace {
@@ -29,7 +30,7 @@ unsigned short __score_hypn_depth[8] = {
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 draw_hypnogram( cairo_t *cr)
 {
       // bg
@@ -124,7 +125,7 @@ draw_hypnogram( cairo_t *cr)
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 do_dialog_import_hypnogram()
 {
 	GtkWidget *f_chooser =
@@ -166,7 +167,7 @@ do_dialog_import_hypnogram()
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 do_dialog_export_hypnogram() const
 {
 	GtkWidget *f_chooser =
@@ -188,7 +189,7 @@ do_dialog_export_hypnogram() const
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 do_clear_hypnogram()
 {
 	hypnogram.assign(
diff --git a/src/aghermann/ui/sf/ica.cc b/src/aghermann/ui/sf/ica.cc
index 5ebd48b..dade7ad 100644
--- a/src/aghermann/ui/sf/ica.cc
+++ b/src/aghermann/ui/sf/ica.cc
@@ -19,12 +19,13 @@
 #include "sf_cb.hh"
 
 using namespace std;
+using namespace agh::ui;
 
 const char
-	*agh::ui::SScoringFacility::ica_unmapped_menu_item_label = "(not mapped)";
+	*SScoringFacility::ica_unmapped_menu_item_label = "(not mapped)";
 
 int
-agh::ui::SScoringFacility::
+SScoringFacility::
 setup_ica()
 {
 	if ( ica )
@@ -135,13 +136,13 @@ setup_ica()
 
 
 int
-agh::ui::SScoringFacility::
+SScoringFacility::
 run_ica()
 {
 	if ( ica == nullptr )
 		return 1;
 
-	agh::ui::SBusyBlock bb (wSF);
+	SBusyBlock bb (wSF);
 
 	ica_components = itpp::mat (0, 0); // free up couple of hundred megs
 	ica->obj() . separate();
@@ -155,13 +156,13 @@ run_ica()
 
 
 int
-agh::ui::SScoringFacility::
+SScoringFacility::
 remix_ics()
 {
 	if ( ica == nullptr )
 		return 1;
 
-	agh::ui::SBusyBlock bb (wSF);
+	SBusyBlock bb (wSF);
 
 	switch ( remix_mode ) {
 	case TICARemixMode::map:
@@ -228,7 +229,7 @@ remix_ics()
 }
 
 int
-agh::ui::SScoringFacility::
+SScoringFacility::
 restore_ics()
 {
 	if ( ica == nullptr )
@@ -250,7 +251,7 @@ restore_ics()
 
 
 int
-agh::ui::SScoringFacility::
+SScoringFacility::
 apply_remix( const bool do_backup)
 {
 	if ( ica == nullptr )
@@ -267,8 +268,8 @@ apply_remix( const bool do_backup)
 		affected_sources.unique();
 		for ( auto &fname : affected_sources ) {
 			snprintf_buf( "cp -f '%s' '%s.orig'", fname.c_str(), fname.c_str());
-			if ( system(__buf__) )
-				fprintf( stderr, "SScoringFacility::apply_remix(): Command '%s' failed", __buf__);
+			if ( system(global::buf) )
+				fprintf( stderr, "SScoringFacility::apply_remix(): Command '%s' failed", global::buf);
 		}
 	}
 	// put signal
@@ -298,7 +299,7 @@ apply_remix( const bool do_backup)
 
 int
 __attribute__ ((pure))
-agh::ui::SScoringFacility::
+SScoringFacility::
 ic_near( const double y) const
 {
 	int nearest = INT_MAX, thisd;
@@ -324,7 +325,7 @@ ic_near( const double y) const
 
 int
 __attribute__ ((pure))
-agh::ui::SScoringFacility::
+SScoringFacility::
 ic_of( const SChannel* ch) const
 {
 	int h = 0;
@@ -333,7 +334,7 @@ ic_of( const SChannel* ch) const
 			return h;
 		++h;
 	}
-	throw out_of_range ("agh::ui::SScoringFacility::ic_of(): bad channel");
+	throw out_of_range ("SScoringFacility::ic_of(): bad channel");
 }
 
 
diff --git a/src/aghermann/ui/sf/montage-overlays.cc b/src/aghermann/ui/sf/montage-overlays.cc
index 197b8cb..5610a35 100644
--- a/src/aghermann/ui/sf/montage-overlays.cc
+++ b/src/aghermann/ui/sf/montage-overlays.cc
@@ -18,10 +18,10 @@
 #include "sf.hh"
 
 using namespace std;
-
+using namespace agh::ui;
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 draw_overlays( cairo_t* cr,
 	       const int wd, const float zeroy) const
 {
@@ -59,17 +59,18 @@ draw_overlays( cairo_t* cr,
 
 				if ( b == psd.focused_band ) {
 					cairo_select_font_face( cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
-					snprintf_buf( "%s %g–%g",
-						      _p._p.ED->FreqBandNames[(unsigned)b],
-						      _p._p.ED->freq_bands[(unsigned)b][0],
-						      _p._p.ED->freq_bands[(unsigned)b][1]);
+					snprintf_buf(
+						"%s %g–%g",
+						_p._p.ED->FreqBandNames[(unsigned)b],
+						_p._p.ED->freq_bands[(unsigned)b][0],
+						_p._p.ED->freq_bands[(unsigned)b][1]);
 				} else {
 					cairo_select_font_face( cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
 					snprintf_buf( "%s", _p._p.ED->FreqBandNames[(unsigned)b]);
 				}
 				cairo_move_to( cr, _p.da_wd - 170,
 					       ptop + psd.uppermost_band*12 - 12*(unsigned)b + 12);
-				cairo_show_text( cr, __buf__);
+				cairo_show_text( cr, global::buf);
 				cairo_stroke( cr);
 			}
 		} else {
@@ -164,14 +165,15 @@ draw_overlays( cairo_t* cr,
 			_p._p.CwB[SExpDesignUI::TColour::sf_labels].set_source_rgba( cr);
 			cairo_set_font_size( cr, 8);
 
-			snprintf_buf( "%g Hz",
-				      last_spectrum_bin * crecording.psd_profile.Pp.binsize);
-//				      draw_spectrum_absolute ? 'A' : 'R');
-			cairo_text_extents( cr, __buf__, &extents);
+			snprintf_buf(
+				"%g Hz",
+				last_spectrum_bin * crecording.psd_profile.Pp.binsize);
+//				draw_spectrum_absolute ? 'A' : 'R');
+			cairo_text_extents( cr, global::buf, &extents);
 			cairo_move_to( cr,
 				       gx + gw - extents.width - 5,
 				       gy + 4);
-			cairo_show_text( cr, __buf__);
+			cairo_show_text( cr, global::buf);
 			cairo_stroke( cr);
 		}
 	}
@@ -304,7 +306,7 @@ draw_overlays( cairo_t* cr,
 		cairo_set_source( cr, cp);
 
 		cairo_set_line_width( cr, .3);
-		agh::ui::cairo_draw_envelope(
+		cairo_draw_envelope(
 			cr,
 			raw_profile, 0, raw_profile.size(),
 			_p.da_wd, 0., pbot - EMGProfileHeight/2, signal_display_scale/2.); // half-signal scale, looks ok?
@@ -323,17 +325,19 @@ draw_overlays( cairo_t* cr,
 		cairo_select_font_face( cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
 		_p._p.CwB[SExpDesignUI::TColour::sf_cursor].set_source_rgb( cr);
 		if ( this == &_p.channels.front() )
-			snprintf_buf( "%4.2f (%5.2fs)",
-				      (draw_filtered_signal ? signal_filtered : signal_original)
-				      [ (size_t)(_p.crosshair_at_time * samplerate()) ],
-				      _p.crosshair_at_time - _p.cur_xvpage_start() - _p.skirting_run_per1 * _p.vpagesize());
+			snprintf_buf(
+				"%4.2f (%5.2fs)",
+				(draw_filtered_signal ? signal_filtered : signal_original)
+				[ (size_t)(_p.crosshair_at_time * samplerate()) ],
+				_p.crosshair_at_time - _p.cur_xvpage_start() - _p.skirting_run_per1 * _p.vpagesize());
 		else
-			snprintf_buf( "%4.2f",
-				      (draw_filtered_signal ? signal_filtered : signal_original)
-				      [ (size_t)(_p.crosshair_at_time * samplerate()) ]);
+			snprintf_buf(
+				"%4.2f",
+				(draw_filtered_signal ? signal_filtered : signal_original)
+				[ (size_t)(_p.crosshair_at_time * samplerate()) ]);
 
 		cairo_move_to( cr, _p.crosshair_at+2, ptop + 22);
-		cairo_show_text( cr, __buf__);
+		cairo_show_text( cr, global::buf);
 		cairo_stroke( cr);
 	}
 
@@ -354,7 +358,7 @@ draw_overlays( cairo_t* cr,
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 _draw_hour_ticks( cairo_t *cr,
 		  const int htop, const int hbot,
 		  const bool with_cursor)
diff --git a/src/aghermann/ui/sf/montage.cc b/src/aghermann/ui/sf/montage.cc
index 224ce22..492ca7b 100644
--- a/src/aghermann/ui/sf/montage.cc
+++ b/src/aghermann/ui/sf/montage.cc
@@ -18,6 +18,7 @@
 #include "d/patterns.hh"
 
 using namespace std;
+using namespace agh::ui;
 
 namespace {
 
@@ -29,7 +30,7 @@ unsigned short PageTicks[] = {
 
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 draw_signal( const valarray<TFloat>& signal,
 	     size_t width, int vdisp, cairo_t *cr) const
 {
@@ -37,18 +38,19 @@ draw_signal( const valarray<TFloat>& signal,
 		end    = _p.cur_vpage_end()    * samplerate(),
 		run    = end - start,
 		half_pad = run * _p.skirting_run_per1;
-	agh::ui::cairo_draw_signal( cr, signal,
-				  start - half_pad,
-				  end + half_pad,
-				  width, 0, vdisp, signal_display_scale,
-				  resample_signal ? max(1u, (unsigned)spp()) : 1);
+	cairo_draw_signal(
+		cr, signal,
+		start - half_pad,
+		end + half_pad,
+		width, 0, vdisp, signal_display_scale,
+		resample_signal ? max(1u, (unsigned)spp()) : 1);
 }
 
 
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 estimate_montage_height()
 {
 	da_ht = channels.size() * interchannel_gap;
@@ -59,8 +61,8 @@ estimate_montage_height()
 
 
 struct SChHolder {
-	agh::ui::SScoringFacility::SChannel* ch;
-	SChHolder( agh::ui::SScoringFacility::SChannel& ini) : ch (&ini) {}
+	SScoringFacility::SChannel* ch;
+	SChHolder( SScoringFacility::SChannel& ini) : ch (&ini) {}
 	bool operator<( const SChHolder& rv) const
 		{
 			return ch->zeroy < rv.ch->zeroy;
@@ -70,7 +72,7 @@ struct SChHolder {
 
 
 sigfile::SAnnotation*
-agh::ui::SScoringFacility::
+SScoringFacility::
 interactively_choose_annotation() const
 {
 	// do some on-the-fly construcion
@@ -102,7 +104,7 @@ interactively_choose_annotation() const
 
 
 int
-agh::ui::SScoringFacility::
+SScoringFacility::
 find_free_space()
 {
 	vector<SChHolder> thomas;
@@ -134,7 +136,7 @@ find_free_space()
 }
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 space_evenly()
 {
 	vector<SChHolder> thomas;
@@ -157,7 +159,7 @@ space_evenly()
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 expand_by_factor( const double fac)
 {
 	for ( auto &H : channels ) {
@@ -182,7 +184,7 @@ expand_by_factor( const double fac)
 
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 draw_for_montage( const string& fname,
 		  const int width, const int height) // to a file
 {
@@ -197,7 +199,7 @@ draw_for_montage( const string& fname,
 }
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 draw_for_montage( cairo_t* cr)
 {
 	if ( !hidden ) {
@@ -209,7 +211,7 @@ draw_for_montage( cairo_t* cr)
 
 
 void
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 draw_page( cairo_t *cr,
 	   const int wd, const float y0,
 	   bool draw_marquee) const
@@ -227,7 +229,7 @@ draw_page( cairo_t *cr,
 	}
 
       // marquee, goes first, not to obscure waveforms
-	if ( _p.mode != agh::ui::SScoringFacility::TMode::shuffling_channels
+	if ( _p.mode != SScoringFacility::TMode::shuffling_channels
 	     and draw_marquee // possibly undesired (such as when drawing for unfazer (what unfazer?))
 	     && agh::alg::overlap(
 		     selection_start_time, selection_end_time,
@@ -256,15 +258,16 @@ draw_page( cairo_t *cr,
 		_p._p.CwB[SExpDesignUI::TColour::sf_cursor].set_source_rgba( cr);
 
 		cairo_text_extents_t extents;
-		snprintf_buf( "%5.2fs",
-			      selection_start_time - _p.cur_xvpage_start() - pre);
-		cairo_text_extents( cr, __buf__, &extents);
+		snprintf_buf(
+			"%5.2fs",
+			selection_start_time - _p.cur_xvpage_start() - pre);
+		cairo_text_extents( cr, global::buf, &extents);
 		double ido = ma - 3 - extents.width;
 		if ( ido < extents.width+3 )
 			cairo_move_to( cr, ma+3, ptop + 30);
 		else
 			cairo_move_to( cr, ido, ptop + 12);
-		cairo_show_text( cr, __buf__);
+		cairo_show_text( cr, global::buf);
 		cairo_stroke( cr);
 
 		if ( (draw_selection_envelope || draw_selection_course || draw_selection_dzcdf) &&
@@ -287,15 +290,15 @@ draw_page( cairo_t *cr,
 
 					cairo_set_source_rgba( cr, 1, 1, 1, .6);
 					cairo_set_line_width( cr, 1);
-					agh::ui::cairo_draw_signal(
+					cairo_draw_signal(
 						cr, env_u, 0, env_u.size(),
 						me-ma, ma, y0, signal_display_scale);
-					agh::ui::cairo_draw_signal(
+					cairo_draw_signal(
 						cr, env_l, 0, env_l.size(),
 						me-ma, ma, y0, signal_display_scale,
 						1,
-						agh::ui::TDrawSignalDirection::backward,
-						agh::ui::TDrawSignalPathOption::yes);
+						TDrawSignalDirection::backward,
+						TDrawSignalPathOption::yes);
 					cairo_close_path( cr);
 					cairo_fill( cr);
 					cairo_stroke( cr);
@@ -312,7 +315,7 @@ draw_page( cairo_t *cr,
 
 				cairo_set_source_rgba( cr, 0.3, 0.3, 0.3, .5);
 				cairo_set_line_width( cr, 3.);
-				agh::ui::cairo_draw_signal(
+				cairo_draw_signal(
 					cr, course, 0, course.size(),
 					me-ma, ma, y0, signal_display_scale);
 				cairo_stroke( cr);
@@ -330,7 +333,7 @@ draw_page( cairo_t *cr,
 
 					cairo_set_source_rgba( cr, 0.3, 0.3, 0.99, .8);
 					cairo_set_line_width( cr, 1.);
-					agh::ui::cairo_draw_signal(
+					cairo_draw_signal(
 						cr, dzcdf, 0, dzcdf.size(),
 						me-ma, ma, y0, dzcdf_display_scale);
 					cairo_stroke( cr);
@@ -341,22 +344,24 @@ draw_page( cairo_t *cr,
 	      // labels
 		if ( selection_end_time - selection_start_time > .25 ) {  // don't mark end if selection is too short
 			_p._p.CwB[SExpDesignUI::TColour::sf_cursor].set_source_rgba( cr);
-			snprintf_buf( "%5.2fs",
-				      selection_end_time - _p.cur_xvpage_start() - pre);
-			cairo_text_extents( cr, __buf__, &extents);
+			snprintf_buf(
+				"%5.2fs",
+				selection_end_time - _p.cur_xvpage_start() - pre);
+			cairo_text_extents( cr, global::buf, &extents);
 			ido = me + extents.width+3;
 			if ( ido > wd )
 				cairo_move_to( cr, me - 3 - extents.width, ptop + 30);
 			else
 				cairo_move_to( cr, me + 3, ptop + 12);
-			cairo_show_text( cr, __buf__);
+			cairo_show_text( cr, global::buf);
 
-			snprintf_buf( "< %4.2fs >", // "←%4.2fs→",
-				      selection_end_time - selection_start_time);
-			cairo_text_extents( cr, __buf__, &extents);
+			snprintf_buf(
+				"< %4.2fs >", // "←%4.2fs→",
+				selection_end_time - selection_start_time);
+			cairo_text_extents( cr, global::buf, &extents);
 			cairo_move_to( cr, ma+(me-ma)/2 - extents.width/2,
 				       ptop + (extents.width < me-ma ? 12 : 30));
-			cairo_show_text( cr, __buf__);
+			cairo_show_text( cr, global::buf);
 
 			// MC metrics
 			if ( schannel().type() == sigfile::SChannel::TType::eeg &&
@@ -364,12 +369,13 @@ draw_page( cairo_t *cr,
 
 				cairo_set_font_size( cr, 10);
 				cairo_select_font_face( cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
-				snprintf_buf( "%4.2f (%3.1f / %3.1f)",
-					      selection_SS / selection_SU, selection_SS, selection_SU);
-				cairo_text_extents( cr, __buf__, &extents);
+				snprintf_buf(
+					"%4.2f (%3.1f / %3.1f)",
+					selection_SS / selection_SU, selection_SS, selection_SU);
+				cairo_text_extents( cr, global::buf, &extents);
 				cairo_move_to( cr, ma+(me-ma)/2 - extents.width/2,
 					       pbot - (extents.width < me-ma ? 12 : 30));
-				cairo_show_text( cr, __buf__);
+				cairo_show_text( cr, global::buf);
 			}
 			cairo_stroke( cr);
 		}
@@ -385,7 +391,7 @@ draw_page( cairo_t *cr,
 		draw_signal_filtered( wd, y0, cr);
 		cairo_stroke( cr);
 
-		if ( _p.mode == agh::ui::SScoringFacility::TMode::scoring ) {
+		if ( _p.mode == SScoringFacility::TMode::scoring ) {
 			_p._p.CwB[SExpDesignUI::TColour::sf_labels].set_source_rgb( cr);
 			cairo_move_to( cr, wd-88, y0 - 15);
 			cairo_set_font_size( cr, 10);
@@ -407,7 +413,7 @@ draw_page( cairo_t *cr,
 		draw_signal_original( wd, y0, cr);
 		cairo_stroke( cr);
 
-		if ( _p.mode == agh::ui::SScoringFacility::TMode::scoring ) {
+		if ( _p.mode == SScoringFacility::TMode::scoring ) {
 			_p._p.CwB[SExpDesignUI::TColour::sf_labels].set_source_rgb( cr);
 			cairo_move_to( cr, wd-88, y0 - 25);
 			cairo_set_font_size( cr, 10);
@@ -417,7 +423,7 @@ draw_page( cairo_t *cr,
 	}
 
       // waveform: signal_reconstituted
-	if ( _p.mode == agh::ui::SScoringFacility::TMode::showing_remixed &&
+	if ( _p.mode == SScoringFacility::TMode::showing_remixed &&
 	     signal_reconstituted.size() != 0 ) {
 		if ( apply_reconstituted ) {
 			cairo_set_line_width( cr, fine_line() * 1.3);
@@ -477,7 +483,7 @@ draw_page( cairo_t *cr,
 	}
 
       // annotations
-	if ( _p.mode == agh::ui::SScoringFacility::TMode::scoring
+	if ( _p.mode == SScoringFacility::TMode::scoring
 	     and not annotations.empty() ) {
 		double last_label_end = 0;
 		int overlap_count = 0;
@@ -576,12 +582,12 @@ draw_page( cairo_t *cr,
 
 		cairo_set_source_rgba( cr, 1., 1., 1., 0.6);
 		cairo_move_to( cr, x+1, y+1);
-		cairo_show_text( cr, __buf__);
+		cairo_show_text( cr, global::buf);
 		cairo_stroke( cr);
 
 		cairo_set_source_rgba( cr, 0., 0., 0., 0.7);
 		cairo_move_to( cr, x, y);
-		cairo_show_text( cr, __buf__);
+		cairo_show_text( cr, global::buf);
 		cairo_stroke( cr);
 	}
 
@@ -595,7 +601,7 @@ draw_page( cairo_t *cr,
 		cairo_set_source_rgb( cr, 0., 0., 0.);
 		cairo_set_line_width( cr, 1.5);
 		double dpuf =
-			agh::alg::sensible_scale_reduction_factor(
+			alg::sensible_scale_reduction_factor(
 				1 * signal_display_scale, _p.interchannel_gap * .75);
 		int x = 10;
 		cairo_move_to( cr, x, ptop + 5);
@@ -612,15 +618,12 @@ draw_page( cairo_t *cr,
 	{
 		cairo_set_font_size( cr, 9);
 		if ( have_low_pass() ) {
-			snprintf_buf( "LP: %6.2f/%u", filters.low_pass_cutoff, filters.low_pass_order);
 			cairo_move_to( cr, wd-100, y0 + 15);
-			cairo_show_text( cr, __buf__);
+			cairo_show_text( cr, snprintf_buf( "LP: %6.2f/%u", filters.low_pass_cutoff, filters.low_pass_order));
 		}
 		if ( have_high_pass() ) {
 			cairo_move_to( cr, wd-100, y0 + 24);
-			cairo_show_text(
-				cr,
-				snprintf_buf( "HP: %6.2f/%u", filters.high_pass_cutoff, filters.high_pass_order));
+			cairo_show_text( cr, snprintf_buf( "HP: %6.2f/%u", filters.high_pass_cutoff, filters.high_pass_order));
 		}
 		if ( have_notch_filter() ) {
 			static const char *nfs[] = { "", "50 Hz", "60 Hz" };
@@ -633,7 +636,7 @@ draw_page( cairo_t *cr,
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 draw_montage( const string& fname) // to a file
 {
 	cairo_surface_t *cs = cairo_svg_surface_create( fname.c_str(), da_wd, da_ht);
@@ -647,7 +650,7 @@ draw_montage( const string& fname) // to a file
 
 template <class T>
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 _draw_matrix_to_montage( cairo_t *cr, const itpp::Mat<T>& mat)
 {
 	int gap = da_ht/mat.rows();
@@ -705,10 +708,11 @@ _draw_matrix_to_montage( cairo_t *cr, const itpp::Mat<T>& mat)
 			run   = end - start,
 			half_pad = run * skirting_run_per1;
 
-		agh::ui::cairo_draw_signal( cr, mat, r,
-					  start - half_pad,
-					  end + half_pad,
-					  da_wd, 0, our_y, our_display_scale);
+		cairo_draw_signal(
+			cr, mat, r,
+			start - half_pad,
+			end + half_pad,
+			da_wd, 0, our_y, our_display_scale);
 		cairo_stroke( cr);
 		our_y += gap;
 	}
@@ -716,7 +720,7 @@ _draw_matrix_to_montage( cairo_t *cr, const itpp::Mat<T>& mat)
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 draw_montage( cairo_t* cr)
 {
 	double	true_frac = 1. - 1. / (1. + 2*skirting_run_per1),
@@ -727,7 +731,7 @@ draw_montage( cairo_t* cr)
 	switch ( mode ) {
 	case TMode::showing_ics:
 		if ( ica_components.size() == 0 ) {
-			agh::ui::cairo_put_banner(
+			cairo_put_banner(
 				cr, da_wd, da_ht,
 				"Now set up ICA parameters, then press [Compute ICs]");
 		} else
@@ -735,7 +739,7 @@ draw_montage( cairo_t* cr)
 			// draw ignoring channels' zeroy
 	    break;
 	case TMode::separating:
-		agh::ui::cairo_put_banner(
+		cairo_put_banner(
 			cr, da_wd, da_ht,
 			"Separating...");
 	    break;
@@ -834,7 +838,7 @@ draw_montage( cairo_t* cr)
 			_p.CwB[SExpDesignUI::TColour::sf_labels].set_source_rgba( cr);
 			cairo_move_to( cr, half_pad + i * ef / PageTicks[pagesize_item] + 5, da_ht-2);
 			snprintf_buf_ts_s( tick_pos);
-			cairo_show_text( cr, __buf__);
+			cairo_show_text( cr, global::buf);
 		}
 		cairo_stroke( cr);
 	}
@@ -852,7 +856,6 @@ draw_montage( cairo_t* cr)
 }
 
 
-
 // Local Variables:
 // Mode: c++
 // indent-tabs-mode: 8
diff --git a/src/aghermann/ui/sf/montage_cb.cc b/src/aghermann/ui/sf/montage_cb.cc
index 18959b8..4a99f08 100644
--- a/src/aghermann/ui/sf/montage_cb.cc
+++ b/src/aghermann/ui/sf/montage_cb.cc
@@ -22,6 +22,7 @@
 
 
 using namespace std;
+using namespace agh;
 using namespace agh::ui;
 
 extern "C" {
@@ -623,7 +624,7 @@ iSFPageShowHidden_activate_cb(
 	SF.using_channel = Ch;
 	gdk_window_get_device_position(
 		gtk_widget_get_window( (GtkWidget*)SF.daSFMontage),
-		__client_pointer__,
+		global::client_pointer,
 		NULL, (int*)&Ch->zeroy, NULL); //SF.find_free_space();
 	SF.zeroy_before_shuffling = Ch->zeroy;
 	SF.event_y_when_shuffling = (double)Ch->zeroy;
@@ -770,7 +771,9 @@ iSFPageFilter_activate_cb(
 
 	gtk_label_set_markup(
 		FD.lSFFilterCaption,
-		snprintf_buf( "<big>Filters for channel <b>%s</b></big>", SF.using_channel->name()));
+		snprintf_buf(
+			"<big>Filters for channel <b>%s</b></big>",
+			SF.using_channel->name()));
 
 	if ( gtk_dialog_run( FD.wSFFilters) == GTK_RESPONSE_OK ) {
 		FD.W_V.down();
@@ -816,8 +819,9 @@ iSFPageArtifactsMarkFlat_activate_cb(
 		auto marked = SF.using_channel->mark_flat_regions_as_artifacts( AS.min_size, AS.pad);
 
 		SF.sb_message(
-			snprintf_buf( "Detected %.2g sec of flat regions, adding %.2g sec to already marked",
-				      marked.first, marked.second));
+			snprintf_buf(
+				"Detected %.2g sec of flat regions, adding %.2g sec to already marked",
+				marked.first, marked.second));
 
 		gtk_widget_queue_draw( (GtkWidget*)SF.daSFMontage);
 		gtk_widget_queue_draw( (GtkWidget*)SF.daSFHypnogram);
@@ -875,14 +879,15 @@ iSFPageSaveChannelAsSVG_activate_cb(
 	auto& SF = *(SScoringFacility*)userdata;
 	auto& ED = SF._p;
 	string j_dir = ED.ED->subject_dir( SF.using_channel->crecording.subject());
-	string fname { snprintf_buf(
-			"%s/%s/%s-p%zu@%zu.svg",
-			j_dir.c_str(), ED.AghD(), ED.AghT(), SF.cur_vpage(), SF.vpagesize()) };
+	string fname = str::sasprintf(
+		"%s/%s/%s-p%zu@%zu.svg",
+		j_dir.c_str(), ED.AghD(), ED.AghT(), SF.cur_vpage(), SF.vpagesize());
 
-	SF.using_channel->draw_for_montage( fname.c_str(), SF.da_wd, SF.interchannel_gap);
+	SF.using_channel->draw_for_montage( fname, SF.da_wd, SF.interchannel_gap);
 	ED.sb_message(
-		snprintf_buf( "Wrote \"%s\"",
-			      agh::str::homedir2tilda(fname).c_str()));
+		str::sasprintf(
+			"Wrote \"%s\"",
+			agh::str::homedir2tilda(fname).c_str()));
 }
 
 
@@ -894,15 +899,13 @@ iSFPageSaveMontageAsSVG_activate_cb(
 	auto& SF = *(SScoringFacility*)userdata;
 	auto& ED = SF._p;
 	string j_dir = ED.ED->subject_dir( SF.using_channel->crecording.subject());
-	string fname { snprintf_buf(
+	string fname = str::sasprintf(
 			"%s/%s/montage-p%zu@%zu.svg",
-			j_dir.c_str(), ED.AghD(), SF.cur_vpage(), SF.vpagesize())};
+			j_dir.c_str(), ED.AghD(), SF.cur_vpage(), SF.vpagesize());
 
-	SF.draw_montage( fname.c_str());
+	SF.draw_montage( fname);
 	ED.sb_message(
-		snprintf_buf(
-			"Wrote \"%s\"",
-			agh::str::homedir2tilda(fname).c_str()));
+		str::sasprintf( "Wrote \"%s\"", agh::str::homedir2tilda(fname).c_str()));
 }
 
 
@@ -916,14 +919,12 @@ iSFPageExportSignal_activate_cb(
 	string fname_base = r.F().filename();
 	r.F().export_filtered(
 		SF.using_channel->h(),
-		snprintf_buf( "%s-filt.tsv", fname_base.c_str()));
-	snprintf_buf( "%s-orig.tsv", fname_base.c_str());
+		str::sasprintf( "%s-filt.tsv", fname_base.c_str()));
 	r.F().export_original(
 		SF.using_channel->h(),
-		snprintf_buf( "%s-filt.tsv", fname_base.c_str()));
-	SF._p.sb_message(
-		snprintf_buf( "Wrote \"%s-{filt,orig}.tsv\"",
-			      fname_base.c_str()));
+		str::sasprintf( "%s-filt.tsv", fname_base.c_str()));
+	SF.sb_message(
+		str::sasprintf( "Wrote \"%s-{filt,orig}.tsv\"", fname_base.c_str()));
 }
 
 
@@ -1189,7 +1190,7 @@ iSFPageSelectionAnnotate_activate_cb(
 			: SAnnotation::TType::plain;
 
 		if ( strlen( new_ann) == 0 && type == SAnnotation::TType::plain ) {
-			agh::ui::pop_ok_message( SF.wSF, "Give a plain annotation a name", "and try again.");
+			pop_ok_message( SF.wSF, "Give a plain annotation a name", "and try again.");
 			return;
 		}
 
@@ -1251,15 +1252,14 @@ iSFPowerExportRange_activate_cb(
 	auto& SF = *(SScoringFacility*)userdata;
 	auto& R = SF.using_channel->crecording;
 
-	string fname_base;
 	if ( SF.using_channel->draw_psd ) {
-		fname_base = R.psd_profile.fname_base();
-		snprintf_buf( "%s-psd_%g-%g.tsv",
-			      fname_base.c_str(), SF.using_channel->psd.from, SF.using_channel->psd.upto);
+		string fname = str::sasprintf(
+			"%s-psd_%g-%g.tsv",
+			R.psd_profile.fname_base().c_str(), SF.using_channel->psd.from, SF.using_channel->psd.upto);
 		R.psd_profile.export_tsv(
 			SF.using_channel->psd.from, SF.using_channel->psd.upto,
-			__buf__);
-		fname_base = __buf__; // recycle
+			fname);
+		SF.sb_message( str::sasprintf( "Wrote \"%s\"", str::homedir2tilda(fname).c_str()));
 	}
 	// if ( SF.using_channel->draw_swu ) {
 	// 	fname_base = R.swu_profile.fname_base();
@@ -1267,8 +1267,8 @@ iSFPowerExportRange_activate_cb(
 	// 		      fname_base.c_str(), SF.using_channel->swu.from, SF.using_channel->swu.upto);
 	// 	R.swu_profile.export_tsv(
 	// 		SF.using_channel->swu.from, SF.using_channel->swu.upto,
-	// 		__buf__);
-	// 	fname_base = __buf__; // recycle
+	// 		global::buf);
+	// 	fname_base = global::buf; // recycle
 	// }
 	// if ( SF.using_channel->draw_mc ) {
 	// 	fname_base = R.mc_profile.fname_base();
@@ -1278,11 +1278,9 @@ iSFPowerExportRange_activate_cb(
 	// 		      R.freq_from + R.bandwidth*(SF.using_channel->mc.bin+1));
 	// 	R.mc_profile.export_tsv(
 	// 		SF.using_channel->mc.bin,
-	// 		__buf__);
-	// 	fname_base = __buf__;
+	// 		global::buf);
+	// 	fname_base = global::buf;
 	// }
-
-	SF._p.sb_message( snprintf_buf( "Wrote %s", agh::str::homedir2tilda(fname_base).c_str()));
 }
 
 void
@@ -1295,26 +1293,26 @@ iSFPowerExportAll_activate_cb(
 
 	string fname_base;
 	if ( SF.using_channel->draw_psd ) {
-		fname_base = SF.using_channel->crecording.psd_profile.fname_base();
-		snprintf_buf( "%s-psd.tsv", fname_base.c_str());
-		R.psd_profile.export_tsv( __buf__);
-		fname_base = __buf__; // recycle
+		string fname = str::sasprintf(
+			"%s-psd.tsv",
+			SF.using_channel->crecording.psd_profile.fname_base().c_str());
+		R.psd_profile.export_tsv( fname);
+		SF.sb_message( str::sasprintf( "Wrote \"%s\"", agh::str::homedir2tilda(fname).c_str()));
 	}
 	if ( SF.using_channel->draw_swu ) {
-		fname_base = SF.using_channel->crecording.swu_profile.fname_base();
-		snprintf_buf( "%s-swu.tsv", fname_base.c_str());
-		R.swu_profile.export_tsv( __buf__);
-		fname_base = __buf__;
+		string fname = str::sasprintf(
+			"%s-swu.tsv",
+			SF.using_channel->crecording.swu_profile.fname_base().c_str());
+		R.swu_profile.export_tsv( fname);
+		SF.sb_message( str::sasprintf( "Wrote \"%s\"", agh::str::homedir2tilda(fname).c_str()));
 	}
 	if ( SF.using_channel->draw_mc ) {
-		fname_base = SF.using_channel->crecording.mc_profile.fname_base();
-		snprintf_buf( "%s-mc.tsv", fname_base.c_str());
-		R.mc_profile.export_tsv( __buf__);
-		fname_base = __buf__;
+		string fname = str::sasprintf(
+			"%s-psd.tsv",
+			SF.using_channel->crecording.psd_profile.fname_base().c_str());
+		R.psd_profile.export_tsv( fname);
+		SF.sb_message( str::sasprintf( "Wrote \"%s\"", agh::str::homedir2tilda(fname).c_str()));
 	}
-
-	snprintf_buf( "Wrote %s", agh::str::homedir2tilda(fname_base).c_str());
-	SF._p.sb_message( __buf__);
 }
 
 void
diff --git a/src/aghermann/ui/sf/sf.cc b/src/aghermann/ui/sf/sf.cc
index 9be6b93..ae08c4a 100644
--- a/src/aghermann/ui/sf/sf.cc
+++ b/src/aghermann/ui/sf/sf.cc
@@ -25,23 +25,23 @@
 #include "d/patterns.hh"
 
 using namespace std;
+using namespace agh::ui;
 
+size_t	SScoringFacility::IntersignalSpace = 120,
+	SScoringFacility::HypnogramHeight  =  40,
+	SScoringFacility::EMGProfileHeight =  30;
 
-size_t	agh::ui::SScoringFacility::IntersignalSpace = 120,
-	agh::ui::SScoringFacility::HypnogramHeight  =  40,
-	agh::ui::SScoringFacility::EMGProfileHeight =  30;
 
-
-// class agh::ui::SScoringFacility
+// class SScoringFacility
 
 const array<unsigned, 9>
-	agh::ui::SScoringFacility::DisplayPageSizeValues = {
+	SScoringFacility::DisplayPageSizeValues = {
 	{4, 5, 10, 15, 20, 30, 60, 60*3, 60*5}
 };
 
 size_t
 __attribute__ ((pure))
-agh::ui::SScoringFacility::
+SScoringFacility::
 figure_display_pagesize_item( const size_t seconds)
 {
 	size_t i = 0;
@@ -53,10 +53,10 @@ figure_display_pagesize_item( const size_t seconds)
 
 using agh::confval::SValidator;
 
-agh::ui::SScoringFacility::
+SScoringFacility::
 SScoringFacility (agh::CSubject& J,
 		  const string& D, const string& E,
-		  agh::ui::SExpDesignUI& parent)
+		  SExpDesignUI& parent)
       : _p (parent),
 	_csubject (J),
 	_session (D),
@@ -97,7 +97,7 @@ SScoringFacility (agh::CSubject& J,
 	da_wd (800), // gets properly set in a configure_event cb
 	da_ht (NAN) // bad value, to be estimated unless previously saved
 {
-	agh::ui::SBusyBlock bb (_p.wMainWindow);
+	SBusyBlock bb (_p.wMainWindow);
 
       // complete widget construction
       // histogram -> scores
@@ -260,7 +260,7 @@ SScoringFacility (agh::CSubject& J,
 		}
 	// if there's too many visible, suggest to hide some
 	if ( channels.size() > 10 && n_hidden == 0 )
-		agh::ui::pop_ok_message(
+		pop_ok_message(
 			wSF, "<b>Montage seems overcrowded</b>",
 			"The recording you are about to view has %zu channels.\n"
 			"You can hide some using appropriate channel context menus.", channels.size() - n_hidden);
@@ -302,7 +302,7 @@ SScoringFacility (agh::CSubject& J,
 }
 
 
-agh::ui::SScoringFacility::
+SScoringFacility::
 ~SScoringFacility ()
 {
 	// put scores
@@ -338,7 +338,7 @@ agh::ui::SScoringFacility::
 }
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 redraw_ssubject_timeline() const
 {
 	auto j = _p.subject_presentation_by_csubject( _csubject);
@@ -350,8 +350,8 @@ redraw_ssubject_timeline() const
 
 
 
-agh::ui::SScoringFacility::SChannel&
-agh::ui::SScoringFacility::
+SScoringFacility::SChannel&
+SScoringFacility::
 operator[]( const string& ch)
 {
 	auto iter = find( channels.begin(), channels.end(), ch);
@@ -360,8 +360,8 @@ operator[]( const string& ch)
 	return *iter;
 }
 
-agh::ui::SScoringFacility::SChannel&
-agh::ui::SScoringFacility::
+SScoringFacility::SChannel&
+SScoringFacility::
 channel_by_idx( size_t i)
 {
 	for ( auto &H : channels )
@@ -371,9 +371,9 @@ channel_by_idx( size_t i)
 }
 
 
-agh::ui::SScoringFacility::SChannel*
+SScoringFacility::SChannel*
 __attribute__ ((pure))
-agh::ui::SScoringFacility::
+SScoringFacility::
 channel_near( const int y)
 {
 	int nearest = INT_MAX, thisy;
@@ -399,7 +399,7 @@ channel_near( const int y)
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 update_all_channels_profile_display_scale()
 {
 	for ( auto& H : channels )
@@ -410,7 +410,7 @@ update_all_channels_profile_display_scale()
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 get_hypnogram()
 {
 	// just get from the first source,
@@ -421,7 +421,7 @@ get_hypnogram()
 		hypnogram[p] = F[p].score_code();
 }
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 put_hypnogram()
 {
 	// but put to all
@@ -434,7 +434,7 @@ put_hypnogram()
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 calculate_scored_percent()
 {
 	using namespace sigfile;
@@ -463,7 +463,7 @@ calculate_scored_percent()
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 set_cur_vpage( size_t p, const bool touch_self)
 {
 	if ( _cur_vpage == p && !touch_self )
@@ -489,7 +489,7 @@ set_cur_vpage( size_t p, const bool touch_self)
 }
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 set_vpagesize_item( int item, const bool touch_self)
 {
 	if ( pagesize_item == item && !touch_self )
@@ -517,7 +517,7 @@ set_vpagesize_item( int item, const bool touch_self)
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 do_score_forward( const char score_ch)
 {
 	hypnogram[_cur_page] = score_ch;
@@ -527,7 +527,7 @@ do_score_forward( const char score_ch)
 }
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 do_score_back( const char score_ch)
 {
 	hypnogram[_cur_page] = score_ch;
@@ -537,7 +537,7 @@ do_score_back( const char score_ch)
 }
 
 size_t
-agh::ui::SScoringFacility::SChannel::
+SScoringFacility::SChannel::
 marquee_to_selection()
 {
 	if ( marquee_mstart < marquee_mend) {
@@ -565,7 +565,7 @@ marquee_to_selection()
 
 
 bool
-agh::ui::SScoringFacility::
+SScoringFacility::
 page_has_artifacts( const size_t p, const bool search_all) const
 {
 	for ( auto &H : channels )
@@ -581,7 +581,7 @@ page_has_artifacts( const size_t p, const bool search_all) const
 
 
 bool
-agh::ui::SScoringFacility::
+SScoringFacility::
 page_has_annotations( const size_t p, const SChannel& H) const
 {
 	int	half_pad_samples = skirting_run_per1 * vpagesize() * H.samplerate();
@@ -598,7 +598,7 @@ page_has_annotations( const size_t p, const SChannel& H) const
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 draw_score_stats() const
 {
 	gtk_label_set_markup(
@@ -617,7 +617,7 @@ draw_score_stats() const
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 draw_current_pos( const double x) const
 {
 	static const time_t epoch_clockhour = 3 * 60 * 60;
@@ -629,8 +629,9 @@ draw_current_pos( const double x) const
 			struct tm *ltime = localtime( &time_at_cur_pos);
 			char tmp[10];
 			strftime( tmp, 9, "%H:%M:%S", ltime);
-			snprintf_buf( "%s.%02d",
-				      tmp, (int)((clickt - floor(clickt)) * 100));
+			snprintf_buf(
+				"%s.%02d",
+				tmp, (int)((clickt - floor(clickt)) * 100));
 		} else
 			snprintf_buf( "--:--:--");
 	} else {
@@ -639,16 +640,15 @@ draw_current_pos( const double x) const
 		struct tm *ltime = localtime( &time_at_cur_pos);
 		char tmp[10];
 		strftime( tmp, 9, "%H:%M:%S", ltime);
-		snprintf_buf( "%s",
-			      tmp);
+		snprintf_buf( "%s", tmp);
 	}
 
-	gtk_button_set_label( eSFCurrentPos, __buf__);
+	gtk_button_set_label( eSFCurrentPos, global::buf);
 }
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 queue_redraw_all() const
 {
 	if ( suppress_redraw )
@@ -668,7 +668,7 @@ queue_redraw_all() const
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 load_montage()
 {
 	libconfig::Config conf;
@@ -713,7 +713,7 @@ load_montage()
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 save_montage()
 {
 	libconfig::Config conf;
@@ -740,7 +740,7 @@ save_montage()
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 sb_message( const string& msg) const
 {
 	gtk_statusbar_pop(  sbSF, sbSFContextIdGeneral);
@@ -748,7 +748,7 @@ sb_message( const string& msg) const
 }
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 sb_clear() const
 {
 	gtk_statusbar_pop(  sbSF, sbSFContextIdGeneral);
@@ -757,7 +757,7 @@ sb_clear() const
 
 
 const char* const
-	agh::ui::SScoringFacility::tooltips[2] = {
+	SScoringFacility::tooltips[2] = {
 	"<b>Page views:</b>\n"
 	"  Wheel:	adjust display scale;\n"
 	"  Ctrl+Wheel:	change scale for\n"
@@ -789,7 +789,7 @@ const char* const
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 set_tooltip( TTipIdx i) const
 {
 	gtk_widget_set_tooltip_markup( (GtkWidget*)lSFHint, tooltips[i]);
@@ -798,7 +798,7 @@ set_tooltip( TTipIdx i) const
 
 
 void
-agh::ui::SScoringFacility::
+SScoringFacility::
 update_main_menu_items()
 {
 	bool	all_draw_original[2] = {true, true},
diff --git a/src/aghermann/ui/sf/sf_cb.cc b/src/aghermann/ui/sf/sf_cb.cc
index 6db2e0e..ff7c7aa 100644
--- a/src/aghermann/ui/sf/sf_cb.cc
+++ b/src/aghermann/ui/sf/sf_cb.cc
@@ -14,8 +14,8 @@
 using namespace std;
 using namespace agh::ui;
 
-extern "C" {
 
+extern "C" {
 
 gboolean
 wSF_delete_event_cb(
diff --git a/src/aghermann/ui/sm/sm-construct.cc b/src/aghermann/ui/sm/sm-construct.cc
index b75bb59..4962558 100644
--- a/src/aghermann/ui/sm/sm-construct.cc
+++ b/src/aghermann/ui/sm/sm-construct.cc
@@ -17,10 +17,11 @@
 #include "sm_cb.hh"
 
 using namespace std;
+using namespace agh::ui;
 
 
 int
-agh::ui::SSessionChooser::
+SSessionChooser::
 construct_widgets()
 {
       // load glade
diff --git a/src/aghermann/ui/sm/sm.cc b/src/aghermann/ui/sm/sm.cc
index 907d908..adba916 100644
--- a/src/aghermann/ui/sm/sm.cc
+++ b/src/aghermann/ui/sm/sm.cc
@@ -24,10 +24,11 @@
 #include "sm_cb.hh"
 
 using namespace std;
+using namespace agh::ui;
 
 
 void
-agh::ui::SSession::
+SSession::
 get_session_stats()
 {
 	agh::fs::total_supported_sigfiles = 0;
@@ -45,7 +46,7 @@ get_session_stats()
 }
 
 
-agh::ui::SSessionChooser::
+SSessionChooser::
 SSessionChooser (const char* explicit_session)
       : filename (string (getenv("HOME")) + "/.config/aghermann/sessionrc"),
 	ed (nullptr)
@@ -60,7 +61,7 @@ SSessionChooser (const char* explicit_session)
 	try {
 		if ( have_explicit_dir ) {
 			char* canonicalized = canonicalize_file_name( explicit_session);
-			ed = new agh::ui::SExpDesignUI(
+			ed = new SExpDesignUI(
 				this, canonicalized);
 			set_unique_app_window( ed->wMainWindow);
 			free( canonicalized);
@@ -70,25 +71,25 @@ SSessionChooser (const char* explicit_session)
 			//set_unique_app_window( (GtkWindow*)wSessionChooser);
 
 		} else {
-			ed = new agh::ui::SExpDesignUI(
+			ed = new SExpDesignUI(
 				this, get_dir());
 			set_unique_app_window( ed->wMainWindow);
 		}
 	} catch (runtime_error ex) {
-		agh::ui::pop_ok_message( nullptr, "Huh", "%s", ex.what());
+		pop_ok_message( nullptr, "Huh", "%s", ex.what());
 
 		string new_experiment_dir = string (getenv("HOME")) + "/NewExperiment";
 		if ( agh::fs::mkdir_with_parents( new_experiment_dir.c_str()) ) {
-			agh::ui::pop_ok_message( nullptr, "Failed to create a new directory in your $HOME.",
+			pop_ok_message( nullptr, "Failed to create a new directory in your $HOME.",
 					       " There's nothing we can do about that.");
 		}
-		ed = new agh::ui::SExpDesignUI( this, new_experiment_dir);
+		ed = new SExpDesignUI( this, new_experiment_dir);
 		// if HOME is non-writable, then don't catch: it's too seriously broken
 	}
 }
 
 
-agh::ui::SSessionChooser::
+SSessionChooser::
 ~SSessionChooser()
 {
 	destruct_widgets();
@@ -102,7 +103,7 @@ agh::ui::SSessionChooser::
 
 
 int
-agh::ui::SSessionChooser::
+SSessionChooser::
 open_selected_session()
 {
 	assert (ed == nullptr);
@@ -111,7 +112,7 @@ open_selected_session()
 		return 1; // double check
 
 	try {
-		ed = new agh::ui::SExpDesignUI(
+		ed = new SExpDesignUI(
 			this, selected);
 		set_unique_app_window( ed->wMainWindow);
 
@@ -130,7 +131,7 @@ open_selected_session()
 
 
 void
-agh::ui::SSessionChooser::
+SSessionChooser::
 close_current_session()
 {
 	assert (ed);
@@ -144,7 +145,7 @@ close_current_session()
 
 
 void
-agh::ui::SSessionChooser::
+SSessionChooser::
 destruct_widgets()
 {
       // // destroy toplevels
@@ -159,21 +160,21 @@ destruct_widgets()
 
 
 void
-agh::ui::SSessionChooser::
+SSessionChooser::
 buf_on_status_bar( const bool)
 {
 	// gtk_statusbar_pop( sbSessionChooserStatusBar, sbChooserContextIdGeneral);
-	// gtk_statusbar_push( sbSessionChooserStatusBar, sbChooserContextIdGeneral, __buf__);
+	// gtk_statusbar_push( sbSessionChooserStatusBar, sbChooserContextIdGeneral, global::buf);
 	/// segfaults no matter what. Cannot call gtk_events_pending() from a handler.
 	// if ( ensure ) {
 	//  	g_signal_handler_block( bSessionChooserSelect, bSessionChooserSelect_clicked_cb_handler);
-	//   	agh::ui::gtk_flush();
+	//   	gtk_flush();
 	//  	g_signal_handler_unblock( bSessionChooserSelect, bSessionChooserSelect_clicked_cb_handler);
 	// }
 }
 
 void
-agh::ui::SSessionChooser::
+SSessionChooser::
 sb_progress_indicator( const char* current, const size_t n, const size_t i)
 {
 	snprintf_buf( "(%zu of %zu) %s", i, n, current);
@@ -183,7 +184,7 @@ sb_progress_indicator( const char* current, const size_t n, const size_t i)
 
 
 string
-agh::ui::SSessionChooser::
+SSessionChooser::
 get_selected_dir()
 {
 	auto selection = gtk_tree_view_get_selection( tvSessionChooserList);
@@ -211,7 +212,7 @@ get_selected_dir()
 
 
 string
-agh::ui::SSessionChooser::
+SSessionChooser::
 get_dir( const int idx) const
 {
 	GtkTreeIter iter;
@@ -244,7 +245,7 @@ get_dir( const int idx) const
 
 
 void
-agh::ui::SSessionChooser::
+SSessionChooser::
 read_sessionrc()
 {
 	sessions.clear();
@@ -283,7 +284,7 @@ read_sessionrc()
 
 
 void
-agh::ui::SSessionChooser::
+SSessionChooser::
 write_sessionrc() const
 {
 	try {
@@ -306,7 +307,7 @@ write_sessionrc() const
 
 
 void
-agh::ui::SSessionChooser::
+SSessionChooser::
 conditionally_enable_buttons()
 {
 	auto selection = gtk_tree_view_get_selection( tvSessionChooserList);
@@ -319,7 +320,7 @@ conditionally_enable_buttons()
 
 
 void
-agh::ui::SSessionChooser::
+SSessionChooser::
 _sync_list_to_model()
 {
 	gtk_list_store_clear( mSessionChooserList);
@@ -329,17 +330,17 @@ _sync_list_to_model()
 		snprintf_buf( "%d", (int)E.n_recordings);
 		gtk_list_store_set( mSessionChooserList, &iter,
 				    2, E.c_str(),
-				    1, __buf__,
+				    1, global::buf,
 				    -1);
-		strftime( __buf__, AGH_BUF_SIZE-1, "%c", localtime(&E.last_visited));
+		strftime( global::buf, AGH_BUF_SIZE-1, "%c", localtime(&E.last_visited));
 		gtk_list_store_set( mSessionChooserList, &iter,
-				    0, __buf__,
+				    0, global::buf,
 				    -1);
 	}
 }
 
 void
-agh::ui::SSessionChooser::
+SSessionChooser::
 _sync_model_to_list()
 {
 	sessions.clear();
diff --git a/src/aghermann/ui/sm/sm_cb.cc b/src/aghermann/ui/sm/sm_cb.cc
index 076ecf8..4c33a6c 100644
--- a/src/aghermann/ui/sm/sm_cb.cc
+++ b/src/aghermann/ui/sm/sm_cb.cc
@@ -72,7 +72,7 @@ bSessionChooserOpen_clicked_cb(
 {
 	auto& SC = *(SSessionChooser*)userdata;
 
-	agh::ui::SBusyBlock bb (SC.wSessionChooser);
+	SBusyBlock bb (SC.wSessionChooser);
 
 	int ret = SC.open_selected_session();
 
@@ -207,7 +207,7 @@ bSessionChooserRemove_clicked_cb(
 	gtk_tree_model_get( model, &iter,
 			    0, &entry,
 			    -1);
-	// SC.sessions.remove_if( [&entry]( agh::ui::SSession& S) { return S == entry; });
+	// SC.sessions.remove_if( [&entry]( SSession& S) { return S == entry; });
 	gtk_list_store_remove( SC.mSessionChooserList, &iter);
 	SC._sync_model_to_list();
 
diff --git a/src/aghermann/ui/ui++.cc b/src/aghermann/ui/ui++.cc
new file mode 100644
index 0000000..cb567d8
--- /dev/null
+++ b/src/aghermann/ui/ui++.cc
@@ -0,0 +1,63 @@
+/*
+ *       File name:  ui/ui++.cc
+ *         Project:  Aghermann
+ *          Author:  Andrei Zavada <johnhommer at gmail.com>
+ * Initial version:  2008-07-01
+ *
+ *         Purpose:  ui++
+ *
+ *         License:  GPL
+ */
+
+#include <gtk/gtk.h>
+
+#include <list>
+#include <string>
+#include "ui++.hh"
+
+using namespace std;
+
+namespace agh {
+namespace ui {
+
+template <> void
+SUIVar_<GtkListStore, list<string>>::up() const
+{
+	gtk_list_store_clear( w);
+	GtkTreeIter iter;
+	for ( auto& s : *v ) {
+		gtk_list_store_append( w, &iter);
+		gtk_list_store_set(
+			w, &iter,
+			1, s.c_str(),
+			-1);
+	}
+}
+template <> void
+SUIVar_<GtkListStore, list<string>>::down() const
+{
+	v->clear();
+	GtkTreeIter
+		iter;
+	gchar	*entry;
+	while ( gtk_tree_model_get_iter_first( (GtkTreeModel*)w, &iter) ) {
+		gtk_tree_model_get(
+			(GtkTreeModel*)w, &iter,
+			1, &entry,
+			-1);
+		v->emplace_back( entry);
+		g_free( entry);
+	}
+}
+
+
+}} // namespace agh::ui
+
+
+// Local Variables:
+// Mode: c++
+// indent-tabs-mode: 8
+// tab-width: 8
+// c-basic-offset: 8
+// End:
+
diff --git a/src/aghermann/ui/ui++.hh b/src/aghermann/ui/ui++.hh
index 2102687..3e3c4d5 100644
--- a/src/aghermann/ui/ui++.hh
+++ b/src/aghermann/ui/ui++.hh
@@ -31,6 +31,93 @@ using namespace std;
 namespace agh {
 namespace ui {
 
+
+// SGeometry
+
+struct SGeometry {
+	int x, y, w, h;
+	SGeometry()
+	      : x (-1), y (-1), w (-1), h (-1)
+		{}
+	SGeometry( int x_, int y_, int w_, int h_)
+	      : x (x_), y (y_), w (w_), h (h_)
+		{}
+	bool is_valid() const
+		{
+			return	(x > 0) && (x < 3000) &&
+				(y > 0) && (y < 3000) &&
+				(w > 1) && (w < 50000) &&
+				(h > 1) && (h < 50000);
+		}
+};
+
+
+
+// SManagedColor
+// connects colours to buttons and also provides useful shortcuts for cairo
+
+struct SManagedColor {
+	GdkRGBA clr;
+	GtkColorButton* btn;
+
+	SManagedColor& operator=( const SManagedColor&) = default;
+	void acquire()
+		{
+			gtk_color_chooser_get_rgba( (GtkColorChooser*)btn, &clr);
+		}
+
+	void set_source_rgb( cairo_t* cr) const
+		{
+			cairo_set_source_rgb( cr, clr.red, clr.green, clr.blue);
+		}
+	void set_source_rgba( cairo_t* cr, double alpha_override = NAN) const
+		{
+			cairo_set_source_rgba(
+				cr, clr.red, clr.green, clr.blue,
+				isfinite(alpha_override) ? alpha_override : clr.alpha);
+		}
+	void set_source_rgb_contrasting( cairo_t* cr) const
+		{
+			cairo_set_source_rgb(
+				cr, 1-clr.red, 1-clr.green, 1-clr.blue);
+		}
+	void set_source_rgba_contrasting( cairo_t* cr, double alpha_override = NAN) const
+		{
+			cairo_set_source_rgba(
+				cr, 1-clr.red, 1-clr.green, 1-clr.blue,
+				isfinite(alpha_override) ? alpha_override : clr.alpha);
+		}
+
+	void pattern_add_color_stop_rgba( cairo_pattern_t* cp, double at, double alpha_override = NAN) const
+		{
+			cairo_pattern_add_color_stop_rgba(
+				cp, at, clr.red, clr.green, clr.blue,
+				isfinite(alpha_override) ? alpha_override : clr.alpha);
+		}
+};
+
+
+enum class TGtkRefreshMode {
+	gtk, gdk
+};
+
+
+inline GdkColor
+contrasting_to( const GdkColor* c)
+{
+	GdkColor cc;
+	if ( c->red + c->green + c->blue < 65535*3/2 )
+		cc.red = cc.green = cc.blue = 65535;
+	else
+		cc.red = cc.green = cc.blue = 0;
+	return cc;
+}
+
+
+
+
+// SBusyBlock
+
 class SBusyBlock {
 	DELETE_DEFAULT_METHODS (SBusyBlock);
     public:
@@ -39,23 +126,24 @@ class SBusyBlock {
 		{
 			lock();
 		}
-	// poor ubuntu people
-	// SBusyBlock (GtkWindow* w)
-	//       : SBusyBlock ((GtkWidget*)w)
-	// 	{}
-	// SBusyBlock (GtkDialog* w)
-	//       : SBusyBlock ((GtkWidget*)w)
-	// 	{}
-	SBusyBlock (GtkWindow* w_)
-	      : w ((GtkWidget*)w_)
-		{
-			lock();
-		}
-	SBusyBlock (GtkDialog* w_)
-	      : w ((GtkWidget*)w_)
-		{
-			lock();
-		}
+	// delegating ctors
+	SBusyBlock (GtkWindow* w)
+	      : SBusyBlock ((GtkWidget*)w)
+		{}
+	SBusyBlock (GtkDialog* w)
+	      : SBusyBlock ((GtkWidget*)w)
+		{}
+
+	// SBusyBlock (GtkWindow* w_)
+	//       : w ((GtkWidget*)w_)
+	// 	{
+	// 		lock();
+	// 	}
+	// SBusyBlock (GtkDialog* w_)
+	//       : w ((GtkWidget*)w_)
+	// 	{
+	// 		lock();
+	// 	}
 
        ~SBusyBlock ()
 		{
@@ -75,6 +163,9 @@ class SBusyBlock {
 
 
 
+// SUIVar
+// binding GTK spinbuttons, comboboxes etc to variables
+
 class SUIVar_base {
     public:
 	virtual ~SUIVar_base ()
diff --git a/src/aghermann/ui/libcommon.cc b/src/aghermann/ui/ui.cc
similarity index 65%
rename from src/aghermann/ui/libcommon.cc
rename to src/aghermann/ui/ui.cc
index 94d9923..d458cfb 100644
--- a/src/aghermann/ui/libcommon.cc
+++ b/src/aghermann/ui/ui.cc
@@ -1,40 +1,22 @@
 /*
- *       File name:  ui/globals.cc
+ *       File name:  aghermann/ui/ui.cc
  *         Project:  Aghermann
  *          Author:  Andrei Zavada <johnhommer at gmail.com>
  * Initial version:  2008-07-01
  *
- *         Purpose:  common GTK+ variables; ui init
+ *         Purpose:  general-purpose GTK+ functions; ui init
  *
  *         License:  GPL
  */
 
-#include <cassert>
 #include <gtk/gtk.h>
 
 #include "common/alg.hh"
 #include "globals.hh"
-#include "misc.hh"
 #include "ui.hh"
-#include "ui++.hh"
 
 using namespace std;
-
-char	agh::ui::__buf__[AGH_BUF_SIZE];
-
-GString	*agh::ui::__ss__;
-
-GdkDevice
-	*agh::ui::__client_pointer__;
-
-UniqueApp
-	*agh::ui::__unique_app__;
-
-GtkWindow
-	*agh::ui::__main_window__;
-
-double	agh::ui::__hdpmm__,
-	agh::ui::__vdpmm__;
+using namespace agh::ui;
 
 #define AGH_UI_GRESOURCE_FILE "aghermann.gresource"
 
@@ -45,8 +27,8 @@ agh::ui::
 set_unique_app_window( GtkWindow* w)
 {
 	unique_app_watch_window(
-		agh::ui::__unique_app__,
-		agh::ui::__main_window__ = w);
+		global::unique_app,
+		global::main_window = w);
 }
 
 // own init
@@ -55,19 +37,21 @@ int
 agh::ui::
 prepare_for_expdesign()
 {
-	__ss__ = g_string_new( "");
-
       // tell me what they are
-	__client_pointer__ =
+	global::client_pointer =
 		gdk_device_manager_get_client_pointer(
 			gdk_display_get_device_manager( gdk_display_get_default()));
 
 	{
 		auto scr = gdk_screen_get_default();
-		__hdpmm__ = (double)gdk_screen_get_width ( scr) / gdk_screen_get_width_mm ( scr);
-		__vdpmm__ = (double)gdk_screen_get_height( scr) / gdk_screen_get_height_mm( scr);
-		printf( "Screen xdpmm is %g v, %g h\n", __hdpmm__, __vdpmm__);
-		gdk_screen_set_resolution( scr, (__hdpmm__ + __vdpmm__)/2);
+
+		using global::hdpmm;
+		using global::vdpmm;
+
+		hdpmm = (double)gdk_screen_get_width ( scr) / gdk_screen_get_width_mm ( scr);
+		vdpmm = (double)gdk_screen_get_height( scr) / gdk_screen_get_height_mm( scr);
+		printf( "Screen xdpmm is %g v, %g h\n", hdpmm, vdpmm);
+		gdk_screen_set_resolution( scr, (hdpmm + vdpmm)/2);
 	}
 
 	GResource
@@ -89,80 +73,6 @@ prepare_for_expdesign()
 
 
 
-// these are intended for durations, not timestamps
-void
-agh::ui::
-snprintf_buf_ts_d( const double d_)
-{
-	if ( d_ < 1. )
-		snprintf_buf_ts_h( d_ * 24);
-	else {
-		unsigned m_ = lroundf(d_*24*60*60) / 60,
-			m = (m_ % 60),
-			h = (m_ / 60) % 24,
-			d = (m_ / 60 / 24);
-		if ( h % 24 == 0 && m % 60 == 0 )
-			snprintf_buf( "%ud", d);
-		else if ( m % 60 == 0 )
-			snprintf_buf( "%ud%uh", d, h);
-		else
-			snprintf_buf( "%ud%uh%um", d, h, m);
-	}
-}
-
-void
-agh::ui::
-snprintf_buf_ts_h( const double h_)
-{
-	if ( h_ < 1. )
-		snprintf_buf_ts_m( h_ * 60);
-	else if ( h_ >= 24. )
-		snprintf_buf_ts_d( h_ / 24);
-	else {
-		unsigned m_ = lroundf( h_*60*60) / 60,
-			m = (m_ % 60),
-			h = (m_ / 60);
-		if ( m % 60 == 0 )
-			snprintf_buf( "%uh", h);
-		else
-			snprintf_buf( "%uh%um", h, m);
-	}
-}
-
-void
-agh::ui::
-snprintf_buf_ts_m( const double m_)
-{
-	if ( m_ < 1. )
-		snprintf_buf_ts_s( m_ * 60);
-	else if ( m_ >= 60. )
-		snprintf_buf_ts_h( m_ / 60);
-	else {
-		unsigned s_ = lroundf( m_*60) / 60,
-			s = (s_ % 60),
-			m = (s_ / 60);
-		if ( s % 60 == 0 )
-			snprintf_buf( "%um", m);
-		else
-			snprintf_buf( "%um%us", m, s);
-	}
-}
-
-void
-agh::ui::
-snprintf_buf_ts_s( const double s_)
-{
-	if ( s_ >= 60. )
-		snprintf_buf_ts_m( s_/60);
-	else
-		snprintf_buf( "%.2gs", s_);
-}
-
-
-
-
-
-
 
 
 // cairo
@@ -193,8 +103,8 @@ cairo_draw_signal( cairo_t *cr, const valarray<TFloat>& V,
 		   const ssize_t start, const ssize_t end,
 		   const size_t hspan, const float hoff, const float voff, const float scale,
 		   const unsigned short decimate,
-		   const agh::ui::TDrawSignalDirection direction,
-		   const agh::ui::TDrawSignalPathOption continue_path_option)
+		   const TDrawSignalDirection direction,
+		   const TDrawSignalPathOption continue_path_option)
 {
 	bool continue_path = continue_path_option == TDrawSignalPathOption::yes;
 	switch ( direction ) {
@@ -259,7 +169,6 @@ cairo_draw_envelope( cairo_t *cr, const valarray<TFloat>& V,
 
 
 
-
 // gtk
 
 
@@ -278,10 +187,14 @@ agh::ui::
 gtk_cell_layout_set_renderer( GtkComboBox *cb)
 {
 	GtkCellRenderer *r = gtk_cell_renderer_text_new();
-	gtk_cell_layout_pack_start( (GtkCellLayout*)cb, r, FALSE);
-	gtk_cell_layout_set_attributes( (GtkCellLayout*)cb, r,
-					"text", 0,
-					NULL);
+	gtk_cell_layout_pack_start(
+		(GtkCellLayout*)cb,
+		r,
+		FALSE);
+	gtk_cell_layout_set_attributes(
+		(GtkCellLayout*)cb, r,
+		"text", 0,
+		NULL);
 }
 
 void
@@ -363,47 +276,9 @@ set_cursor_busy( bool busy, GtkWidget *wid)
 	gdk_window_set_cursor( gtk_widget_get_window( wid), busy ? cursor_busy : cursor_normal);
 }
 
-
-namespace agh {
-namespace ui {
-
-template <> void
-SUIVar_<GtkListStore, list<string>>::up() const
-{
-	gtk_list_store_clear( w);
-	GtkTreeIter iter;
-	for ( auto& s : *v ) {
-		gtk_list_store_append( w, &iter);
-		gtk_list_store_set( w, &iter,
-				    1, s.c_str(),
-				    -1);
-	}
-}
-template <> void
-SUIVar_<GtkListStore, list<string>>::down() const
-{
-	v->clear();
-	GtkTreeIter
-		iter;
-	gchar	*entry;
-	while ( gtk_tree_model_get_iter_first( (GtkTreeModel*)w, &iter) ) {
-		gtk_tree_model_get( (GtkTreeModel*)w, &iter,
-				    1, &entry,
-				    -1);
-		v->emplace_back( entry);
-		g_free( entry);
-	}
-}
-
-
-}
-} // namespace agh::ui
-
-
 // Local Variables:
 // Mode: c++
 // indent-tabs-mode: 8
 // tab-width: 8
 // c-basic-offset: 8
 // End:
-
diff --git a/src/aghermann/ui/ui.hh b/src/aghermann/ui/ui.hh
index 56998fb..2f020af 100644
--- a/src/aghermann/ui/ui.hh
+++ b/src/aghermann/ui/ui.hh
@@ -4,8 +4,7 @@
  *          Author:  Andrei Zavada <johnhommer at gmail.com>
  * Initial version:  2008-04-28
  *
- *         Purpose: collected global variables for use after
- *                  gtk_main(), and __buf__ and __ss__ strings
+ *         Purpose: simple, C-style UI supporting functions
  *
  *         License:  GPL
  */
@@ -35,80 +34,10 @@ namespace agh {
 namespace ui {
 
 
-struct SGeometry {
-	int x, y, w, h;
-	SGeometry()
-	      : x (-1), y (-1), w (-1), h (-1)
-		{}
-	SGeometry( int x_, int y_, int w_, int h_)
-	      : x (x_), y (y_), w (w_), h (h_)
-		{}
-	bool is_valid() const
-		{
-			return	(x > 0) && (x < 3000) &&
-				(y > 0) && (y < 3000) &&
-				(w > 1) && (w < 50000) &&
-				(h > 1) && (h < 50000);
-		}
-};
-
-
-inline GdkColor
-contrasting_to( const GdkColor* c)
-{
-	GdkColor cc;
-	if ( c->red + c->green + c->blue < 65535*3/2 )
-		cc.red = cc.green = cc.blue = 65535;
-	else
-		cc.red = cc.green = cc.blue = 0;
-	return cc;
-}
+int prepare_for_expdesign();
 
+void set_unique_app_window( GtkWindow*);
 
-struct SManagedColor {
-	GdkRGBA clr;
-	GtkColorButton* btn;
-
-	SManagedColor& operator=( const SManagedColor&) = default;
-	void acquire()
-		{
-			gtk_color_chooser_get_rgba( (GtkColorChooser*)btn, &clr);
-		}
-
-	void set_source_rgb( cairo_t* cr) const
-		{
-			cairo_set_source_rgb( cr, clr.red, clr.green, clr.blue);
-		}
-	void set_source_rgba( cairo_t* cr, double alpha_override = NAN) const
-		{
-			cairo_set_source_rgba(
-				cr, clr.red, clr.green, clr.blue,
-				isfinite(alpha_override) ? alpha_override : clr.alpha);
-		}
-	void set_source_rgb_contrasting( cairo_t* cr) const
-		{
-			cairo_set_source_rgb(
-				cr, 1-clr.red, 1-clr.green, 1-clr.blue);
-		}
-	void set_source_rgba_contrasting( cairo_t* cr, double alpha_override = NAN) const
-		{
-			cairo_set_source_rgba(
-				cr, 1-clr.red, 1-clr.green, 1-clr.blue,
-				isfinite(alpha_override) ? alpha_override : clr.alpha);
-		}
-
-	void pattern_add_color_stop_rgba( cairo_pattern_t* cp, double at, double alpha_override = NAN) const
-		{
-			cairo_pattern_add_color_stop_rgba(
-				cp, at, clr.red, clr.green, clr.blue,
-				isfinite(alpha_override) ? alpha_override : clr.alpha);
-		}
-};
-
-
-enum class TGtkRefreshMode {
-	gtk, gdk
-};
 
 inline void
 gtk_flush()
@@ -133,11 +62,6 @@ cairo_draw_signal( cairo_t*,
 		   unsigned short decimate = 1,
 		   TDrawSignalDirection direction = TDrawSignalDirection::forward,
 		   TDrawSignalPathOption continue_path = TDrawSignalPathOption::yes);
-void
-cairo_draw_envelope( cairo_t*,
-		     const valarray<TFloat>&,
-		     ssize_t start, ssize_t end,
-		     size_t da_wd, float hdisp, float vdisp, float display_scale);
 
 inline void
 cairo_draw_signal( cairo_t *cr,
@@ -160,6 +84,12 @@ cairo_draw_signal( cairo_t *cr,
 			   continue_path);
 }
 
+void
+cairo_draw_envelope( cairo_t*,
+		     const valarray<TFloat>&,
+		     ssize_t start, ssize_t end,
+		     size_t da_wd, float hdisp, float vdisp, float display_scale);
+
 
 void
 cairo_put_banner( cairo_t *cr,
diff --git a/src/common/lang.hh b/src/common/lang.hh
index 76342e8..7289741 100644
--- a/src/common/lang.hh
+++ b/src/common/lang.hh
@@ -25,8 +25,6 @@ using namespace std;
 namespace agh {
 
 
-
-
 typedef unsigned long hash_t;
 
 
diff --git a/src/common/libcommon.cc b/src/common/libcommon.cc
index 38b2897..45f8cae 100644
--- a/src/common/libcommon.cc
+++ b/src/common/libcommon.cc
@@ -228,72 +228,72 @@ dhms_colon( double seconds, int dd)
 
 
 
-
-wstring
-agh::str::
-to_wstring( const string& in, const char* charset)
-{
-        wstring out;
-
-        size_t sufficient = ((in.size() + 1) * sizeof(wchar_t));
-
-        iconv_t cd = iconv_open( "WCHAR_T", charset);
-        if ( cd == (iconv_t) -1 )
-                return out;
-
-        char    *inptr  = const_cast<char*> (&in[0]), // iconv doesn't touch input, or does it?
-                *wrptr  = (char*)malloc( sufficient),
-                *wrptr0 = wrptr;
-
-        size_t  insize = in.size(),
-                avail  = sufficient;
-        size_t  nconv  = iconv( cd, &inptr, &insize, &wrptr, &avail);
-        if ( nconv != (size_t) -1 ) {
-                if ( avail >= sizeof(wchar_t) ) {
-                        *((wchar_t*) wrptr) = L'\0';
-                        out.assign( (wchar_t*)wrptr0);
-                }
-        }
-
-        free( (void*)wrptr0);
-        if ( iconv_close( cd) != 0 )
-                perror ("iconv_close");
-
-        return out;
-}
-
-
-string
-agh::str::
-from_wstring( const wstring& in, const char* charset)
-{
-        string out;
-
-        size_t sufficient = (in.size() * 4 + 1);
-
-        iconv_t cd = iconv_open( charset, "WCHAR_T");
-        if ( cd == (iconv_t) -1 )
-                return out;
-
-        char    *inptr = (char*) const_cast<wchar_t*> (&in[0]), // yes we can!
-                *wrptr = (char*)malloc( sufficient),
-                *wrptr0 = wrptr;
-
-        size_t  insize = in.size() * sizeof(wchar_t),
-                avail  = sufficient;
-        size_t  nconv  = iconv( cd, &inptr, &insize, &wrptr, &avail);
-        if ( nconv != (size_t) -1 ) {
-                if ( avail > 0 ) {
-                        *wrptr = '\0';
-                        out.assign( wrptr0);
-                }
-        }
-
-        free( wrptr0);
-        iconv_close( cd);
-
-        return out;
-}
+// uncomment on demand
+// wstring
+// agh::str::
+// to_wstring( const string& in, const char* charset)
+// {
+//         wstring out;
+
+//         size_t sufficient = ((in.size() + 1) * sizeof(wchar_t));
+
+//         iconv_t cd = iconv_open( "WCHAR_T", charset);
+//         if ( cd == (iconv_t) -1 )
+//                 return out;
+
+//         char    *inptr  = const_cast<char*> (&in[0]), // iconv doesn't touch input, or does it?
+//                 *wrptr  = (char*)malloc( sufficient),
+//                 *wrptr0 = wrptr;
+
+//         size_t  insize = in.size(),
+//                 avail  = sufficient;
+//         size_t  nconv  = iconv( cd, &inptr, &insize, &wrptr, &avail);
+//         if ( nconv != (size_t) -1 ) {
+//                 if ( avail >= sizeof(wchar_t) ) {
+//                         *((wchar_t*) wrptr) = L'\0';
+//                         out.assign( (wchar_t*)wrptr0);
+//                 }
+//         }
+
+//         free( (void*)wrptr0);
+//         if ( iconv_close( cd) != 0 )
+//                 perror ("iconv_close");
+
+//         return out;
+// }
+
+
+// string
+// agh::str::
+// from_wstring( const wstring& in, const char* charset)
+// {
+//         string out;
+
+//         size_t sufficient = (in.size() * 4 + 1);
+
+//         iconv_t cd = iconv_open( charset, "WCHAR_T");
+//         if ( cd == (iconv_t) -1 )
+//                 return out;
+
+//         char    *inptr = (char*) const_cast<wchar_t*> (&in[0]), // yes we can!
+//                 *wrptr = (char*)malloc( sufficient),
+//                 *wrptr0 = wrptr;
+
+//         size_t  insize = in.size() * sizeof(wchar_t),
+//                 avail  = sufficient;
+//         size_t  nconv  = iconv( cd, &inptr, &insize, &wrptr, &avail);
+//         if ( nconv != (size_t) -1 ) {
+//                 if ( avail > 0 ) {
+//                         *wrptr = '\0';
+//                         out.assign( wrptr0);
+//                 }
+//         }
+
+//         free( wrptr0);
+//         iconv_close( cd);
+
+//         return out;
+// }
 
 
 
diff --git a/src/common/string.hh b/src/common/string.hh
index 1df2510..a11f82f 100644
--- a/src/common/string.hh
+++ b/src/common/string.hh
@@ -12,6 +12,7 @@
 #ifndef _AGH_COMMON_STRING_H
 #define _AGH_COMMON_STRING_H
 
+#include <cstring>
 #include <string>
 #include <list>
 #include <sstream>
@@ -25,12 +26,14 @@ using namespace std;
 namespace agh {
 namespace str {
 
-string trim( const string& r0);
-string pad( const string& r0, size_t to);
+enum class TStrCmpCaseOption {
+	sensitive, insensitive
+};
 
 string sasprintf( const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
 
-
+string trim( const string& r0);
+string pad( const string& r0, size_t to);
 
 template <typename C>
 string
@@ -46,41 +49,54 @@ join( const C& l, const char* sep)
 	return recv.str();
 }
 
-list<string> tokens( const string& s_, const char* sep);
+list<string> tokens( const string&, const char* sep);
+
 inline
-list<string> tokens( const string& s_, char c)
+list<string>
+tokens( const string& s_, char c)
 {
 	char sep[2] = {c, '\0'};
-	return tokens( s_, sep);
+	return move(tokens( s_, sep));
 }
 
 list<string> tokens_trimmed( const string& s_, const char* sep);
+
 inline
-list<string> tokens_trimmed( const string& s_, char c)
+list<string>
+tokens_trimmed( const string& s_, char c)
 {
 	char sep[2] = {c, '\0'};
-	return tokens_trimmed( s_, sep);
+	return move(tokens_trimmed( s_, sep));
 }
 
 
 
+inline
+bool
+has_suffix( const string& s, const string& suffix,
+	    TStrCmpCaseOption case_option = TStrCmpCaseOption::sensitive)
+{
+	return	suffix.size() <= s.size() and
+		0 == (case_option == TStrCmpCaseOption::sensitive ? strcmp : strcasecmp)(
+			&s[s.size()-suffix.size()], &suffix[0]);
+}
+
 void decompose_double( double value, double *mantissa, int *exponent);
 
 
 
 string& homedir2tilda( string& inplace);
-string  homedir2tilda( const string& v);
+string  homedir2tilda( const string&);
 string& tilda2homedir( string& inplace);
-string  tilda2homedir( const string& v);
+string  tilda2homedir( const string&);
 
 string dhms( double seconds, int decimal_digits = 0) __attribute__ ((pure));
 string dhms_colon( double seconds, int decimal_digits = 0) __attribute__ ((pure));
 
 
-// unicode/wcs
-
-wstring to_wstring( const string&, const char* charset = "UTF-8");
-string from_wstring( const wstring&, const char* charset = "UTF-8");
+// unicode/wcs; uncomment on demand
+// wstring to_wstring( const string&, const char* charset = "UTF-8");
+// string from_wstring( const wstring&, const char* charset = "UTF-8");
 
 
 }
diff --git a/src/tools/edfhed-gtk.cc b/src/tools/edfhed-gtk.cc
index 7662aa5..b7eb251 100644
--- a/src/tools/edfhed-gtk.cc
+++ b/src/tools/edfhed-gtk.cc
@@ -146,7 +146,7 @@ main( int argc, char **argv)
 			printf( "Usage: %s file.edf\n", argv[0]);
 			return 0;
 		} else {
-			// agh::ui::pop_ok_message( NULL, "Usage: %s file.edf", argv[0]);
+			// pop_ok_message( NULL, "Usage: %s file.edf", argv[0]);
 			GtkWidget *f_chooser = gtk_file_chooser_dialog_new(
 				"edfhed-gtk: Choose a file to edit",
 				NULL,

-- 
Alioth's /git/debian-med/git-commit-notice on /srv/git.debian.org/git/debian-med/aghermann.git



More information about the debian-med-commit mailing list