#!/bin/bash

# small help-program which scans all includes in current directory for
# includes which contain classes inheriting from soundGenerator and
# then it creates a cpp-file with the plugin-management-function of class
# soundGenerator


classnames=""
includes=""

for i in `find | grep ".h"` ; do
	line=`cat $i | grep "public soundGenerator"`
	if [ ! -z "$line" ] ; then
		includes="$includes `echo $i | rev | cut -d '/' -f1 | rev`"
		classnames="$classnames `echo $line | cut -d " " -f2`"
	fi
done

echo "// WARNING: This file has been automatically generated and will be regenerated,"
echo "// so please don't edit!"
echo
echo "#include \"qt3support.h\""
echo
echo "#ifdef QT4"
echo
echo "#include <Qt/QtXml>"
echo "#include <QMessageBox>"
echo
echo "#else"
echo
echo "#include <qdom.h>"
echo "#include <qmessagebox.h>"
echo
echo "#endif"
echo
echo "#include \"sound_generator.h\""
echo "#include \"channel_track.h\""
echo "#include \"settings.h\""
echo
for i in $includes ; do
	echo "#include \"$i\""
done
echo
echo
echo "soundGenerator * soundGenerator::pluginInstance( const QString & _node_name,"
echo "						channelTrack * _channel_track )"
echo "{"
for i in $classnames ; do
	echo "	if( _node_name == $i::s_pluginNodeName )"
	echo "	{"
	echo "		return( new $i( _channel_track ) );"
	echo "	}"
done
echo

echo "	QMessageBox::information( NULL, tr( \"Error while loading plugin\" ),"
echo "					tr(\"The %1-plugin wasn't found! \""
echo "						\"Using AudioFileProcessor with \""
echo "						\"default settings instead.\\n\""
echo "					).arg( _node_name ),"
echo "					QMessageBox::Ok |"
echo "						QMessageBox::Default );"
echo
echo "	audioFileProcessor * afp = new audioFileProcessor( _channel_track );"
echo "	afp->loadSettings( audioFileProcessor::defaultSettings() );"
echo "	return( afp );"
echo "}"

exit 0
