/***************************************************************************
                          Scales.cpp  -  description
                             -------------------
    begin                : Fre Aug 15 2003
    copyright            : (C) 2003 by klaus frieler
    email                : kgf@omniversum.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/
#include "Scales.h"
#include "Types.h"


uint const Scale::major[]   =  { 0, 2, 4, 5, 7, 9,   11    };
uint const Scale::minor1[]  =  { 0, 2, 3, 5, 7, 8,   10    };
uint const Scale::minor2[]  =  { 0, 2, 3, 5, 7, 9,   11    };
uint const Scale::minor3[]  =  { 0, 2, 3, 5, 7, 8, 9,10, 11};
uint const Scale::chromatic[]  =  { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};

Scale::Scale(uint scale)
{
   setScale(scale);
}



void Scale::setScale(uint scale)
{
   uint const* pScale = 0;
   m_sz = 0;
   switch(scale){
      case MAJOR:
         pScale = Scale::major;
         m_sz = 7;
      break;
      case MINOR1:
         pScale = Scale::minor1;
         m_sz = 7;
      break;
      case MINOR2:
         pScale = Scale::minor2;
         m_sz = 7;
      break;
      case MINOR3:
         pScale = Scale::minor3;
         m_sz = 9;
      break;
      case CHROMATIC:
         pScale = Scale::chromatic;
         m_sz = 12;
      break;
   
   }
   if(pScale){
      for(uint i = 0 ; i<m_sz; ++i){
         m_scale.push_back(pScale[i]);
      }
   }
}

uint Scale::getScaleDegree(uint pitchClass)
{
   for(uint i = 0; i<m_scale.size();++i){
      if(m_scale[i] == pitchClass)
         return i+1;
   }
   return 0;
}

vector<uint> Scale::getScaleAbsolute(uint baseTone, uint mode)
{
   vector<uint> scale;
   setScale(mode);
   for(uint i = 0; i<m_scale.size(); ++i){
      uint pitch = (m_scale[i] + baseTone) % 12;
   }
   return scale;
}
