/***************************************************************************
 * songkey.h: implementation of SongKey
 *
 * This file is part of KGuitar, a KDE tabulature editor
 *
 * copyright (C) 2003-2006 the KTabEdit development team <mrgwen@gmail.com>
 ***************************************************************************/

/***************************************************************************
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * See the file COPYING for more information.
 ***************************************************************************/
 
#include "songkey.h"

#include <QString>

SongKey::SongKey()
: k(7),
  minorClef(false)
{
}

SongKey::~SongKey()
{
}

void SongKey::clone(const SongKey* key)
{
	k = key->k;
	minorClef = key->minorClef;
}

void SongKey::setKey(QChar c)
{
	k = c;
}

QChar SongKey::key() const
{
	return k;
}

char SongKey::asciiCodeOfKey() const
{
	return k.toAscii();
}

QString SongKey::nameOfKey() const
{
	if (!minorClef) {
		switch (k.toAscii()) {
			case -7:
				return "Cb";
			case -6:
				return "Gb";
			case -5:
				return "Db";
			case -4:
				return "Ab";
			case -3:
				return "Eb";
			case -2:
				return "Bb";
			case -1:
				return "F";
			case 0:
				return "C";
			case 1:
				return "G";
			case 2:
				return "D";
			case 3:
				return "A";
			case 4:
				return "E";
			case 5:
				return "B";
			case 6:
				return "F#";
			case 7:
				return "C#";
		}
	} else {
		switch (k.toAscii()) {
			case -7:
				return "Abm";
			case -6:
				return "Ebm";
			case -5:
				return "Bbm";
			case -4:
				return "Fm";
			case -3:
				return "Cm";
			case -2:
				return "Gm";
			case -1:
				return "Dm";
			case 0:
				return "Am";
			case 1:
				return "Em";
			case 2:
				return "Bm";
			case 3:
				return "F#m";
			case 4:
				return "D#m";
			case 5:
				return "G#m";
			case 6:
				return "D#m";
			case 7:
				return "A#m";
		}
	}
	
	return "Bad key";
}

void SongKey::setMinor(bool i)
{
	minorClef = i;
}

bool SongKey::isMinor() const
{
	return minorClef;
}

bool SongKey::operator==(const SongKey& songKey) const
{
	return (minorClef == songKey.minorClef && k == songKey.k);
}

bool SongKey::operator!=(const SongKey& songKey) const
{
	return !(this->operator==(songKey));
}
