diff layer/LayerFactory.cpp @ 411:96e4d7b9e165

* Add region model and layer; improve assignment of model types to feature extraction transforms with duration
author Chris Cannam
date Thu, 18 Sep 2008 16:08:14 +0000
parents d58701996fae
children 1fe7951a61e8
line wrap: on
line diff
--- a/layer/LayerFactory.cpp	Thu Sep 18 12:09:32 2008 +0000
+++ b/layer/LayerFactory.cpp	Thu Sep 18 16:08:14 2008 +0000
@@ -21,6 +21,7 @@
 #include "TimeInstantLayer.h"
 #include "TimeValueLayer.h"
 #include "NoteLayer.h"
+#include "RegionLayer.h"
 #include "TextLayer.h"
 #include "ImageLayer.h"
 #include "Colour3DPlotLayer.h"
@@ -35,6 +36,7 @@
 #include "data/model/SparseOneDimensionalModel.h"
 #include "data/model/SparseTimeValueModel.h"
 #include "data/model/NoteModel.h"
+#include "data/model/RegionModel.h"
 #include "data/model/TextModel.h"
 #include "data/model/ImageModel.h"
 #include "data/model/DenseThreeDimensionalModel.h"
@@ -71,6 +73,7 @@
     case TimeInstants: return Layer::tr("Time Instants");
     case TimeValues:   return Layer::tr("Time Values");
     case Notes:        return Layer::tr("Notes");
+    case Regions:      return Layer::tr("Regions");
     case Text:         return Layer::tr("Text");
     case Image:        return Layer::tr("Images");
     case Colour3DPlot: return Layer::tr("Colour 3D Plot");
@@ -152,12 +155,16 @@
 
     if (dynamic_cast<SparseTimeValueModel *>(model)) {
 	types.insert(TimeValues);
-    
-}
+    }
+
     if (dynamic_cast<NoteModel *>(model)) {
 	types.insert(Notes);
     }
 
+    if (dynamic_cast<RegionModel *>(model)) {
+	types.insert(Regions);
+    }
+
     if (dynamic_cast<TextModel *>(model)) {
 	types.insert(Text);
     }
@@ -183,6 +190,7 @@
     types.insert(TimeInstants);
     types.insert(TimeValues);
     types.insert(Notes);
+    types.insert(Regions);
     types.insert(Text);
     types.insert(Image);
     //!!! and in principle Colour3DPlot -- now that's a challenge
@@ -198,6 +206,7 @@
     if (dynamic_cast<const TimeInstantLayer *>(layer)) return TimeInstants;
     if (dynamic_cast<const TimeValueLayer *>(layer)) return TimeValues;
     if (dynamic_cast<const NoteLayer *>(layer)) return Notes;
+    if (dynamic_cast<const RegionLayer *>(layer)) return Regions;
     if (dynamic_cast<const TextLayer *>(layer)) return Text;
     if (dynamic_cast<const ImageLayer *>(layer)) return Image;
     if (dynamic_cast<const Colour3DPlotLayer *>(layer)) return Colour3DPlot;
@@ -216,6 +225,7 @@
     case TimeInstants: return "instants";
     case TimeValues: return "values";
     case Notes: return "notes";
+    case Regions: return "regions";
     case Text: return "text";
     case Image: return "image";
     case Colour3DPlot: return "colour3d";
@@ -237,6 +247,7 @@
     case TimeInstants: return "timeinstants";
     case TimeValues: return "timevalues";
     case Notes: return "notes";
+    case Regions: return "regions";
     case Text: return "text";
     case Image: return "image";
     case Colour3DPlot: return "colour3dplot";
@@ -257,6 +268,7 @@
     if (name == "timeinstants") return TimeInstants;
     if (name == "timevalues") return TimeValues;
     if (name == "notes") return Notes;
+    if (name == "regions") return Regions;
     if (name == "text") return Text;
     if (name == "image") return Image;
     if (name == "colour3dplot") return Colour3DPlot;
@@ -292,6 +304,9 @@
     if (trySetModel<NoteLayer, NoteModel>(layer, model))
 	return;
 
+    if (trySetModel<RegionLayer, RegionModel>(layer, model))
+	return;
+
     if (trySetModel<TextLayer, TextModel>(layer, model))
 	return;
 
@@ -320,6 +335,8 @@
 	return new SparseTimeValueModel(baseModel->getSampleRate(), 1, true);
     } else if (layerType == Notes) {
 	return new NoteModel(baseModel->getSampleRate(), 1, true);
+    } else if (layerType == Regions) {
+	return new RegionModel(baseModel->getSampleRate(), 1, true);
     } else if (layerType == Text) {
 	return new TextModel(baseModel->getSampleRate(), 1, true);
     } else if (layerType == Image) {
@@ -389,6 +406,10 @@
 	layer = new NoteLayer;
 	break;
 
+    case Regions:
+	layer = new RegionLayer;
+	break;
+
     case Text:
 	layer = new TextLayer;
 	break;
@@ -492,15 +513,18 @@
     bool haveFrame = false;
     bool haveValue = false;
     bool haveDuration = false;
+    bool haveLevel = false;
 
     for (Clipboard::PointList::const_iterator i = contents.begin();
          i != contents.end(); ++i) {
         if (i->haveFrame()) haveFrame = true;
         if (i->haveValue()) haveValue = true;
         if (i->haveDuration()) haveDuration = true;
+        if (i->haveLevel()) haveLevel = true;
     }
 
-    if (haveFrame && haveValue && haveDuration) return Notes;
+    if (haveFrame && haveValue && haveDuration && haveLevel) return Notes;
+    if (haveFrame && haveValue && haveDuration) return Regions;
     if (haveFrame && haveValue) return TimeValues;
     return TimeInstants;
 }