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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/**********************************************************************
Audacity: A Digital Audio Editor
NoteTrack.cpp
Dominic Mazzoni
**********************************************************************/
#include <wx/dc.h>
#include <wx/brush.h>
#include <wx/pen.h>
#include "AColor.h"
#include "NoteTrack.h"
#include "DirManager.h"
NoteTrack::NoteTrack(DirManager * projDirManager):
VTrack(projDirManager)
{
name = "Note Track";
mSeq = NULL;
mLen = 0.0;
mBottomNote = 24;
mVisibleChannels = 0xFFFF;
}
void NoteTrack::DrawLabelControls(wxDC & dc, wxRect & r)
{
int wid = 20;
int ht = 16;
if (r.height < ht * 4)
return;
int x = r.x + r.width / 2 - wid * 2;
int y = r.y + 4;
for (int row = 0; row < 4; row++)
for (int col = 0; col < 4; col++) {
int channel = row * 4 + col + 1;
wxRect box;
box.x = x + col * wid;
box.y = y + row * ht;
box.width = wid;
box.height = ht;
if (mVisibleChannels & (1 << (channel - 1))) {
AColor::MIDIChannel(&dc, channel);
dc.DrawRectangle(box);
AColor::LightMIDIChannel(&dc, channel);
dc.DrawLine(box.x, box.y, box.x + box.width - 1, box.y);
dc.DrawLine(box.x, box.y, box.x, box.y + box.height - 1);
AColor::DarkMIDIChannel(&dc, channel);
dc.DrawLine(box.x + box.width - 1, box.y,
box.x + box.width - 1, box.y + box.height);
dc.DrawLine(box.x, box.y + box.height - 1, box.x + box.width,
box.y + box.height - 1);
} else {
AColor::MIDIChannel(&dc, 0);
dc.DrawRectangle(box);
}
dc.DrawText(wxString::Format("%d", channel), box.x + 5,
box.y + 3);
}
}
bool NoteTrack::LabelClick(wxRect & r, int mx, int my, bool right)
{
int wid = 23;
int ht = 16;
if (r.height < ht * 4)
return false;
int x = r.x + r.width / 2 - wid * 2;
int y = r.y + 4;
int col = (mx - x) / wid;
int row = (my - y) / ht;
if (row < 0 || row >= 4 || col < 0 || col >= 4)
return false;
int channel = row * 4 + col;
if (right) {
if (mVisibleChannels == (1 << channel))
mVisibleChannels = 0xFFFF;
else
mVisibleChannels = (1 << channel);
} else
mVisibleChannels ^= (1 << channel);
return true;
}
double NoteTrack::GetMaxLen()
{
return mLen;
}
void NoteTrack::CalcLen()
{
int numEvents = mSeq->notes.len;
if (numEvents <= 0)
mLen = 0.0;
else {
mLen = 0.0;
for (int i = 0; i < numEvents; i++) {
if (mSeq->notes[numEvents - 1]->time > mLen)
mLen = mSeq->notes[numEvents - 1]->time;
if (mSeq->notes[numEvents - 1]->type == 'n') {
double endtime = mSeq->notes[numEvents - 1]->time +
((Note_ptr) mSeq->notes[numEvents - 1])->dur;
if (endtime > mLen)
mLen = endtime;
}
}
}
}
void NoteTrack::SetSequence(Seq_ptr seq)
{
if (mSeq)
delete mSeq;
mSeq = seq;
CalcLen();
}
|