/***************************************************************************
                          converter.cpp  -  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.                                   *
 *                                                                         *
 ***************************************************************************/
#include "converter.h"
#include "FileReader.h"

bool Converter::read(const string& inFile, Format format)
{
   bool bRet = false;
   FileIOBase *pFileIO = FileIOFactory::Create(format);
   if(!pFileIO){
      setErrorText("Unable to create file reader.");
      return bRet;
   }
   pFileIO->setParameter(this);

   if(!pFileIO->read(inFile, &m_pMelody)){
      setErrorText(pFileIO->getErrorText());
   }
   else{
      bRet = true;
   }
   FileIOFactory::Destroy(&pFileIO);
   return bRet;
}

bool Converter::write(const string& outFile, Format format)
{
   bool bRet = false;
   FileIOBase *pFileIO = FileIOFactory::Create(format);
   if(!pFileIO){
      setErrorText("Unable to create file writer.");
      return bRet;
   }
   pFileIO->setParameter(this);
   if(!pFileIO->write(outFile, m_pMelody)){
      setErrorText(pFileIO->getErrorText());
   }
   else bRet = true;
   FileIOFactory::Destroy(&pFileIO);
   return bRet;
}

