#include "MidiData.h" #include "midi_parse.h" //kind declarations /* * $Id: MidiData.cpp,v 1.3 1999/03/30 17:12:37 baron Exp baron $ * * Copyright 1999 Kelvin W Sherlock */ MidiData::MidiData(int event_kind): BListItem(), time(-1), channel(-1), value(-1), kind(event_kind) { } MidiData::~MidiData() { } float MidiData::GetTime(void) const { return time; } int MidiData::GetChannel(void) const { return channel; } long MidiData::GetValue(void) const { return value; } void MidiData::SetTime(float t) { time = t; } void MidiData::SetChannel(int ch) { channel = ch; } void MidiData::SetValue(long v) { value = v; } void MidiData::SetKind(int event_kind) { kind = event_kind; } int MidiData::GetKind(void) const { return kind; } bool MidiData::Edit(void) { return 0; } void MidiData::DrawItem(BView *owner, BRect frame, bool complete) { BString S(""); char buffer[64]; if (complete || IsSelected()) { if (IsSelected()) owner->SetHighColor(216,216,216); else owner->SetHighColor(owner->ViewColor()); owner->FillRect(frame); } owner->SetHighColor(0, 0, 0); //black //Draw the time if (time != -1) { owner->MovePenTo(frame.left + 4, frame.bottom - 2); /* * time is a float == # of quarter notes since start of the song * */ //TODO - check the time signature ... int bar = (int)(time / 4) + 1; //assume 4/4 int qn = ((int)(time) % 4) + 1; int tmp = (int)(time * 1000) % 1000; sprintf(buffer, "%4d:%02d.%03d%c", bar, qn, tmp, 0); owner->DrawString(buffer); } if (channel != -1) { //Draw the channel S = ""; owner->MovePenTo(frame.left + 74, frame.bottom - 2); S << (uint32) (channel+1); owner->DrawString(S.String()); } } Note::Note(): MidiData(NOTE_ON), OnVelocity(-1), OffVelocity(-1), note(-1), length(-1) { } Note::~Note() { } void Note::SetOnVelocity(int v) { OnVelocity = v; } void Note::SetOffVelocity(int v) { OffVelocity = v; } void Note::SetNote(int n) { note = n; } void Note::SetNoteLength(float len) { length = len; } int Note::GetOnVelocity(void) const { return OnVelocity; } int Note::GetOffVelocity(void) const { return OffVelocity; } int Note::GetNote(void) const { return note; } float Note::GetNoteLength(void) const { return length; } /* * This is called to draw the item in a BList * */ //TODO - implement void Note::DrawItem(BView *owner, BRect frame, bool complete) { BString S(""); static char *notes[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" }; MidiData::DrawItem(owner, frame, complete); //type of event owner->MovePenTo(frame.left + 104, frame.bottom - 2); owner->DrawString("Note On"); //Draw The note S = ""; owner->MovePenTo(frame.left + 204, frame.bottom - 2); S += notes[GetNote() % 12]; S += " "; S <<(uint32)(GetNote() / 12); owner->DrawString(S.String()); //Draw the Velocity S = ""; owner->MovePenTo(frame.left + 254, frame.bottom - 2); S << (uint32) OnVelocity; owner->DrawString(S.String()); //Draw the length if (length != -1) //sanity check { S = ""; S << length; owner->MovePenTo(frame.left + 304, frame.bottom - 2); owner->DrawString(S.String()); } } //TODO - implement bool Note::Edit(void) { return false; } Text::Text(): MidiData(TEXT_EVENT), type(-1), txt("") { } Text::~Text() { } void Text::SetText(const BString& b) { txt = b; } const char *Text::GetText(void) const { return txt.String(); } void Text::SetType(int t) { type = t; } int Text::GetType(void) const { return type; } void Text::DrawItem(BView *owner, BRect frame, bool complete) { static char *tt[] = { NULL, "Text", // #1 "Copyright", "Sequence Name", "Instrument Name", "Lyric", "Marker", "Cue Point" }; BString S; MidiData::DrawItem(owner, frame, complete); //do the hilighting thing owner->SetHighColor(255,0,0); //red //draw the type of text if (type > 0 && type < 8) { owner->MovePenTo(frame.left + 104, frame.bottom - 2); S = tt[type]; owner->DrawString(S.String()); } //draw the first 40 chars (or so) if (txt.Length()) { S.SetTo(txt, MIN(txt.Length(), 40)); owner->MovePenTo(frame.left + 204, frame.bottom - 2); owner->DrawString(S.String()); } } bool Text::Edit(void) { return false; } Tempo::Tempo(): MidiData(SET_TEMPO) { } Tempo::~Tempo() { } void Tempo::DrawItem(BView *owner, BRect frame, bool complete) { char buffer[64]; float f; int t = GetValue(); MidiData::DrawItem(owner, frame, complete); owner->MovePenTo(frame.left + 104, frame.bottom - 2); owner->DrawString("Tempo"); // draw the tempo f = t ? (float)60000000.0/t : 0; sprintf(buffer, "%2.2f%c", f, 0); owner->MovePenTo(frame.left + 204, frame.bottom - 2); owner->DrawString(buffer); } ProgramChange::ProgramChange(): MidiData(PROGRAM_CHANGE) {} ProgramChange::~ProgramChange() {} extern char *Instruments[]; void ProgramChange::DrawItem(BView *owner, BRect frame, bool complete) { MidiData::DrawItem(owner, frame, complete); owner->SetHighColor(0,0,255); //blue owner->MovePenTo(frame.left + 104, frame.bottom -2 ); owner->DrawString("Program Change"); if (GetValue() != -1 && GetValue() < 128 && GetChannel() != 9) { owner->MovePenTo(frame.left + 204, frame.bottom - 2); owner->DrawString(Instruments[GetValue()]); } } PitchBend::PitchBend(): MidiData(PITCH_BEND) {} PitchBend::~PitchBend() {} void PitchBend::DrawItem(BView *owner, BRect frame, bool complete) { char buffer[64]; MidiData::DrawItem(owner, frame, complete); owner->SetHighColor(0, 100, 0); //ranger green owner->MovePenTo(frame.left + 104, frame.bottom - 2); owner->DrawString("Pitch Bend"); sprintf(buffer, "%d%c", GetValue(), 0); owner->MovePenTo(frame.left + 204, frame.bottom - 2); owner->DrawString(buffer); } KeySignature::KeySignature(): MidiData(KEY_SIGNATURE), minor(false), // C Major key(0) {} KeySignature::~KeySignature() {} bool KeySignature::GetMinor(void) const { return minor; } int KeySignature::GetKey(void) const { return key; } void KeySignature::SetKey(int k) { key = k; } void KeySignature::SetMinor(bool b) { minor = b; } void KeySignature::DrawItem(BView *owner, BRect frame, bool complete) { BString S(""); static char *kSharp[] = { "C Am ", "G Em ", "D Bm ", "A F#m", "E C#m", "B G#m", "F# D#m", "C# A#m", "G# Fm ", "D# Cm ", //TODO - are these right??? "A# Gm ", "F Dm " }; static char *kFlat[] = { "C Am ", "F Dm ", "Bb Gm ", "Eb Cm ", "Ab Fm ", "Db Bbm", "Gb Ebm", "B Abm", //TODO - see above "E Dbm", "A Gbm", "D Bm ", "G Em " }; MidiData::DrawItem(owner, frame, complete); owner->MovePenTo(frame.left + 104, frame.bottom - 2); owner->DrawString("Key"); S = ""; if (key >= 0 && key < 12) { char *cp = kSharp[key]; if (minor) cp += 3; S.SetTo(cp, 3); } else { register int k = 256 - key; if (k >= 0 && k < 12) { char *cp = kFlat[k]; if (minor) cp += 3; S.SetTo(cp, 3); } } owner->MovePenTo(frame.left + 204, frame.bottom - 2); owner->DrawString(S.String()); } ControlChange::ControlChange(): MidiData(CONTROL_CHANGE), controller(-1) {} ControlChange::~ControlChange() {} void ControlChange::SetController(int c) { controller = c; } int ControlChange::GetController(void) const { return controller; } void ControlChange::DrawItem(BView *owner, BRect frame, bool complete) { static char *names[] = { "Bank Select", "Modulation Controller", "Breath Controller", NULL, "Foot Controller", "Portamento Time", "Data Entry", "Volume", "Balance Controller", NULL, "PanPot", "Expression" }; BString S(""); MidiData::DrawItem(owner, frame, complete); owner->SetHighColor(255,0,255); owner->MovePenTo(frame.left + 104, frame.bottom - 2); owner->DrawString("Control Change"); if (controller != -1) { if (controller < 12 && names[controller]) S = names[controller]; else { S = "Controller #"; S << (uint32) controller; } owner->MovePenTo(frame.left + 204, frame.bottom - 2); owner->DrawString(S.String()); if (GetValue() != -1) { S = ""; S << (uint32) GetValue(); owner->MovePenTo(frame.left + 304, frame.bottom - 2); owner->DrawString(S.String()); } } } TimeSig::TimeSig(): MidiData(TIME_SIGNATURE), num(-1), den(-1), clock(-1), click(-1) {} TimeSig::~TimeSig() {} void TimeSig::SetNumerator(int n) { num = n; } void TimeSig::SetDenominator(int d) { den = d; } void TimeSig::SetClock(int c) { clock = c; } void TimeSig::SetClick(int c) { click = c; } int TimeSig::GetNumerator(void) const { return num; } int TimeSig::GetDenominator(void) const { return den; } int TimeSig::GetClick(void) const { return click; } int TimeSig::GetClock(void) const { return clock; } void TimeSig::DrawItem(BView *owner, BRect frame, bool complete) { BString S(""); MidiData::DrawItem(owner, frame, complete); owner->MovePenTo(frame.left + 104, frame.bottom - 2); owner->DrawString("Time Signature"); if (num != -1 && den != -1) { S <<(uint32) num; S += "/"; S <<(uint32) (1 << den); owner->MovePenTo(frame.left + 204, frame.bottom - 2); owner->DrawString(S.String()); } }