aboutsummaryrefslogtreecommitdiff
path: root/composer/Pattern.cpp
blob: 070838a85d9dca2f0b98cecdeb8fbf4b41328888 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "Pattern.hpp"

#include <iostream>

#include "Common.hpp"

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)
{
    row = WRAP(row, rows.size());
    col = WRAP(col, columns);
	rows[row][col] = cell;
}

Cell Pattern::getCell(int row, int col)
{
    row = WRAP(row, rows.size());
    col = WRAP(col, columns);
	return rows[row][col];
}