aboutsummaryrefslogtreecommitdiff
path: root/composer/Pattern.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'composer/Pattern.cpp')
-rw-r--r--composer/Pattern.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/composer/Pattern.cpp b/composer/Pattern.cpp
new file mode 100644
index 0000000..69c60f4
--- /dev/null
+++ b/composer/Pattern.cpp
@@ -0,0 +1,81 @@
+#include "Pattern.hpp"
+
+#include <iostream>
+
+using std::cout;
+using std::cerr;
+using std::endl;
+
+Pattern::Pattern(int numRows, int numCols, string patternName)
+: name(patternName)
+{
+ Cell empty_cell;
+ Row empty_row;
+
+ SETSYMBOL(&empty_cell, gensym("empty"));
+
+ while(numCols-- > 0)
+ {
+ empty_row.push_back(empty_cell);
+ }
+
+ columns = empty_row.size();
+
+ while(numRows-- > 0)
+ {
+ Row row(empty_row);
+ rows.push_back(row);
+ }
+}
+
+void Pattern::print()
+{
+ cerr << "---- Pattern: " << name << " ----" << endl;
+
+ char buf[MAXPDSTRING];
+
+ for(unsigned int i = 0; i < rows.size(); i++)
+ {
+ cerr << " Row[" << i << "]: ";
+ for(unsigned int j = 0; j < rows[i].size(); j++)
+ {
+ if(j > 0) cerr << ", ";
+ atom_string(&rows[i][j], buf, MAXPDSTRING);
+ cerr << buf << endl;
+ }
+ }
+
+ cerr << "---- End pattern (" << name << ") ----" << endl;
+}
+
+void Pattern::resize(int numRows, int numCols)
+{
+ Cell empty_cell;
+ Row empty_row;
+
+ SETSYMBOL(&empty_cell, gensym("empty"));
+
+ while(numCols-- > 0)
+ {
+ empty_row.push_back(empty_cell);
+ }
+
+ rows.resize(numRows, empty_row);
+
+ for(unsigned int i = 0; i < rows.size(); i++)
+ {
+ rows[i].resize(empty_row.size(), empty_cell);
+ }
+
+ columns = empty_row.size();
+}
+
+void Pattern::setCell(int row, int col, Cell cell)
+{
+ rows[row][col] = cell;
+}
+
+Cell Pattern::getCell(int row, int col)
+{
+ return rows[row][col];
+}