-
Notifications
You must be signed in to change notification settings - Fork 0
/
NoteStack.cpp
120 lines (98 loc) · 2.98 KB
/
NoteStack.cpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* NoteStack.cpp
*
* Created on: Jan 28, 2014
* Author: edwinrietmeijer
*/
#include "NoteStack.h"
namespace notestack {
NoteStack::NoteStack() : longestDur_ ( 0.0 ) {
}
void NoteStack::addNote( const int & newPitch, const double & newDuration, const double & newVelocity ) {
noteStackPitches_.push_back( newPitch );
noteStackDurations_.push_back( newDuration );
noteStackVelocities_.push_back( newVelocity );
if ( newDuration > longestDur_ ) {
longestDur_ = newDuration;
}
}
const double & NoteStack::getLongestDur() {
return longestDur_;
}
int NoteStack::getPitchVecSize() {
return noteStackPitches_.size();
}
int NoteStack::getDurVecSize() {
return noteStackDurations_.size();
}
int NoteStack::getVelVecSize() {
return noteStackVelocities_.size();
}
int NoteStack::getPitch( int pitchIndex ) {
if (! noteStackPitches_.empty() ) {
if( pitchIndex >= 0 && pitchIndex < noteStackPitches_.size() ) {
return noteStackPitches_.at( pitchIndex );
} else {
if ( pitchIndex >= noteStackPitches_.size() ) {
return noteStackPitches_.back();
} else {
return noteStackPitches_.front();
}
}
} else {
return 0;
}
}
double NoteStack::getDuration( int durIndex ) {
if( durIndex >= 0 && durIndex < noteStackDurations_.size() ) {
return noteStackDurations_.at( durIndex );
} else {
return longestDur_;
}
}
double NoteStack::getVelocity( int velIndex ) {
if( velIndex >= 0 && velIndex < noteStackVelocities_.size() ) {
return noteStackVelocities_.at( velIndex );
} else {
return 0.0;
}
}
int NoteStack::getLowestNoteIndex() {
int lowestNoteIndex = 0;
if (! noteStackPitches_.empty() ) {
int lowestNote = noteStackPitches_.front();
for ( int i = 1; i < noteStackPitches_.size(); ++i ) {
if ( noteStackPitches_.at( i ) < lowestNote ) {
lowestNote = noteStackPitches_.at( i );
lowestNoteIndex = i;
}
}
}
return lowestNoteIndex;
}
void NoteStack::merge( notestack::NoteStack * noteStackToMerge ) {
noteStackPitches_.insert( noteStackPitches_.end(), noteStackToMerge -> noteStackPitches_.begin(), noteStackToMerge -> noteStackPitches_.end() );
noteStackDurations_.insert( noteStackDurations_.end(), noteStackToMerge -> noteStackDurations_.begin(), noteStackToMerge -> noteStackDurations_.end() );
noteStackVelocities_.insert( noteStackVelocities_.end(), noteStackToMerge -> noteStackVelocities_.begin(), noteStackToMerge -> noteStackVelocities_.end() );
}
void NoteStack::clear() {
noteStackPitches_.clear();
noteStackDurations_.clear();
noteStackVelocities_.clear();
// noteStack_.clear();
}
void NoteStack::dump() {
for ( int i = 0; i < noteStackPitches_.size(); ++i ) {
std::cout << std::setw( 3 ) << noteStackPitches_.at( i ) << " " << noteStackDurations_.at( i ) << " " << noteStackVelocities_.at( i );
if ( i < noteStackPitches_.size() - 1 ) {
std::cout << " - ";
}
}
std::cout << std::endl;
}
//std::vector<customtypes::Note> & NoteStack::getStack() {
// return noteStack_;
//}
NoteStack::~NoteStack() {
}
} // namespace noteStack