diff layer/LayerFactory.cpp @ 30:ea6fe8cfcdd5

* Add the Note layer for pianoroll-type display of note-type data * Complete the MIDI file importer (well, nearly -- it would be nice to be able to import the non-note data as other sorts of models, and that's not done yet). * Minor refactoring in RealTime etc
author Chris Cannam
date Fri, 10 Feb 2006 17:51:36 +0000
parents 0183ebb725ca
children 10ba9276a315
line wrap: on
line diff
--- a/layer/LayerFactory.cpp	Wed Feb 08 17:59:16 2006 +0000
+++ b/layer/LayerFactory.cpp	Fri Feb 10 17:51:36 2006 +0000
@@ -14,12 +14,14 @@
 #include "TimeRulerLayer.h"
 #include "TimeInstantLayer.h"
 #include "TimeValueLayer.h"
+#include "NoteLayer.h"
 #include "Colour3DPlotLayer.h"
 
 #include "model/RangeSummarisableTimeValueModel.h"
 #include "model/DenseTimeValueModel.h"
 #include "model/SparseOneDimensionalModel.h"
 #include "model/SparseTimeValueModel.h"
+#include "model/NoteModel.h"
 #include "model/DenseThreeDimensionalModel.h"
 
 LayerFactory *
@@ -44,6 +46,7 @@
     case TimeRuler:    return Layer::tr("Ruler");
     case TimeInstants: return Layer::tr("Time Instants");
     case TimeValues:   return Layer::tr("Time Values");
+    case Notes:        return Layer::tr("Notes");
     case Colour3DPlot: return Layer::tr("Colour 3D Plot");
 
     case MelodicRangeSpectrogram:
@@ -84,6 +87,10 @@
 	types.insert(TimeValues);
     }
 
+    if (dynamic_cast<NoteModel *>(model)) {
+	types.insert(Notes);
+    }
+
     // We don't count TimeRuler here as it doesn't actually display
     // the data, although it can be backed by any model
 
@@ -96,6 +103,7 @@
     LayerTypeSet types;
     types.insert(TimeInstants);
     types.insert(TimeValues);
+    types.insert(Notes);
     //!!! and in principle Colour3DPlot -- now that's a challenge
     return types;
 }
@@ -108,6 +116,7 @@
     if (dynamic_cast<const TimeRulerLayer *>(layer)) return TimeRuler;
     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 Colour3DPlotLayer *>(layer)) return Colour3DPlot;
     return UnknownLayer;
 }
@@ -121,6 +130,7 @@
     case TimeRuler: return "timeruler";
     case TimeInstants: return "instants";
     case TimeValues: return "values";
+    case Notes: return "notes";
     case Colour3DPlot: return "colour3d";
     default: return "unknown";
     }
@@ -135,6 +145,7 @@
     case TimeRuler: return "timeruler";
     case TimeInstants: return "timeinstants";
     case TimeValues: return "timevalues";
+    case Notes: return "notes";
     case Colour3DPlot: return "colour3dplot";
     default: return "unknown";
     }
@@ -148,6 +159,7 @@
     if (name == "timeruler") return TimeRuler;
     if (name == "timeinstants") return TimeInstants;
     if (name == "timevalues") return TimeValues;
+    if (name == "notes") return Notes;
     if (name == "colour3dplot") return Colour3DPlot;
     return UnknownLayer;
 }
@@ -170,6 +182,9 @@
     if (trySetModel<TimeValueLayer, SparseTimeValueModel>(layer, model))
 	return;
 
+    if (trySetModel<NoteLayer, NoteModel>(layer, model))
+	return;
+
     if (trySetModel<Colour3DPlotLayer, DenseThreeDimensionalModel>(layer, model))
 	return;
 
@@ -185,6 +200,9 @@
     } else if (layerType == TimeValues) {
 	return new SparseTimeValueModel(baseModel->getSampleRate(), 1,
 					0.0, 0.0, true);
+    } else if (layerType == Notes) {
+	return new NoteModel(baseModel->getSampleRate(), 1,
+			     0.0, 0.0, true);
     } else {
 	return 0;
     }
@@ -220,6 +238,10 @@
 	layer = new TimeValueLayer(view);
 	break;
 
+    case Notes:
+	layer = new NoteLayer(view);
+	break;
+
     case Colour3DPlot:
 	layer = new Colour3DPlotLayer(view);
 	break;