From f8ac52e520aa5e20a256a3fd9a649b461f3afeef Mon Sep 17 00:00:00 2001 From: mescalinum Date: Fri, 25 Sep 2009 17:19:25 +0000 Subject: rewrite in C++ svn path=/trunk/externals/ffext/; revision=12451 --- composer/Pattern.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 composer/Pattern.cpp (limited to 'composer/Pattern.cpp') 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 + +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]; +} -- cgit v1.2.1