changeset 776:32e66fcc4cb7 pitch-align

Make querying and setting the external alignment program or transform separate from selecting the alignment type - we need it to work that way for a clearer UI
author Chris Cannam
date Thu, 25 Jun 2020 09:32:01 +0100
parents 699b5b130ea2
children 87d33e79855b
files align/Align.cpp align/Align.h
diffstat 2 files changed, 113 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/align/Align.cpp	Mon Jun 01 17:13:09 2020 +0100
+++ b/align/Align.cpp	Thu Jun 25 09:32:01 2020 +0100
@@ -97,8 +97,7 @@
                   ModelId reference,
                   ModelId toAlign)
 {
-    QString additionalData;
-    AlignmentType type = getAlignmentPreference(additionalData);
+    AlignmentType type = getAlignmentPreference();
     
     std::shared_ptr<Aligner> aligner;
 
@@ -183,10 +182,11 @@
             throw std::logic_error("Not yet implemented"); //!!!
 
         case ExternalProgramAlignment: {
-            aligner = make_shared<ExternalProgramAligner>(doc,
-                                                          reference,
-                                                          toAlign,
-                                                          additionalData);
+            aligner = make_shared<ExternalProgramAligner>
+                (doc,
+                 reference,
+                 toAlign,
+                 getPreferredAlignmentProgram());
         }
         }
 
@@ -203,52 +203,68 @@
 }
 
 Align::AlignmentType
-Align::getAlignmentPreference(QString &additionalData)
+Align::getAlignmentPreference()
 {
     QSettings settings;
     settings.beginGroup("Alignment");
-
     QString tag = settings.value
         ("alignment-type", getAlignmentTypeTag(MATCHAlignment)).toString();
+    return getAlignmentTypeForTag(tag);
+}
 
-    AlignmentType type = getAlignmentTypeForTag(tag);
+QString
+Align::getPreferredAlignmentProgram()
+{
+    QSettings settings;
+    settings.beginGroup("Alignment");
+    return settings.value("alignment-program", "").toString();
+}
 
-    if (type == TransformDrivenDTWAlignment) {
-        additionalData = settings.value("alignment-transform", "").toString();
-    } else if (type == ExternalProgramAlignment) {
-        additionalData = settings.value("alignment-program", "").toString();
-    }
-
-    settings.endGroup();
-    return type;
+Transform
+Align::getPreferredAlignmentTransform()
+{
+    QSettings settings;
+    settings.beginGroup("Alignment");
+    QString xml = settings.value("alignment-transform", "").toString();
+    return Transform(xml);
 }
 
 void
-Align::setAlignmentPreference(AlignmentType type, QString additionalData)
+Align::setAlignmentPreference(AlignmentType type)
 {
     QSettings settings;
     settings.beginGroup("Alignment");
-
     QString tag = getAlignmentTypeTag(type);
     settings.setValue("alignment-type", tag);
+    settings.endGroup();
+}
 
-    if (type == TransformDrivenDTWAlignment) {
-        settings.setValue("alignment-transform", additionalData);
-    } else if (type == ExternalProgramAlignment) {
-        settings.setValue("alignment-program", additionalData);
-    }
+void
+Align::setPreferredAlignmentProgram(QString program)
+{
+    QSettings settings;
+    settings.beginGroup("Alignment");
+    settings.setValue("alignment-program", program);
+    settings.endGroup();
+}
 
+void
+Align::setPreferredAlignmentTransform(Transform transform)
+{
+    QSettings settings;
+    settings.beginGroup("Alignment");
+    settings.setValue("alignment-transform", transform.toXmlString());
     settings.endGroup();
 }
 
 bool
 Align::canAlign() 
 {
-    QString additionalData;
-    AlignmentType type = getAlignmentPreference(additionalData);
+    AlignmentType type = getAlignmentPreference();
 
     if (type == ExternalProgramAlignment) {
-        return ExternalProgramAligner::isAvailable(additionalData);
+        return ExternalProgramAligner::isAvailable
+            (getPreferredAlignmentProgram());
     } else {
         return TransformAligner::isAvailable();
     }
--- a/align/Align.h	Mon Jun 01 17:13:09 2020 +0100
+++ b/align/Align.h	Thu Jun 25 09:32:01 2020 +0100
@@ -23,6 +23,8 @@
 
 #include "Aligner.h"
 
+#include "transform/Transform.h"
+
 class AlignmentModel;
 class Document;
 
@@ -46,18 +48,79 @@
         LastAlignmentType = ExternalProgramAlignment
     };
 
