// Note: Instrumentation statements are highlighted in green 

#include <vobject.hpp>
#pragma hdrstop
#include "fret.hpp"

///////////////////////////////////////////////////////////////////////////////
// Fret
///////////////////////////////////////////////////////////////////////////////

// Visual Member Definition 
VISIBILITY_START(Fret, "Fret", 0)
VVARIABLE(Fret, number, "Number", 0, 0)
VVARIABLE(Fret, xPosition, "Fret position", 0, 0)
VISIBILITY_END

Fret::Fret(void) :
  number(0),
  xPosition(0)
{

}

Fret::Fret(unsigned short fret_number, float x_position) :
  number(fret_number),
  xPosition(x_position)
{
}

Fret::~Fret(void)
{
}

Fret::Fret(const Fret &fret)
{
  *this = fret;
}

Fret & Fret::operator=(const Fret & fret)
{
  number = fret.number;
  xPosition = fret.xPosition;
  return *this;
}

bool Fret::operator==(const Fret & fret) const
{
  return number == fret.number;
}

// Override VObject's getPosition to allow access to object's positional information
unsigned short Fret::getPosition(float x_origin, float y_origin,
                                      float & object_x, float & object_y,
                                      unsigned short coord_type)
{
  object_x = xPosition - x_origin;
  object_y = 0 - y_origin;
  return 1;
}

// Override VObject's setPosition to allow modification of the object's positional information
unsigned short Fret::setPosition(float x_origin, float y_origin,
                                      float object_x, float object_y,
                                      unsigned short coord_type)
{
  xPosition = object_x + x_origin;
  return 1;
}

///////////////////////////////////////////////////////////////////////////////
// FretTable
///////////////////////////////////////////////////////////////////////////////

// Visual Member Definition 
VISIBILITY_START(FretTable, "FretTable", 0)
VVCONTAINER(FretTable, fretTable, "Fretted Note Table", 0, 0)
VISIBILITY_END

FretTable::FretTable(void)
{
}

FretTable::~FretTable(void)
{
}

FretTable::FretTable(const FretTable & fret_table)
{
  *this = fret_table;
}

FretTable & FretTable::operator=(const FretTable & fret_table)
{
  fretTable.erase(fretTable.begin(), fretTable.end()) ;
  FretVector::const_iterator fret_iter = fret_table.fretTable.begin();
  while (fret_iter != fret_table.fretTable.end()) {
    fretTable.push_back(*fret_iter);
    fret_iter++;
  }
  return *this;
}

void FretTable::AddFret(Fret & a_fret)
{
  fretTable.push_back(a_fret);
}

///////////////////////////////////////////////////////////////////////////////
// FrettedNote
///////////////////////////////////////////////////////////////////////////////

// Visual Member Definition 
VISIBILITY_START1(FrettedNote, Note, "Fretted Note", 0)
VVARIABLE(FrettedNote, guitarFret, "Fret", 0, 0)
VVARIABLE(FrettedNote, guitarString, "String", 0, 0)
VISIBILITY_END

FrettedNote::FrettedNote(void)
{
}

FrettedNote::FrettedNote(Note & note, Fret & guitar_fret, GuitarString & guitar_string) :
  Note(note),
  guitarFret(guitar_fret),
  guitarString(guitar_string)
{
}
FrettedNote::FrettedNote(const FrettedNote & fretted_note)
{
  *this = fretted_note;
}

FrettedNote::~FrettedNote(void)
{
}

FrettedNote & FrettedNote::operator=(const FrettedNote &fretted_note)
{
  Note::operator=(fretted_note);
  guitarFret = fretted_note.guitarFret;
  guitarString = fretted_note.guitarString;
  return  *this;
}

bool FrettedNote::operator==(const FrettedNote &fretted_note) const
{
  return ((guitarFret == fretted_note.guitarFret) && (guitarString == fretted_note.guitarString));
}

unsigned short FrettedNote::getPosition(float x_origin, float y_origin,
                                      float & object_x, float & object_y,
                                      unsigned short coord_type)
{
  object_x = guitarFret.xPosition - x_origin;
  object_y = guitarString.yPosition - y_origin;
  return 1;
}

unsigned short FrettedNote::setPosition(float x_origin, float y_origin,
                                      float object_x, float object_y,
                                      unsigned short coord_type)
{
  guitarFret.xPosition = object_x + x_origin;
  guitarString.yPosition = object_y + y_origin;
  return 1;
}

///////////////////////////////////////////////////////////////////////////////
// FrettedNoteTable
///////////////////////////////////////////////////////////////////////////////

// Visual Member Definition 
VISIBILITY_START(FrettedNoteTable, "FrettedNoteTable", 0)
VVCONTAINER(FrettedNoteTable, frettedNoteTable, "Fretted Note Table", 0, 0)
VISIBILITY_END

FrettedNoteTable::FrettedNoteTable(void)
{
}

FrettedNoteTable::~FrettedNoteTable(void)
{
}

FrettedNoteTable::FrettedNoteTable(const FrettedNoteTable & fretted_note_table)
{
  *this = fretted_note_table;
}

void FrettedNoteTable::populateEditView(void)
{
  frettedNoteTable.push_back(FrettedNote());
}

void FrettedNoteTable::depopulateEditView(void)
{
}

FrettedNoteTable & FrettedNoteTable::operator=(const FrettedNoteTable & fretted_note_table)
{
  frettedNoteTable.erase(frettedNoteTable.begin(), frettedNoteTable.end()) ;
  FrettedNoteVector::const_iterator fretted_note_iter = fretted_note_table.frettedNoteTable.begin();
  while (fretted_note_iter != fretted_note_table.frettedNoteTable.end()) {
    frettedNoteTable.push_back(*fretted_note_iter);
    fretted_note_iter++;
  }
  return *this;
}

void FrettedNoteTable::AddNote(FrettedNote & fretted_note_table)
{
  frettedNoteTable.push_back(fretted_note_table);
}

void FrettedNoteTable::Clear(void)
{
  frettedNoteTable.erase(frettedNoteTable.begin(), frettedNoteTable.end());
}

FrettedNote * FrettedNoteTable::FindFrettedNote(unsigned short midi_number)
{
  FrettedNoteVector::iterator fretted_note_iter = frettedNoteTable.begin();
  while (fretted_note_iter != frettedNoteTable.end()) {
    if ((*fretted_note_iter).midiNumber == midi_number)
      return &(*fretted_note_iter);
    fretted_note_iter++;
  }
  return NULL;
}




Copyright 2002-2007 Outerface Technologies, Inc.