/***************************************************************************
                          converter.h  -  description
                             -------------------
    begin                : Sam Nov 22 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.                                   *
 *                                                                         *
 ***************************************************************************/
#ifndef _LIBMELODY_CONVERT_H
#define _LIBMELODY_CONVERT_H
#include "types.h"
#include "Melody.h"

class ConverterParameter
{
public:
   ConverterParameter():
      m_tempo(500.0), 
      m_cut(0.0),
      m_iPhraseIdx(0), 
      m_bWriteSegmentation(false), 
      m_bIgnoreTempoChanges(false),
      m_nQuantLevel(24){}
   ConverterParameter(double tempo, double cut, int phrase, bool seg, bool ignoreTC, uint quant)
      :m_tempo(tempo)
      ,m_cut(cut)
      ,m_iPhraseIdx(phrase)
      ,m_bWriteSegmentation(seg)
      ,m_bIgnoreTempoChanges(ignoreTC)
      ,m_nQuantLevel(quant){}
   ConverterParameter(const ConverterParameter& param)
   {
      setParameter(param.m_tempo, param.m_cut, param.m_iPhraseIdx, param.m_bWriteSegmentation, param.m_bIgnoreTempoChanges, 
         param.m_nQuantLevel);
   }

   void setParameter(double tempo, double cut, int phrase, bool seg, bool ignoreTC, uint quant)
   {
      m_tempo = tempo;
      m_cut = cut;
      m_iPhraseIdx = phrase;
      m_bWriteSegmentation = seg;
      m_bIgnoreTempoChanges = ignoreTC;
      m_nQuantLevel = quant;
   }
   void        setTempo(double tempo){m_tempo = tempo; }
   void        setCut(double cut){m_cut = cut; }
   void        setPhraseIndex(uint idx){ m_iPhraseIdx = idx;}
   void        setWriteSegmentation(bool bWriteSegmentation){ m_bWriteSegmentation = bWriteSegmentation;}
   void        setQuantization(uint nQuant){ m_nQuantLevel = nQuant;}
   void        setIgnoreTempoChanges(bool bIgnoreTempoChanges){m_bIgnoreTempoChanges = bIgnoreTempoChanges;}
   double      getTempo(){return m_tempo; }
   double      getCut(){return m_cut; }
   int         getPhraseIndex(){ return m_iPhraseIdx;}
   bool        getWriteSegmentation(){ return m_bWriteSegmentation;}
   bool        getIgnoreTempoChanges(){ return m_bIgnoreTempoChanges;}
   uint        getQuantization(){ return m_nQuantLevel;}

protected:
   double      m_tempo;
   double      m_cut;
   int         m_iPhraseIdx;
   bool        m_bWriteSegmentation;
   bool        m_bIgnoreTempoChanges;
   uint        m_nQuantLevel;
};

class Converter : public ConverterParameter
{
public:
   Converter():m_sErrTxt(""),m_pMelody(0){}
   Converter(double tempo, double cut = 0):ConverterParameter(tempo, cut, -1, false, false, 24),m_sErrTxt(""),m_pMelody(0){}
   ~Converter()
   {
      if (m_pMelody) {
         delete m_pMelody;
         m_pMelody = 0;
      }
   }

   bool        read(const string& inFile, Format format);
   bool        write(const string& outFile, Format format);
   string      getErrorText(){ return m_sErrTxt;}
   void        setErrorText(const string& errTxt){ m_sErrTxt = errTxt;}
   Melody*     getMelody(){ return m_pMelody;}

protected:
   string         m_sErrTxt;
   Melody*        m_pMelody;
   
};

#endif
