/***************************************************************************
 * guitarpro4.h: implementation of GuitarPro4 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 GUITARPRO4_H
#define GUITARPRO4_H

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

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

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

/**
	The GuitarPro4 class. This class import and export guitar pro version 4 files.
*/
class GuitarPro4 : public FileImport, public FileExport
{
public:
	GuitarPro4();
	virtual ~GuitarPro4();
	
	bool loadFile(const QString &);
	bool saveFile(const QString &, const TabSong &);
private:
	void readHeader(TabSong*);
	void readMidi();
	void readBars(TabSong*);
	void readTracks(TabSong*);
	
	TabChord* readChords();
	void readChanges(TabMixTableChanges* mixer);
	void readEffectsOnBeat(TabTimeEffect* timeEffect);
	void readEffectsOnNote(TabNoteEffect* noteEffect);
	void readNotes(bool rest, uchar beatduration, TabTime* time, uint noteLength);
	
	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);
	
	QString getDelphiString();
	QString getChordName();
	unsigned char getBeatDuration();
	
	void writeHeader(const TabSong &);
	void writeMidiHeader(const TabSong &);
	void writeBarsHeader(const TabSong &);
	void writeTracksHeader(const TabSong &tabSong);
	
	void writeBars(uint ,const TabBar &);
	void writeTimes(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 &);
	
	QVector<TrackMidiProperties*> mInstruments;
	QVector<TabBarProperties*> mTrackProperties;
	
	QFile mFile;
	
	uint mNbbars, mNbtrack;
};

#endif