+    /**
+     * Convert an alignment type to a stable machine-readable string.
+     */
     static QString getAlignmentTypeTag(AlignmentType type);
+
+    /**
+     * Convert an alignment type back from a stable machine-readable
+     * string.
+     */
     static AlignmentType getAlignmentTypeForTag(QString tag);
 
-    static AlignmentType getAlignmentPreference(QString &additionalData);
-    static void setAlignmentPreference(AlignmentType type,
-                                       QString additionalData = "");
+    /**
+     * Get the currently set alignment preference from the global
+     * application settings. If the returned preference is
+     * TransformDrivenDTWAlignment or ExternalProgramAlignment, then
+     * it will also be necessary to query
+     * getPreferredAlignmentTransform() or
+     * getPreferredAlignmentProgram() respectively in order to get the
+     * information needed to perform an alignment.
+     */
+    static AlignmentType getAlignmentPreference();
+    
+    /**
+     * Set the alignment preference to the global application
+     * settings. If the preference is TransformDrivenDTWAlignment or
+     * ExternalProgramAlignment, you may also wish to call
+     * setPreferredAlignmentTransform() or
+     * setPreferredAlignmentProgram() respectively.
+     */
+    static void setAlignmentPreference(AlignmentType type);
+
+    /**
+     * Get the external program associated with the
+     * ExternalProgramAlignment type, if any is set (an empty string
+     * otherwise). Note that this will return a value if any has ever
+     * been set, regardless of whether ExternalProgramAlignment is the
+     * currently chosen alignment type or not.
+     */
+    static QString getPreferredAlignmentProgram();
+
+    /**
+     * Set the external program associated with the
+     * ExternalProgramAlignment type. It is not necessary for the
+     * current preferred alignment type actually to be
+     * ExternalProgramAlignment in order to change this setting.  No
+     * validation is carried out on the argument - we don't verify
+     * that it actually is the path of a program, or anything else.
+     */
+    static void setPreferredAlignmentProgram(QString program);
+    
+    /**
+     * Get the transform associated with the
+     * TransformDrivenDTWAlignment type, if any is set (a default
+     * constructed Transform otherwise). Note that this will return a
+     * value if any has ever been set, regardless of whether
+     * TransformDrivenDTWAlignment is the currently chosen alignment
+     * type or not.
+     */
+    static Transform getPreferredAlignmentTransform();
+
+    /**
+     * Set the transform associated with the
+     * TransformDrivenDTWAlignment type. It is not necessary for the
+     * current preferred alignment type actually to be
+     * TransformDrivenDTWAlignment in order to change this setting.
+     */ 
+    static void setPreferredAlignmentTransform(Transform transform);
     
     /**
      * Align the "other" model to the reference, attaching an
      * AlignmentModel to it. Alignment is carried out by the method
-     * configured in the user preferences (either a plugin transform
-     * or an external process) and is done asynchronously. 
+     * configured in the user preferences (see
+     * getAlignmentPreference() etc) and is done asynchronously.
      *
      * Any errors are reported by firing the alignmentFailed
      * signal. Note that the signal may be fired during the call to
@@ -99,13 +162,11 @@
                            ModelId toAlign);
     
     /**
-     * Return true if the alignment facility is available (relevant
-     * plugin installed, etc).
+     * Return true if the preferred alignment facility is available
+     * (relevant plugin installed, etc).
      */
     static bool canAlign();
 
-    //!!! + check whether specific alignment types are available
-
 signals:
     /**
      * Emitted when an alignment is successfully completed. The