/***************************************************************************
 * guitarpro.h: implementation of GuitarPro class
 *
 * This file is part of KTabEdit, a KDE tabulature editor
 *
 * copyright (C) 2003-2006 the KTabEdit development team <mrgwen@gmail.com>
 * copyright (C) 2002-2003 the KGuitar 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.
 ***************************************************************************/

#ifndef GUITARPRO_H
#define GUITARPRO_H

#include <QColor>
#include <QFile>
#include <QVector>

#include "fileexport.h"
#include "fileimport.h"

class TabBar;
class TabBarProperties;
class TabTimeEffect;
class TabMixTableChanges;
class TabChord;
class TrackMidiProperties;
class TabSong;
class TabTime;

/**
	The GuitarPro class. This class import and export guitar pro version 3 files.
*/
class GuitarPro : public FileImport, public FileExport
{
public:
	/**
		Contruct the GuitarPro class.
		The constructor inits two vectors (instruments and track properties)
	*/
	GuitarPro();
	
	/**
		Destructor the GuitarPro class.
		It does nothing.
	*/
	virtual ~GuitarPro();
	
	/**
		Load a guitar pro 3 file.
		@param fileName the name of the file
		@return the song
	*/
	bool loadFile(const QString& fileName);
	
	/**
		Save a guitar pro 3 file.
		@param fileName the name of the file
		@param tabSong the song
		@return true if the file is saved
	*/
	bool saveFile(const QString& fileName, const TabSong& tabSong);
private:
	void readHeader(TabSong*);
	void readMidi();
	void readBars(TabSong*);
	void readTracks(TabSong*);
	
	TabChord* readChords();
	void readChanges(TabMixTableChanges* mixer);
	void readEffects(TabTimeEffect* timeEffect);
	void readNotes(bool rest, uchar beatduration, TabTime* time, uint noteLength);
	
	unsigned char getBeatDuration();
	
	
	void dummies(uint);
	void writeDummies(uint i);
	
	unsigned char getByte();
	void writeByte(char c);
	
	unsigned long getLong();
	void writeLong(long l);
	
	void writeColor(const QColor &color);
	
	QString getString();
	void writeString(const QString &s);
	
	QString getStringNoInc(int i);
	void writeStringNoInc(const QString &s, int i);
	
	void writeHeader(const TabSong &);
	void writeMidiHeader(const TabSong &);
	void writeBarsHeader(const TabSong &);
	void writeTracksHeader(const TabSong &tabSong);
	
	void writeBars(uint ,const TabBar &);
	void writeTime(uint , const TabMixTableChanges &, const TabTime *);
	void writeBeatDuration(const TabTime *);
	void writeChord(const TabChord &);
	void writeEffects(const TabTimeEffect*);
	void writeChanges(const TabMixTableChanges &);
	void writeFrets(uint, const TabTime *);
	
	QFile mFile;
	
	QVector<TrackMidiProperties*> mInstruments;
	QVector<TabBarProperties*> mTrackProperties;
	
	unsigned int mNbbars, mNbtrack;
};

#endif
