summaryrefslogtreecommitdiff
path: root/chordNote.cpp
blob: 1fa754959305c5fb7cf20de2ddb5e20e45575a05 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "chordNote.h"
#include <iostream>

// Constructors, Destructors & Operators {{{

// All notes are known
ChordNote::ChordNote(bool notes[5], int start, int end):
  start(start), end(end){
  for(int i=0; i<5; i++) this->notes[i] = notes[i];
};

// Used when chords are created from chartfiles
ChordNote::ChordNote(int note, int start, int end):
  start(start), end(end){
  for(int i=0; i<5; i++) (notes[i] = (i==note));
};

// Copy constructor
ChordNote::ChordNote(const ChordNote& chord):
  start(chord.start), end(chord.end){
  for(int i=0; i<5; i++) notes[i] = chord.notes[i];
};

// Destructor
ChordNote::~ChordNote() {};

// Assignment operator
ChordNote& ChordNote::operator=(const ChordNote& other) {
  std::copy(other.notes, other.notes + 5, notes);
  const_cast<int&>(start) = other.start;
  const_cast<int&>(end) = other.end;
  return *this;
}

// }}}

// Getters {{{

bool* ChordNote::getNotes(){
  return notes;
};

int ChordNote::getStart(){
  return start;
}

int ChordNote::getEnd(){
  return end;
}


int ChordNote::getRenderStart() {
  return renderStart;
};

// }}}

// Setters {{{

void ChordNote::setRenderStart(int renderTime) {
  renderStart = start - renderTime;
}

// }}}

// Modifiers {{{

// Toggle a note on/off
bool ChordNote::toggle(int note){
  notes[note] = !notes[note];
  return notes[note];
}

// Merge two chords together
void ChordNote::merge(ChordNote chord){
  for (int i=0; i<5; i++) {
    this->notes[i] = this->notes[i] || chord.has(i);
  }
}

// }}}

// Misc {{{

// Check if a note is on (used in merge)
bool ChordNote::has(int note){
  return notes[note];
}

// Print Info about the chord (used for debugging)
void ChordNote::print(){
  std::cout << "ChordNote: ";
  for(int i=0; i<5; i++) std::cout << (notes[i])? "T" : "F";
  std::cout << "Start: " << start << " End: " << end << std::endl;
}

// Trim all timings to milliseconds
void ChordNote::trim(){
  start = start/1000000;
  end   = end/1000000;
}

// }}}

// vim: syntax=cpp.doxygen