/* ============================================================
 * File  : rendering.cpp
 * Author: Stephane Gibault
 * Date  : Sun Feb 4 2007
 * Description :
 *
 * 
 *  (C) 2007 by Stephane Gibault
 *
 * 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, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * ============================================================ */

#include <QtGui>
#include "mainfrm.h"

void mainfrm::f_go_render_dvd()
{
	if ( frame_iso->isVisible() == false )
	{
		if ( nbre_medias > 0 )
		{
			f_save_widgetonmenu();

			int wl_int_001 = 0;
			int wl_int_002;
			int wl_int_003 = 0;

			while ( wl_int_003 == 0 )
			{
				wl_int_002 = 0;
				while ( table_menus[wl_int_001][wl_int_002][0] != "$$$" && wl_int_003 == 0 )
				{
					if ( table_menus[wl_int_001][wl_int_002][5] != "" && table_menus[wg_int_001][wl_int_002][5] != wg_str_int_002 && table_menus[wl_int_001][wl_int_002][5].mid(0,3) != "!M!" )
					{
						wl_int_003=1;
					}
					wl_int_002++;
				}
				wl_int_001++;
				if ( wl_int_001 > nbre_menuth && wl_int_003 == 0 )
				{
					wl_int_003 = 2;
				}
			}
			if ( wl_int_003 == 2 )
			{
				QMessageBox::information(this, name_application, tr("Aucun bouton de votre DVD ne pointe vers un de vos media. Ceci est interdit."));
				return;
			}

			if ( hdl_current_menu != 0 )
			{
				//hdl_current_menu->is_select = 0;
				hdl_current_menu = 0;
			}

			// *** BLOCAGE DES BARRES D'OUTILS ***
			must_update = 0;
			combo_quoilire_media->setCurrentIndex(0);
			combo_quoilire_media_chapitre->setCurrentIndex(0);
			combo_quoilire_menu->setCurrentIndex(0);
			combo_quoilire_media->setDisabled(true);
			bt_tool_1->setDisabled(true);
			bt_tool_2->setDisabled(true);
			bt_tool_3->setDisabled(true);
			bt_tool_4->setDisabled(true);
			bt_bt_img->setDisabled(true);
			dial_alpha_menu->setDisabled(true);
			bttxt->setDisabled(true);
			frame_th_msk_idea->setDisabled(true);
			combo_quoilire_media->setDisabled(true);
			check_anim->setDisabled(true);
			combo_quoilire_media_chapitre->setDisabled(true);
			combo_quoilire_menu->setDisabled(true);
			must_update = 1;
			//
			hdl_current_menu = 0;
			bt_cancel_encoding->setEnabled(true);
			step_render = 0;
			iserror = 0;
			logstring = "";
			progress_current_dvd->setValue(0);
			progress_current_dvd_2->setValue(0);
			progress_current_dvd_3->setMaximum(100);
			progress_current_dvd_3->setMinimum(0);
			progress_current_dvd_3->setValue(0);
			progress_current_dvd_4->setMaximum(100);
			progress_current_dvd_4->setValue(0);
			thread_ani->hdlmsk = mask_interface;
			thread_ani->progress = 2;
			thread_ani->sens = 1;
			thread_ani->isrender = 1;
			mask_interface->show();
			mask_interface->raise();

			label_14->setText(tr("Progression de la video actuelle"));
			label_29->setText(tr("Generation des menus"));
			label_39->setText(tr("Finalisation du DVD"));

			if ( combo_format_audio->currentIndex() == 0 )
			{
				global_audio = "mp2";
			}
			else
			{
				global_audio = "ac3";
			}

			frame_render->show();
			frame_render->raise();
			QTimer::singleShot(10, this, SLOT(f_run_ani()));
		}
		else
		{
			QMessageBox::information(this, name_application, tr("Vous devez ajouter au moins un media a votre projet."));
		}
	}
	else
	{
		QMessageBox::information(this, name_application, tr("Un traitement est encore en cours. Veuillez patienter."));
	}
}

void mainfrm::f_make_menus()
{
	// *** SAUVEGARDE DU MENU EN COURS D'EDITION ***

	step_render = 1;
	// ***************************************
	// *** GENERATION DES IMAGES DE MEDIAS ***
	// ***************************************
	wg_int_001 = 0;
	int rotation;
	double angleradian;
	int menu_width;
	int menu_height;

	int wl_int_001;
	int wl_int_002;
	int wl_int_003;
	int wl_int_004;
	int wl_int_005;
	int wl_int_006;

	int wl_int_010; // *** MASK CLIQUE ***
	int wl_int_011;
	int wl_int_012;

	int wl_int_013; // *** MASK SURVOLE ***
	int wl_int_014;
	int wl_int_015;

	int wl_int_016; // *** OPACITE DES OVERLAYS ***

	int wl_int_031; // *** SPECIAL POUR ZONE TEXTE *** 
	int wl_int_032; // *** NE PAS UTILISER POUR    ***
	int wl_int_033; // *** AUTRE CHOSE             ***
	int wl_int_034; // *** BOUCLE GIF              ***

	int shadow_opacity = 0;
	int shadow_angle = 0;

	int wl_x;
	int wl_y;

	int wl_cpt_save;

	int isanim;
	int bcle_render;

	QString wl_str_001;
	QString wl_str_002;
	QString wl_str_003;
	QString wl_str_004; // *** RESERVE BOUTONS ANIMES ***
	QString wl_str_005; // *** RESERVE BOUTONS ANIMES ***
	QStringList wl_explode;

	QPixmap wl_pix_001(dvdxsize,dvdysize);
	QPixmap wl_msk_001(dvdxsize,dvdysize);
	QPixmap wl_msk_002(dvdxsize,dvdysize);
	QPixmap wl_msk_003(720,576);

	QPixmap wl_pix_002;
	QPixmap wl_pix_003;
	QPixmap wl_pix_004;
	QPixmap wl_pix_005;
	QPixmap wl_pix_006;
	QPixmap wl_pix_007;
	QPixmap wl_pix_008; // *** SAUVEGARDE DU MENU STATIQUE ***
	QPixmap wl_pix_009;
	wl_pix_009.load(":/Interface/Interface/reload.png"); // *** TEXTE SANS L'OMBRE ***
	QPixmap wl_redimask;

	QImage wl_img_001;
	QImage wl_img_002;
	QImage wlimg;
	QImage wl_image; // *** TRANSPARENCE ***
	QImage wl_image_2; // *** TRANSPARENCE MASKS ***
	QImage wl_image_3; // *** TRANSPARENCE MASKS ***

	QImage wl_ims_1(1000,1000,QImage::Format_ARGB32);

	int lumi = 0;
	int cont = 0;
	int rouge = 0;
	int vert = 0;
	int bleu = 0;
	int valueadd_R = 0;
	int valueadd_V = 0;
	int valueadd_B = 0;
	int opacity = 0;
	int is_anim_thumb = 0;
	int cpt_back = 0;
	int cpt_vign = 0;
	int is_fdanim = 0;
	int wl_larg_txt = 0;
	QRgb srcPixel;
	QColor trtcolor;
	int c_r = 0;
	int c_v = 0;
	int c_b = 0;
	int ac_r = 0;
	int ac_v = 0;
	int ac_b = 0;

	int x;
	int y;
	int sx;
	int sy;

	QMovie wl_movie;

	QPainter p;
	QPainter t;
	QPainter g;
	QPainter s;
	QPainter z;

	while ( wg_int_001 <= nbre_menuth )
	{
		// *** INITIALISATION DES MASKS ***
		wl_msk_001.fill(QColor(0,0,0,0));
		wl_msk_002.fill(QColor(0,0,0,0));

		// *** CHARGEMENT BACKGROUND ET AUTRES THEMES ***
		wl_pix_001.fill(QColor(0,0,0));

		wg_int_003 = 0;
		is_anim_thumb = 0;

		label_29->setText(tr("Generation du menu : ") + QString::number(wg_int_001+1));
		progress_current_dvd_4->setValue(0); 

		while ( table_menus[wg_int_001][wg_int_003][0] != "$$$" && is_anim_thumb == 0 )
		{
			if ( table_menus[wg_int_001][wg_int_003][14] != "0" || table_menus[wg_int_001][wg_int_003][4].right(4) == ".gif" || table_menus[wg_int_001][wg_int_003][4].right(4) == ".GIF" )
			{
				is_anim_thumb = 1;
			}
			wg_int_003++;
		}		

		if ( is_anim_thumb == 0 )
		{
			// **********************************
			// *** MENU SANS VIGNETTES ANIMES ***
			// **********************************

			if ( table_menus_property[wg_int_001][0] != "" )
			{
				if ( table_menus_property[wg_int_001][0].right(4) != ".MPG" && table_menus_property[wg_int_001][0].right(4) != ".mpg" && table_menus_property[wg_int_001][0].right(4) != ".AVI" && table_menus_property[wg_int_001][0].right(4) != ".avi" )
				{
					if ( wl_img_001.load(table_menus_property[wg_int_001][0])  == false )
					{
						wl_img_001.load(":/Interface/Interface/reload.png");
					}

					if ( table_menus_property[wg_int_001][1].toInt() == 0 )
					{
						wl_pix_001.fill(QColor(0,0,0));
						if ( wl_img_001.width() > wl_img_001.height() )
						{
							wl_img_001 = wl_img_001.scaledToWidth ( dvdxsize, Qt::FastTransformation );
						}
						else
						{
							wl_img_001 = wl_img_001.scaledToHeight ( dvdysize, Qt::FastTransformation );
						}
						p.begin(&wl_pix_001);
						p.drawImage(0,0, wl_img_001, 0, 0, -1, -1 );
						p.end();
					}
					else
					{		
						QImage wl_img_002;
						// *** GENERATION DES FORMATS DE SCALE ***
						if ( table_menus_property[wg_int_001][1].toInt() == 1 )
						{
							wl_pix_001.fill(QColor(0,0,0));
							if ( wl_img_001.width() > wl_img_001.height() )
							{
								wl_img_001 = wl_img_001.scaledToWidth ( dvdxsize, Qt::FastTransformation );
							}
							else
							{
								wl_img_001 = wl_img_001.scaledToHeight ( dvdysize, Qt::FastTransformation );
							}
							p.begin(&wl_pix_001);
							p.drawImage((wl_pix_001.width() - wl_img_001.width()) / 2, (wl_pix_001.height() - wl_img_001.height()) / 2, wl_img_001, 0, 0, -1, -1 );
							p.end();
						}
						else
						{
							wl_pix_001.fill(QColor(0,0,0));
							if ( wl_img_001.width() > wl_img_001.height() )
							{
								wl_img_001 = wl_img_001.scaledToHeight ( dvdysize, Qt::FastTransformation );
							}
							else
							{
								wl_img_001 = wl_img_001.scaledToWidth ( dvdxsize, Qt::FastTransformation );
							}
							p.begin(&wl_pix_001);
							p.drawImage((wl_pix_001.width() - wl_img_001.width()) / 2, (wl_pix_001.height() - wl_img_001.height()) / 2, wl_img_001, 0, 0, -1, -1 );
							p.end();
						}
					}
					is_fdanim = 0;
					isanim = 0;
				}
				else
				{
					QDir wl_dircount(path_project + "/DVD/MAIN");
					QStringList filters;
					filters << QString::number(wg_int_001) + "-*.jpg";
					wl_dircount.setNameFilters(filters);
					isanim = wl_dircount.count();
					is_fdanim = 1;
				}
			}
			else
			{
				// *** AUCUN FOND DEFINIS ***
				wl_pix_001.fill(QColor(0,0,0));
				isanim = 0;
				is_fdanim = 0;
			}
		}
		else
		{
			// **********************************
			// *** MENU AVEC VIGNETTES ANIMES ***
			// **********************************
			if ( table_menus_property[wg_int_001][0].right(4) != ".MPG" && table_menus_property[wg_int_001][0].right(4) != ".mpg" && table_menus_property[wg_int_001][0].right(4) != ".AVI" && table_menus_property[wg_int_001][0].right(4) != ".avi" )
			{
				if ( wl_img_001.load(table_menus_property[wg_int_001][0])  == false )
				{
					wl_img_001.load(":/Interface/Interface/reload.png");
				}

				if ( table_menus_property[wg_int_001][1].toInt() == 0 )
				{
					wl_pix_001.fill(QColor(0,0,0));
					if ( wl_img_001.width() > wl_img_001.height() )
					{
						wl_img_001 = wl_img_001.scaledToWidth ( dvdxsize, Qt::FastTransformation );
					}
					else
					{
						wl_img_001 = wl_img_001.scaledToHeight ( dvdysize, Qt::FastTransformation );
					}
					p.begin(&wl_pix_001);
					p.drawImage(0,0, wl_img_001, 0, 0, -1, -1 );
					p.end();
				}
				else
				{		
					QImage wl_img_002;
					// *** GENERATION DES FORMATS DE SCALE ***
					if ( table_menus_property[wg_int_001][1].toInt() == 1 )
					{
						wl_pix_001.fill(QColor(0,0,0));
						if ( wl_img_001.width() > wl_img_001.height() )
						{
							wl_img_001 = wl_img_001.scaledToWidth ( dvdxsize, Qt::FastTransformation );
						}
						else
						{
							wl_img_001 = wl_img_001.scaledToHeight ( dvdysize, Qt::FastTransformation );
						}
						p.begin(&wl_pix_001);
						p.drawImage((wl_pix_001.width() - wl_img_001.width()) / 2, (wl_pix_001.height() - wl_img_001.height()) / 2, wl_img_001, 0, 0, -1, -1 );
						p.end();
					}
					else
					{
						wl_pix_001.fill(QColor(0,0,0));
						if ( wl_img_001.width() > wl_img_001.height() )
						{
							wl_img_001 = wl_img_001.scaledToHeight ( dvdysize, Qt::FastTransformation );
						}
						else
						{
							wl_img_001 = wl_img_001.scaledToWidth ( dvdxsize, Qt::FastTransformation );
						}
						p.begin(&wl_pix_001);
						p.drawImage((wl_pix_001.width() - wl_img_001.width()) / 2, (wl_pix_001.height() - wl_img_001.height()) / 2, wl_img_001, 0, 0, -1, -1 );
						p.end();
					}
				}
				wl_pix_008 = wl_pix_001;
				isanim = table_menus_property[wg_int_001][7].mid(1,table_menus_property[wg_int_001][7].length()-1).toInt()*25;
				is_fdanim = 0;
			}
			else
			{
				QDir wl_dircount(path_project + "/DVD/MAIN");
				QStringList filters;
				filters << QString::number(wg_int_001) + "-*.jpg";
				wl_dircount.setNameFilters(filters);
				if ( wl_dircount.count() < table_menus_property[wg_int_001][7].mid(1,table_menus_property[wg_int_001][7].length()-1).toUInt()*25 )
				{
					isanim = table_menus_property[wg_int_001][7].mid(1,table_menus_property[wg_int_001][7].length()-1).toInt()*25;
				}
				else
				{
					isanim = wl_dircount.count();
				}
				is_fdanim = 1;
			}
		}	

		//
		if ( isanim >= 1 )
		{
			progress_current_dvd_4->setMaximum(isanim);
		}
		else
		{
			progress_current_dvd_4->setMaximum(1);
		}

		wl_str_001 = table_menus_property[wg_int_001][2];
		wl_explode = wl_str_001.split(";",QString::KeepEmptyParts);
		wl_int_010 = wl_explode.at(0).toInt();
		wl_int_011 = wl_explode.at(1).toInt();
		wl_int_012 = wl_explode.at(2).toInt();

		wl_str_001 = table_menus_property[wg_int_001][3];
		wl_explode = wl_str_001.split(";",QString::KeepEmptyParts);
		wl_int_013 = wl_explode.at(0).toInt();
		wl_int_014 = wl_explode.at(1).toInt();
		wl_int_015 = wl_explode.at(2).toInt();

		wl_int_016 = table_menus_property[wg_int_001][6].toInt();

		// *** GENERATION DES BOUTONS ***

		wg_int_002 = 0;
		wl_int_005 = 0;
	     	QFile wmyficbt(path_project + "/DVD/GENE/" + QString::number(wg_int_001) + ".xml");

		if ( !wmyficbt.open( QIODevice::WriteOnly ))
		{
			qDebug() << "ERROR CREATING FILE FOR SPUMUX IN : " + path_project + "/DVD/GENE/";
			return;
		}
		QTextStream outficbt(&wmyficbt);
		outficbt << "<?xml version=\"1.0\" encoding=\"utf-8\"?>" << endl;
		outficbt << "<subpictures>" << endl;
		outficbt << "<stream>" << endl;
		outficbt << "<spu" << endl;
		outficbt << "force=\"yes\"" << endl;
		outficbt << "start=\"00:00:00.00\"" << endl;
		outficbt << "select=\"" + path_project + "/DVD/TEMP/MS" + QString::number(wg_int_001) + ".png\"" << endl;
		outficbt << "highlight=\"" + path_project + "/DVD/TEMP/MC" + QString::number(wg_int_001) + ".png\">" << endl;

		bcle_render = 0;
		cpt_back = 0;
		cpt_vign = 0;
		wl_cpt_save = 0;

		while ( bcle_render <= isanim )
		{
			if ( isanim > 0 )
			{
				if ( is_fdanim == 1 )
				{
					wl_str_002 = "0000";
					wl_str_003 = QString::number(cpt_back+1);
					wl_str_002.replace(4-wl_str_003.length(),wl_str_003.length(),wl_str_003);

					if ( wl_img_001.load(path_project + "/DVD/MAIN/" + QString::number(wg_int_001) + "-" + wl_str_002 + ".jpg") == true )
					{
						wl_pix_001.fill(QColor(0,0,0));

						wl_img_002 = wl_img_001.scaledToWidth(dvdxsize, Qt::FastTransformation);

						p.begin(&wl_pix_001);
						p.drawImage((wl_pix_001.width() - wl_img_002.width()) / 2, (wl_pix_001.height() - wl_img_002.height()) / 2, wl_img_002, 0, 0, -1, -1 );
						p.end();
					}
					else
					{
						cpt_back = 0;
						wl_str_002 = "0000";
						wl_str_003 = QString::number(cpt_back+1);
						wl_str_002.replace(4-wl_str_003.length(),wl_str_003.length(),wl_str_003);

						if ( wl_img_001.load(path_project + "/DVD/MAIN/" + QString::number(wg_int_001) + "-" + wl_str_002 + ".jpg") == true )
						{
							wl_pix_001.fill(QColor(0,0,0));
	
							wl_img_002 = wl_img_001.scaledToWidth(dvdxsize, Qt::FastTransformation);

							p.begin(&wl_pix_001);
							p.drawImage((wl_pix_001.width() - wl_img_002.width()) / 2, (wl_pix_001.height() - wl_img_002.height()) / 2, wl_img_002, 0, 0, -1, -1 );
							p.end();
						}
						else
						{
							qDebug() << "ERROR LOADING BACKGROUND STEP 1";
						}
					}
				}
				else
				{
					wl_pix_001 = wl_pix_008;
				}
			}

			while ( table_menus[wg_int_001][wg_int_002][0] != "$$$" )
			{
				if ( table_menus[wg_int_001][wg_int_002][14] == "0" )
				{
					// *** CAS D'UN BOUTON FIXE ***
					if ( table_menus[wg_int_001][wg_int_002][4] == "" )
					{
						wl_pix_002.load(":/Interface/Interface/default_bt.png");
					}
					else
					{
						if ( table_menus[wg_int_001][wg_int_002][4] == "EXT_VIDEO_EXT" )
						{
							wg_int_003=0;
							while ( wg_int_003 < nbre_medias && table_hdl_medias[wg_int_003]->pathname_media != table_menus[wg_int_001][wg_int_002][5] )
							{
								wg_int_003++;
							}
							if ( table_hdl_medias[wg_int_003]->pathname_media == table_menus[wg_int_001][wg_int_002][5] && table_menus[wg_int_001][wg_int_002][9] == wg_str_int_001 )
							{
								wl_pix_002 = table_hdl_medias[wg_int_003]->miniature;
							}
							else
							{
								if ( table_menus[wg_int_001][wg_int_002][9] != "" )
								{
									wg_int_004=0;
									while ( wg_int_004 < table_hdl_medias[wg_int_003]->nbre_chapitres && table_hdl_medias[wg_int_003]->chapitres[wg_int_004] != table_menus[wg_int_001][wg_int_002][9] )
									{
										wg_int_004++;
									}
									if ( table_hdl_medias[wg_int_003]->chapitres[wg_int_004] == table_menus[wg_int_001][wg_int_002][9] )
									{
										// *** MINIATURE DU CHAPITRE ***
										wl_pix_002 = table_hdl_medias[wg_int_003]->miniature;
										wl_pix_002 = table_hdl_medias[wg_int_003]->icones_chapitres[wg_int_004].pixmap( wl_pix_002.width(), wl_pix_002.height(), QIcon::Normal, QIcon::On );
									}
								}
								else
								{
									qDebug() << "LOGICAL ERROR IN MEMORY WHEN SEARCHING MEDIA CHAPTER FOR RENDERING PICTURE BUTTON ON MENU";
								}
							}
						}
						else
						{
							if ( table_menus[wg_int_001][wg_int_002][4].mid(0,5) == "$TXT$" )
							{
								// *** EXTRACTION POUR LE CAS D'UN BOUTON TEXTE ***
								wg_string_001 = table_menus[wg_int_001][wg_int_002][4];
								wg_string_002 = "";
								must_update = 0;
								if ( wg_string_001.mid(0,5) == "$TXT$" )
								{
									wg_int_006 = 5;
									wg_int_007 = 0;
									while ( wg_string_001.mid(wg_int_006,1) != "!" && wg_int_007 < 4 )
									{
										if ( wg_string_001.mid(wg_int_006,1) == "^" )
										{
											if ( wg_int_007 == 0 )
											{
												pntwheel3->red = wg_string_002.toInt();
												wg_string_002 = "";
											}
											if ( wg_int_007 == 1 )
											{
												pntwheel3->green = wg_string_002.toInt();
												wg_string_002 = "";
											}
											if ( wg_int_007 == 2 )
											{
												pntwheel3->blue = wg_string_002.toInt();
												wg_string_002 = "";
												pntwheel3->setColor(pntwheel3->red,pntwheel3->green,pntwheel3->blue);
											}
											if ( wg_int_007 == 3 )
											{
												font_txt->setCurrentFont(QFont(wg_string_002));
											}
											wg_int_007++;
										}
										else
										{
											wg_string_002 = wg_string_002 + wg_string_001.mid(wg_int_006,1);
										}
										wg_int_006++;
									}
									wg_string_004 = wg_string_001.mid(wg_int_006+1,wg_string_001.length() - wg_int_006);
								}
								else
								{
									wg_string_004 = "";
								}
								must_update = 1;

								wl_pix_005.load(":/Interface/Interface/default_bt.png");

								QFont font(font_txt->currentFont());
								font.setPixelSize((table_menus[wg_int_001][wg_int_002][10].toInt()-(24*(wg_string_004.count( "\n", Qt::CaseSensitive )+2)))/(wg_string_004.count( "\n", Qt::CaseSensitive )+1));

								if ( table_menus[wg_int_001][wg_int_002][24].mid(0,1) == "1" )
								{
									font.setBold(true);
								}
								else
								{
									font.setBold(false);
								}

								if ( table_menus[wg_int_001][wg_int_002][24].mid(1,1) == "1" )
								{
									font.setItalic(true);
								}
								else
								{
									font.setItalic(false);
								}

								if ( table_menus[wg_int_001][wg_int_002][24].mid(2,1) == "1" )
								{
									font.setUnderline(true);
								}
								else
								{
									font.setUnderline(false);
								}

								wl_explode = wg_string_004.split("\n",QString::KeepEmptyParts);
								wl_int_031 = 0;
								wl_int_032 = 0;
								wl_int_033 = 0;

								while ( wl_int_031 < wl_explode.count() )
								{
									if ( wl_explode.at(wl_int_031).length() > wl_int_033 )
									{
										wl_int_033 = wl_explode.at(wl_int_031).length();
										wl_int_032 = wl_int_031;
									}
									wl_int_031++;
								}

								QFontMetrics fm(font);
								wl_larg_txt = fm.width(wl_explode.at(wl_int_032))+50;

								if ( wl_larg_txt < 50 )
								{
									wl_larg_txt = 50;
								}

								wl_pix_005 = wl_pix_005.scaled(wl_larg_txt,table_menus[wg_int_001][wg_int_002][10].toInt());
								wl_pix_005.fill(QColor(0,0,0,0));

								p.begin(&wl_pix_005);
								p.setRenderHint(QPainter::Antialiasing,true);
								p.setFont(font);

								if ( table_menus[wg_int_001][wg_int_002][12].toInt() > 0 )
								{
									wg_string_005 = table_menus[wg_int_001][wg_int_002][18];
									wg_string_006 = "";
									wg_int_006 = 0;
									wg_int_007 = 0;

									if ( wg_string_005.length() > 0 )
									{
										// *** BOUCLE RECUPERATION COULEUR SHADOW ***

										while ( wg_int_007 < 3 )
										{
											if ( wg_string_005.mid(wg_int_006,1) == "^" )
											{
												if ( wg_int_007 == 0 )
												{
													pntwheel4->red = wg_string_006.toInt();
													wg_string_006 = "";
												}
												if ( wg_int_007 == 1 )
												{
													pntwheel4->green = wg_string_006.toInt();
													wg_string_006 = "";
												}
												if ( wg_int_007 == 2 )
												{
													pntwheel4->blue = wg_string_006.toInt();
													wg_string_006 = "";
													pntwheel4->setColor(pntwheel4->red,pntwheel4->green,pntwheel4->blue);
												}
												wg_int_007++;
											}
											else
											{
												wg_string_006 = wg_string_006 + wg_string_005.mid(wg_int_006,1);
											}
											wg_int_006++;
										}
										//
										// *** BOUCLE RECUPERATION ANGLE ET OPACITY SHADOW ***
										wg_string_006 = "";
										wg_int_006 = 0;
										wg_int_007 = 0;

										while ( wg_int_007 < 3 )
										{
											if ( wg_string_005.mid(wg_int_006,1) == "$" )
											{
												if ( wg_int_007 == 0 )
												{
													//qDebug() << "A=" << wg_string_006;
													wg_string_006 = "";
												}
												if ( wg_int_007 == 1 )
												{
													//qDebug() << "B=" << wg_string_006;
													shadow_opacity = wg_string_006.toInt();
													wg_string_006 = "";
												}
												if ( wg_int_007 == 2 )
												{
													//qDebug() << "C=" << wg_string_006;
													shadow_angle = wg_string_006.toInt();
													wg_string_006 = "";
												}
												wg_int_007++;
											}
											else
											{
												wg_string_006 = wg_string_006 + wg_string_005.mid(wg_int_006,1);
											}
											wg_int_006++;
										}
									}
									
									wl_ims_1.fill(0);
									
									s.begin(&wl_ims_1);
									s.setRenderHint(QPainter::Antialiasing,true);
									s.setFont(font);
									s.setPen(QColor(pntwheel4->red,pntwheel4->green,pntwheel4->blue,shadow_opacity));
									
									wl_x = 10+(5*cos((M_PI*shadow_angle)/180));
									wl_y = 10+(5*sin((M_PI*shadow_angle)/180));

									s.drawText(QRect(wl_x,wl_y,wl_larg_txt-20,table_menus[wg_int_001][wg_int_002][10].toInt()-20), Qt::AlignVCenter | table_menus[wg_int_001][wg_int_002][24].mid(3,1).toInt(), wg_string_004);
									s.end();
									wl_ims_1 = blur_shadow(wl_ims_1);
									p.drawImage(0,0,wl_ims_1,0,0,-1,-1,Qt::AutoColor);
								}

								p.setPen(QColor(pntwheel3->red,pntwheel3->green,pntwheel3->blue));
								p.drawText(QRect(10,10,wl_larg_txt-20,table_menus[wg_int_001][wg_int_002][10].toInt()-20), Qt::AlignVCenter | table_menus[wg_int_001][wg_int_002][24].mid(3,1).toInt(), wg_string_004);
								p.end();

								wl_pix_009 = wl_pix_009.scaled(wl_pix_005.width(),wl_pix_005.height());
								wl_pix_009.fill(QColor(0,0,0,0));
								z.begin(&wl_pix_009);
								z.setFont(font);
								z.setPen(QColor(pntwheel3->red,pntwheel3->green,pntwheel3->blue));
								z.drawText(QRect(10,10,wl_larg_txt-20,table_menus[wg_int_001][wg_int_002][10].toInt()-20), Qt::AlignVCenter | table_menus[wg_int_001][wg_int_002][24].mid(3,1).toInt(), wg_string_004);
								z.end();

								wl_pix_009 = wl_pix_009.scaled(table_menus[wg_int_001][wg_int_002][8].toInt(),table_menus[wg_int_001][wg_int_002][10].toInt());
								//

								wl_pix_005 = wl_pix_005.scaled(table_menus[wg_int_001][wg_int_002][8].toInt(),table_menus[wg_int_001][wg_int_002][10].toInt());

								wl_pix_002 = wl_pix_005;
							}
							else
							{
								if ( table_menus[wg_int_001][wg_int_002][4].right(4) == ".gif" || table_menus[wg_int_001][wg_int_002][4].right(4) == ".GIF" )
								{
									// *** TRAITEMENT GIF ANIMES ***
									wl_movie.setCacheMode( QMovie::CacheAll );
									wl_movie.setFileName(table_menus[wg_int_001][wg_int_002][4]);
									wl_int_034 = 0;
									wl_movie.jumpToFrame(0);
									while ( wl_int_034 < bcle_render )
									{
										if ( wl_movie.jumpToNextFrame() == false )
										{
											wl_movie.jumpToFrame(0);
										}
										wl_int_034++;
									}
									wl_pix_002 = wl_movie.currentPixmap();
								}
								else
								{
									wl_pix_002.load(table_menus[wg_int_001][wg_int_002][4]);
								}
							}
						}
					}
				}
				else
				{
					// *** CAS D'UN BOUTON ANIME ***
					wl_str_004 = "0000";
					wl_str_005 = QString::number(cpt_vign+1);
					wl_str_004.replace(4-wl_str_005.length(),wl_str_005.length(),wl_str_005);

					if ( wl_pix_002.load(path_project + "/DVD/MAIN/MB" + QString::number(wg_int_002) + "-" + QString::number(wg_int_001) + "-" + wl_str_004 + ".jpg") == true )
					{
					}
					else
					{
						cpt_vign = 0;
						wl_str_004 = "0000";
						wl_str_005 = QString::number(cpt_vign+1);
						wl_str_004.replace(4-wl_str_005.length(),wl_str_005.length(),wl_str_005);

						if ( wl_pix_002.load(path_project + "/DVD/MAIN/MB" + QString::number(wg_int_002) + "-" + QString::number(wg_int_001) + "-" + wl_str_004 + ".jpg") == true )
						{
						}
						else
						{
							qDebug() << "ERROR LOADING BACKGROUND BOUTTON STEP 1 : " << path_project + "/DVD/MAIN/MB" + QString::number(wg_int_002) + "-" + QString::number(wg_int_001) + "-" + wl_str_004 + ".jpg";
						}
					}
				}

				wl_pix_002 = wl_pix_002.scaled(table_menus[wg_int_001][wg_int_002][8].toInt(),table_menus[wg_int_001][wg_int_002][10].toInt());

				rotation = table_menus[wg_int_001][wg_int_002][7].toInt();
				angleradian = (M_PI*rotation)/180;

				if ( rotation <= 90)
				{ 
					menu_width = (wl_pix_002.width() * cos(angleradian))+(wl_pix_002.height() * sin(angleradian));
					menu_height = (wl_pix_002.height() * cos(angleradian))+(wl_pix_002.width() * sin(angleradian));
				}
				else
				{ 
					float mcos = cos(angleradian);
					float msin = sin(angleradian);

					if ( mcos < 0 )
					{
						mcos=mcos*-1;
					}
					if ( msin < 0 )
					{
						msin=msin*-1;
					}
					menu_width = (wl_pix_002.width() * mcos)+(wl_pix_002.height() * msin);
					menu_height = (wl_pix_002.width() * msin)+(wl_pix_002.height() * mcos);
				}

				sx = table_menus[wg_int_001][wg_int_002][20].toInt();
				sy = table_menus[wg_int_001][wg_int_002][21].toInt();

				if ( sx < 0 )
				{
					sx = sx * -1;
				}

				if ( sy < 0 )
				{
					sy = sy * -1;
				}

				//menu_width = menu_width + (sx*3);
				//menu_height = menu_height + (sy*3);
				if ( menu_width >= menu_height )
				{
					menu_width = menu_width+((float)sx*((float)1.2*((float)menu_width/(float)menu_height)));
					menu_height = menu_height+((float)sy*((float)1.2*((float)menu_width/(float)menu_height)));
				}
				else
				{
					menu_width = menu_width+((float)sx*((float)1.2*((float)menu_height/(float)menu_width)));
					menu_height = menu_height+((float)sy*((float)1.2*((float)menu_height/(float)menu_width)));
				}

				p.begin(&wl_pix_001);

				// *** TEST SI MASK SUR LE MENU ***
				if ( table_menus[wg_int_001][wg_int_002][6] != "" )
				{
					wl_pix_004 = wl_pix_002;
					if ( wl_pix_003.load(table_menus[wg_int_001][wg_int_002][6])  == false )
					{
						wl_pix_003.load(":/Interface/Interface/reload.png");
						wl_pix_003.fill(QColor(0,0,0,0));
					}

					if ( wl_pix_003.width() > wl_pix_003.height() )
					{
						wl_pix_003 = wl_pix_003.scaledToWidth( wl_pix_004.width(), Qt::FastTransformation );
						if ( wl_pix_003.height() > wl_pix_004.height() )
						{
							wl_pix_003 = wl_pix_003.scaledToHeight( wl_pix_004.height(), Qt::FastTransformation );
						}
					}
					else
					{
						wl_pix_003 = wl_pix_003.scaledToHeight( wl_pix_004.height(), Qt::FastTransformation );
						if ( wl_pix_003.width() > wl_pix_004.width() )
						{
							wl_pix_003 = wl_pix_003.scaledToWidth( wl_pix_004.width(), Qt::FastTransformation );
						}
					}

					wl_pix_004.fill(QColor(0,0,0,0));

					t.begin(&wl_pix_004);

					t.drawPixmap ( QRect((wl_pix_004.width()-wl_pix_003.width())/2,(wl_pix_004.height()-wl_pix_003.height())/2,-1,-1),wl_pix_003 );
					t.end();
				      	wl_int_006 = table_menus[wg_int_001][wg_int_002][6].lastIndexOf("/");
					if ( wl_int_006 != -1 )
					{
						wl_str_001 = table_menus[wg_int_001][wg_int_002][6].mid(0,wl_int_006) + "/2t_" + table_menus[wg_int_001][wg_int_002][6].mid(wl_int_006+1,table_menus[wg_int_001][wg_int_002][6].length()-(wl_int_006+1));

						if ( wl_pix_006.load(wl_str_001) == true )
						{
							// *** TRAITEMENT DE LA TRANSPARENCE ***

							if ( table_menus[wg_int_001][wg_int_002][17].toInt() < 255 )
							{
								wl_image = wl_pix_002.toImage();
								wl_image = wl_image.convertToFormat ( QImage::Format_ARGB32, Qt::AutoColor );

								for (y = 0; y < wl_image.height(); y++)
								{
									for (x = 0; x < wl_image.width(); x++)
									{
										srcPixel = wl_image.pixel(x, y);
										trtcolor = srcPixel;
										if ( qAlpha(srcPixel) > 0 )
										{
											if ( (table_menus[wg_int_001][wg_int_002][17].toInt()*qAlpha(srcPixel))/255 >=0 && (table_menus[wg_int_001][wg_int_002][17].toInt()*qAlpha(srcPixel))/255 <= 255 )
											{
												trtcolor.setAlpha((table_menus[wg_int_001][wg_int_002][17].toInt()*qAlpha(srcPixel))/255);
											}
											else
											{
												if ( (table_menus[wg_int_001][wg_int_002][17].toInt()*qAlpha(srcPixel))/255 < 0 )
												{
													trtcolor.setAlpha(0);
												}
												else
												{
													trtcolor.setAlpha(255);
												}
											}
											wl_image.setPixel(x, y, trtcolor.rgba());
										}
										else
										{
											trtcolor.setAlpha(0);
											wl_image.setPixel(x, y, trtcolor.rgba());
										}
									}
								}
								wl_pix_002 = QPixmap::fromImage( wl_image, Qt::AutoColor );
							}
							//
							wl_pix_002.setMask(wl_pix_004.mask());

							p.translate((table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));
							p.rotate(table_menus[wg_int_001][wg_int_002][7].toInt());
							p.shear(qreal(table_menus[wg_int_001][wg_int_002][21].toInt())/100,qreal(table_menus[wg_int_001][wg_int_002][20].toInt())/100);
							p.translate(-(table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),-(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));

							p.drawPixmap ( QRect(table_menus[wg_int_001][wg_int_002][0].toInt()+((menu_width-wl_pix_002.width())/2),table_menus[wg_int_001][wg_int_002][1].toInt()+((menu_height-wl_pix_002.height())/2),wl_pix_002.width(),wl_pix_002.height()),wl_pix_002 );

							wl_pix_006 = wl_pix_006.scaled(wl_pix_003.width(), wl_pix_003.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation );
							wl_pix_007 = wl_pix_004;
							wl_pix_007.fill(QColor(0,0,0,0));

							t.begin(&wl_pix_007);

							t.drawPixmap ( QRect((wl_pix_007.width()-wl_pix_006.width())/2,(wl_pix_007.height()-wl_pix_006.height())/2,-1,-1),wl_pix_006 );
							t.end();
							wl_pix_006 = wl_pix_007;

							if ( table_menus[wg_int_001][wg_int_002][13] != "" )
							{
								wlimg = wl_pix_006.toImage();
								wl_explode = table_menus[wg_int_001][wg_int_002][13].split("$",QString::KeepEmptyParts);
								rouge = wl_explode.at(0).toInt();
								vert = wl_explode.at(1).toInt();
								bleu = wl_explode.at(2).toInt();
								opacity = wl_explode.at(3).toInt();

								//
								for (y = 0; y < wlimg.height(); y++)
								{
									for (x = 0; x < wlimg.width(); x++)
									{
										srcPixel = wlimg.pixel(x, y);
										trtcolor = srcPixel;
										//
										if (qAlpha(srcPixel) > 1 )
										{
											if ( cont < 0 )
											{
												ac_r = ( (float)((float)(c_r - trtcolor.red() ) / 100) * -cont);
												ac_v = ( (float)((float)(c_v - trtcolor.green() ) / 100) * -cont);
												ac_b = ( (float)((float)(c_b - trtcolor.blue() ) / 100) * -cont);
											}
											else
											{
												if ( cont > 0 )
												{
													if ( trtcolor.red() < c_r )
													{
														ac_r = ( (float)((float)(0 - trtcolor.red() ) / 100) * -cont);
													}
													else
													{
														ac_r = ( (float)((float)(0 - (((trtcolor.red() + trtcolor.green() + trtcolor.blue())/3)) ) / 100) * -cont);
													}

													if ( trtcolor.green() < c_v )
													{
														ac_v = ( (float)((float)(0 - trtcolor.green() ) / 100) * -cont);
													}
													else
													{
														ac_v = ( (float)((float)(0 - (((trtcolor.red() + trtcolor.green() + trtcolor.blue())/3)) ) / 100) * -cont);
													}

													if ( trtcolor.blue() < c_b )
													{
														ac_b = ( (float)((float)(0 - trtcolor.blue() ) / 100) * -cont);
													}
													else
													{
														ac_b = ( (float)((float)(0 - (((trtcolor.red() + trtcolor.green() + trtcolor.blue())/3)) ) / 100) * -cont);
													}
												}
												else
												{
													ac_r = 0;
													ac_v = 0;
													ac_b = 0;
												}
											}

											//
											valueadd_R = lumi + rouge + ac_r;
											valueadd_V = lumi + vert + ac_v;
											valueadd_B = lumi + bleu + ac_b;
											//

											if ( valueadd_R > 0 )
											{
												if ( trtcolor.red() < 255 - valueadd_R)
												{
													trtcolor.setRed(trtcolor.red() + valueadd_R);
												}
												else
												{
													trtcolor.setRed(255);
												}
											}
											else
											{
												if ( trtcolor.red() > (valueadd_R*-1))
												{
													trtcolor.setRed(trtcolor.red() + valueadd_R);
												}
												else
												{
													trtcolor.setRed(0);
												}
											}

											if ( valueadd_V > 0 )
											{
												if ( trtcolor.green() < 255 - valueadd_V)
												{
													trtcolor.setGreen(trtcolor.green() + valueadd_V);
												}
												else
												{
													trtcolor.setGreen(255);
												}
											}
											else
											{
												if ( trtcolor.green() > (valueadd_V*-1))
												{
													trtcolor.setGreen(trtcolor.green() + valueadd_V);
												}
												else
												{
													trtcolor.setGreen(0);
												}
											}

											if ( valueadd_B > 0 )
											{
												if ( trtcolor.blue() < 255 - valueadd_B)
												{
													trtcolor.setBlue(trtcolor.blue() + valueadd_B);
												}
												else
												{
													trtcolor.setBlue(255);
												}
											}
											else
											{
												if ( trtcolor.blue() > (valueadd_B*-1))
												{
													trtcolor.setBlue(trtcolor.blue() + valueadd_B);
												}
												else
												{
													trtcolor.setBlue(0);
												}
											}
											//
											trtcolor.setAlpha(opacity);
											wlimg.setPixel(x, y, trtcolor.rgba());
										}
									}
								}
								wl_pix_006 = QPixmap::fromImage(wlimg,Qt::AutoColor);
							}
							p.resetMatrix();
							p.translate((table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));
							p.rotate(table_menus[wg_int_001][wg_int_002][7].toInt());
							p.shear(qreal(table_menus[wg_int_001][wg_int_002][21].toInt())/100,qreal(table_menus[wg_int_001][wg_int_002][20].toInt())/100);
							p.translate(-(table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),-(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));
p.drawPixmap ( QRect(table_menus[wg_int_001][wg_int_002][0].toInt()+((menu_width-wl_pix_002.width())/2),table_menus[wg_int_001][wg_int_002][1].toInt()+((menu_height-wl_pix_002.height())/2),wl_pix_002.width(),wl_pix_002.height()),wl_pix_006 );
							//p.drawPixmap ( QRect(table_menus[wg_int_001][wg_int_002][0].toInt(),table_menus[wg_int_001][wg_int_002][1].toInt(),-1,-1),wl_pix_006 );
							p.end();
						}
						else
						{
							// *** TRAITEMENT DE LA TRANSPARENCE ***

							if ( table_menus[wg_int_001][wg_int_002][17].toInt() < 255 )
							{
								wl_image = wl_pix_002.toImage();
								wl_image = wl_image.convertToFormat ( QImage::Format_ARGB32, Qt::AutoColor );

								for (y = 0; y < wl_image.height(); y++)
								{
									for (x = 0; x < wl_image.width(); x++)
									{
										srcPixel = wl_image.pixel(x, y);
										trtcolor = srcPixel;
										if ( qAlpha(srcPixel) > 0 )
										{
											if ( (table_menus[wg_int_001][wg_int_002][17].toInt()*qAlpha(srcPixel))/255 >=0 && (table_menus[wg_int_001][wg_int_002][17].toInt()*qAlpha(srcPixel))/255 <= 255 )
											{
												trtcolor.setAlpha((table_menus[wg_int_001][wg_int_002][17].toInt()*qAlpha(srcPixel))/255);
											}
											else
											{
												if ( (table_menus[wg_int_001][wg_int_002][17].toInt()*qAlpha(srcPixel))/255 < 0 )
												{
													trtcolor.setAlpha(0);
												}
												else
												{
													trtcolor.setAlpha(255);
												}
											}
											wl_image.setPixel(x, y, trtcolor.rgba());
										}
										else
										{
											trtcolor.setAlpha(0);
											wl_image.setPixel(x, y, trtcolor.rgba());
										}
									}
								}
								wl_pix_002 = QPixmap::fromImage( wl_image, Qt::AutoColor );
							}
							// *** MASK SPECIAL SANS OVERMASK ***
							QImage wl_image_2 = wl_pix_002.toImage();
							wl_image_2 = wl_image_2.convertToFormat ( QImage::Format_ARGB32_Premultiplied, Qt::AutoColor );

							wl_image_3 = wl_pix_004.toImage();
							wl_image_3 = wl_image_3.convertToFormat ( QImage::Format_ARGB32_Premultiplied, Qt::AutoColor );

							QPainter::CompositionMode mode = (QPainter::CompositionMode)6;

							g.begin(&wl_image_2);
							g.setCompositionMode ( mode );
							g.drawImage(QRect(0,0,-1,-1),wl_image_3);
							g.end();
							wl_pix_002 = QPixmap::fromImage( wl_image_2, Qt::AutoColor );

							p.translate((table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));
							p.rotate(table_menus[wg_int_001][wg_int_002][7].toInt());
							p.shear(qreal(table_menus[wg_int_001][wg_int_002][21].toInt())/100,qreal(table_menus[wg_int_001][wg_int_002][20].toInt())/100);
							p.translate(-(table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),-(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));

							p.drawPixmap ( QRect(table_menus[wg_int_001][wg_int_002][0].toInt()+((menu_width-wl_pix_002.width())/2),table_menus[wg_int_001][wg_int_002][1].toInt()+((menu_height-wl_pix_002.height())/2),wl_pix_002.width(),wl_pix_002.height()),wl_pix_002 );
							/*p.resetMatrix();
							p.translate((table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));
							p.rotate(table_menus[wg_int_001][wg_int_002][7].toInt());
							p.shear(qreal(table_menus[wg_int_001][wg_int_002][21].toInt())/100,qreal(table_menus[wg_int_001][wg_int_002][20].toInt())/100);
							p.translate(-(table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),-(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));

							p.drawPixmap ( QRect(table_menus[wg_int_001][wg_int_002][0].toInt()+((menu_width-wl_pix_002.width())/2),table_menus[wg_int_001][wg_int_002][1].toInt()+((menu_height-wl_pix_002.height())/2),wl_pix_002.width(),wl_pix_002.height()),wl_pix_002 );*/
							p.end();
						}
					}
				}
				else
				{
					// *** TRAITEMENT DE LA TRANSPARENCE ***

					if ( table_menus[wg_int_001][wg_int_002][17].toInt() < 255 )
					{
						wl_image = wl_pix_002.toImage();
						wl_image = wl_image.convertToFormat ( QImage::Format_ARGB32, Qt::AutoColor );

						for (y = 0; y < wl_image.height(); y++)
						{
							for (x = 0; x < wl_image.width(); x++)
							{
								srcPixel = wl_image.pixel(x, y);
								trtcolor = srcPixel;
								if ( qAlpha(srcPixel) > 0 )
								{
									if ( (table_menus[wg_int_001][wg_int_002][17].toInt()*qAlpha(srcPixel))/255 >=0 && (table_menus[wg_int_001][wg_int_002][17].toInt()*qAlpha(srcPixel))/255 <= 255 )
									{
										trtcolor.setAlpha((table_menus[wg_int_001][wg_int_002][17].toInt()*qAlpha(srcPixel))/255);
									}
									else
									{
										if ( (table_menus[wg_int_001][wg_int_002][17].toInt()*qAlpha(srcPixel))/255 < 0 )
										{
											trtcolor.setAlpha(0);
										}
										else
										{
											trtcolor.setAlpha(255);
										}
									}
									wl_image.setPixel(x, y, trtcolor.rgba());
								}
								else
								{
									trtcolor.setAlpha(0);
									wl_image.setPixel(x, y, trtcolor.rgba());
								}
							}
						}
						wl_pix_002 = QPixmap::fromImage( wl_image, Qt::AutoColor );
					}

					p.translate((table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));
					p.rotate(table_menus[wg_int_001][wg_int_002][7].toInt());
					p.shear(qreal(table_menus[wg_int_001][wg_int_002][21].toInt())/100,qreal(table_menus[wg_int_001][wg_int_002][20].toInt())/100);
					p.translate(-(table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),-(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));

					p.drawPixmap ( QRect(table_menus[wg_int_001][wg_int_002][0].toInt()+((menu_width-wl_pix_002.width())/2),table_menus[wg_int_001][wg_int_002][1].toInt()+((menu_height-wl_pix_002.height())/2),wl_pix_002.width(),wl_pix_002.height()),wl_pix_002 );
					p.end();
				}
				//

				if ( bcle_render == 0 && table_menus[wg_int_001][wg_int_002][11] == "0" )
				{
					// *** OVERLAY SELECTIONNE ***
					p.begin(&wl_msk_001);

					wl_pix_002.fill(QColor(wl_int_010,wl_int_011,wl_int_012,wl_int_016));

					if ( table_menus[wg_int_001][wg_int_002][23] == "" )
					{
						if ( table_menus[wg_int_001][wg_int_002][6] != "" )
						{
							wl_pix_002.setMask(wl_pix_004.mask());
						}

						if ( table_menus[wg_int_001][wg_int_002][4].mid(0,5) == "$TXT$" )
						{
							wl_pix_002.setMask(wl_pix_009.mask());
						}
					}
					else
					{
						if ( wl_pix_005.load(path_project+"/DVD/SVP/" +table_menus[wg_int_001][wg_int_002][23]) == false )
						{
							qDebug() << "ERROR LOADING OVERLAY : " + path_project+"/DVD/SVP/" +table_menus[wg_int_001][wg_int_002][23];
						}
						wl_pix_005 = wl_pix_005.scaled(wl_pix_002.width(),wl_pix_002.height());
						wl_pix_002.setMask(wl_pix_005.mask());
					}

					/*p.translate((table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));
					p.rotate(table_menus[wg_int_001][wg_int_002][7].toInt());
					p.shear(qreal(table_menus[wg_int_001][wg_int_002][21].toInt())/100,qreal(table_menus[wg_int_001][wg_int_002][20].toInt())/100);
					p.translate(-(table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),-(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));

					p.drawPixmap ( QRect(table_menus[wg_int_001][wg_int_002][0].toInt()+((menu_width-wl_pix_002.width())/2),table_menus[wg_int_001][wg_int_002][1].toInt()+((menu_height-wl_pix_002.height())/2),wl_pix_002.width(),wl_pix_002.height()),wl_pix_002 );*/
					p.resetMatrix();
					p.translate((table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));
					p.rotate(table_menus[wg_int_001][wg_int_002][7].toInt());
					p.shear(qreal(table_menus[wg_int_001][wg_int_002][21].toInt())/100,qreal(table_menus[wg_int_001][wg_int_002][20].toInt())/100);
					p.translate(-(table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),-(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));

					p.drawPixmap ( QRect(table_menus[wg_int_001][wg_int_002][0].toInt()+((menu_width-wl_pix_002.width())/2),table_menus[wg_int_001][wg_int_002][1].toInt()+((menu_height-wl_pix_002.height())/2),wl_pix_002.width(),wl_pix_002.height()),wl_pix_002 );

					p.end();

					// *** OVERLAY CLIQUE ***

					wl_pix_002.fill(QColor(wl_int_013,wl_int_014,wl_int_015,wl_int_016));

					p.begin(&wl_msk_002);

					if ( table_menus[wg_int_001][wg_int_002][23] == "" )
					{
						if ( table_menus[wg_int_001][wg_int_002][6] != "" )
						{
							wl_pix_002.setMask(wl_pix_004.mask());
						}

						if ( table_menus[wg_int_001][wg_int_002][4].mid(0,5) == "$TXT$" )
						{
							wl_pix_002.setMask(wl_pix_009.mask());
						}
					}
					else
					{
						if ( wl_pix_005.load(path_project+"/DVD/SVP/" +table_menus[wg_int_001][wg_int_002][23]) == false )
						{
							qDebug() << "ERROR LOADING OVERLAY : " + path_project+"/DVD/SVP/" +table_menus[wg_int_001][wg_int_002][23];
						}
						wl_pix_005 = wl_pix_005.scaled(wl_pix_002.width(),wl_pix_002.height());
						wl_pix_002.setMask(wl_pix_005.mask());
					}

					/*p.translate((table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));
					p.rotate(table_menus[wg_int_001][wg_int_002][7].toInt());
					p.shear(qreal(table_menus[wg_int_001][wg_int_002][21].toInt())/100,qreal(table_menus[wg_int_001][wg_int_002][20].toInt())/100);
					p.translate(-(table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),-(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));

					p.drawPixmap ( QRect(table_menus[wg_int_001][wg_int_002][0].toInt()+((menu_width-wl_pix_002.width())/2),table_menus[wg_int_001][wg_int_002][1].toInt()+((menu_height-wl_pix_002.height())/2),wl_pix_002.width(),wl_pix_002.height()),wl_pix_002 );*/
					p.resetMatrix();
					p.translate((table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));
					p.rotate(table_menus[wg_int_001][wg_int_002][7].toInt());
					p.shear(qreal(table_menus[wg_int_001][wg_int_002][21].toInt())/100,qreal(table_menus[wg_int_001][wg_int_002][20].toInt())/100);
					p.translate(-(table_menus[wg_int_001][wg_int_002][0].toInt()+(menu_width/2)),-(table_menus[wg_int_001][wg_int_002][1].toInt()+(menu_height/2)));

					p.drawPixmap ( QRect(table_menus[wg_int_001][wg_int_002][0].toInt()+((menu_width-wl_pix_002.width())/2),table_menus[wg_int_001][wg_int_002][1].toInt()+((menu_height-wl_pix_002.height())/2),wl_pix_002.width(),wl_pix_002.height()),wl_pix_002 );
					p.end();

					// *** AJOUT DU BOUTON AU FICHIER SPUMUX ***

					if ( table_menus[wg_int_001][wg_int_002][0].toInt() > 0 )
					{
						wl_int_001 = table_menus[wg_int_001][wg_int_002][0].toInt();
					}
					else
					{
						wl_int_001 = 0;
					}
					if ( table_menus[wg_int_001][wg_int_002][1].toInt() > 0 )
					{
						wl_int_002 = table_menus[wg_int_001][wg_int_002][1].toInt();
					}
					else
					{
						wl_int_002 = 0;
					}
					if ( table_menus[wg_int_001][wg_int_002][2].toInt() > 0 )
					{
						wl_int_003 = wl_int_001 + menu_width; //wl_int_001-sx;
					}
					else
					{
						wl_int_003 = 0;
					}
					if ( table_menus[wg_int_001][wg_int_002][3].toInt() > 0 )
					{
						wl_int_004 = wl_int_002 + menu_height; //wl_int_002-sy;
					}
					else
					{
						wl_int_004 = 0;
					}

					if ( wl_int_001 >= dvdxsize )
					{
						wl_int_001 = dvdxsize;
					}

					if ( wl_int_002 >= dvdysize )
					{
						wl_int_002 = dvdysize;
					}

					if ( wl_int_003 >= dvdxsize )
					{
						wl_int_003 = dvdxsize;
					}

					if ( wl_int_004 >= dvdysize )
					{
						wl_int_004 = dvdysize;
					}

					if ( table_menus[wg_int_001][wg_int_002][11] == "0" )
					{
						if ( wl_int_001%2 != 0 )
						{
							wl_int_001++;
						}
						if ( wl_int_002%2 != 0 )
						{
							wl_int_002++;
						}
						if ( wl_int_003%2 != 0 )
						{
							wl_int_003++;
						}
						if ( wl_int_004%2 != 0 )
						{
							wl_int_004++;
						}

						if ( dvdxsize == 720 )
						{
							outficbt << "<button name=\"" + QString::number(wl_int_005+1) + "\"  x0=\"" + QString::number(wl_int_001) + "\" y0=\"" + QString::number(wl_int_002) + "\" x1=\"" + QString::number(wl_int_003) + "\" y1=\"" + QString::number(wl_int_004) + "\" />" << endl;
							outficbt << "<action name=\"" + QString::number(wl_int_005+1) + "\" />" << endl;
						}
						else
						{
							outficbt << "<button name=\"" + QString::number(wl_int_005+1) + "\"  x0=\"" + QString::number(wl_int_001/(float)1.422) + "\" y0=\"" + QString::number(wl_int_002) + "\" x1=\"" + QString::number(wl_int_003/(float)1.422) + "\" y1=\"" + QString::number(wl_int_004) + "\" />" << endl;
							outficbt << "<action name=\"" + QString::number(wl_int_005+1) + "\" />" << endl;
						}
						wl_int_005++;
					}
				}
				//
				wg_int_002++;
			}
			if ( isanim > 0 )
			{
				if ( is_anim_thumb == 0 )
				{
					if ( dvdxsize == 720 )
					{
						wl_pix_001.save(path_project + "/DVD/MAIN/" + QString::number(wg_int_001) + "-" + wl_str_002 + ".jpg","JPEG",100);
					}
					else
					{
						wl_msk_003 = wl_pix_001.scaled(720,576,Qt::IgnoreAspectRatio,Qt::FastTransformation);
						wl_msk_003.save(path_project + "/DVD/MAIN/" + QString::number(wg_int_001) + "-" + wl_str_002 + ".jpg","JPEG",100);
					}
				}
				else
				{
					wl_str_004 = "0000";
					wl_str_005 = QString::number(wl_cpt_save);
					wl_str_004.replace(4-wl_str_005.length(),wl_str_005.length(),wl_str_005);
					if ( dvdxsize == 720 )
					{
						wl_pix_001.save(path_project + "/DVD/MAIN/MX" + QString::number(wg_int_001) + "-" + wl_str_004 + ".jpg","JPEG",100);
					}
					else
					{
						wl_msk_003 = wl_pix_001.scaled(720,576,Qt::IgnoreAspectRatio,Qt::FastTransformation);
						wl_msk_003.save(path_project + "/DVD/MAIN/MX" + QString::number(wg_int_001) + "-" + wl_str_004 + ".jpg","JPEG",100);
					}
					wl_cpt_save++;
				}
			}
			wg_int_002 = 0;

			// *** POINT D'INCREMENTATION ***

			cpt_back++;
			cpt_vign++;
			bcle_render++;

			progress_current_dvd_4->setValue(bcle_render);

			if ( bcle_render == isanim )
			{
				bcle_render = 99999;
			}
		}

		outficbt << "</spu>" << endl;
		outficbt << "</stream>" << endl;
		outficbt << "</subpictures>" << endl;

		wmyficbt.close();

		if ( isanim == 0 )
		{
			if ( dvdxsize == 720 )
			{
				wl_pix_001.save(path_project + "/DVD/TEMP/FD" + QString::number(wg_int_001) + ".jpg","JPEG",100);
				wl_msk_001.save(path_project + "/DVD/TEMP/MS" + QString::number(wg_int_001) + ".png","PNG");
				wl_msk_002.save(path_project + "/DVD/TEMP/MC" + QString::number(wg_int_001) + ".png","PNG");
			}
			else
			{
				wl_msk_003 = wl_pix_001.scaled(720,576,Qt::IgnoreAspectRatio,Qt::FastTransformation);
				wl_msk_003.save(path_project + "/DVD/TEMP/FD" + QString::number(wg_int_001) + ".jpg","JPEG",100);
				wl_msk_003 = wl_msk_001.scaled(720,576,Qt::IgnoreAspectRatio,Qt::FastTransformation);
				wl_msk_003.save(path_project + "/DVD/TEMP/MS" + QString::number(wg_int_001) + ".png","PNG");
				wl_msk_003 = wl_msk_002.scaled(720,576,Qt::IgnoreAspectRatio,Qt::FastTransformation);
				wl_msk_003.save(path_project + "/DVD/TEMP/MC" + QString::number(wg_int_001) + ".png","PNG");
			}
		}
		else
		{
			if ( dvdxsize == 720 )
			{
				wl_msk_001.save(path_project + "/DVD/TEMP/MS" + QString::number(wg_int_001) + ".png","PNG");
				wl_msk_002.save(path_project + "/DVD/TEMP/MC" + QString::number(wg_int_001) + ".png","PNG");
			}
			else
			{
				wl_msk_003 = wl_msk_001.scaled(720,576,Qt::IgnoreAspectRatio,Qt::FastTransformation);
				wl_msk_003.save(path_project + "/DVD/TEMP/MS" + QString::number(wg_int_001) + ".png","PNG");
				wl_msk_003 = wl_msk_002.scaled(720,576,Qt::IgnoreAspectRatio,Qt::FastTransformation);
				wl_msk_003.save(path_project + "/DVD/TEMP/MC" + QString::number(wg_int_001) + ".png","PNG");
			}
		}

		wg_int_001++;
	}
	progress_current_dvd_4->setValue(progress_current_dvd_4->maximum());
	// *** FABRICATION DES VIDEOS POUR LES MENUS ***
     	QFile wmyfic(path_project + "/DVD/GENE/audio.sh");

	if ( !wmyfic.open( QIODevice::WriteOnly ))
	{
		qDebug() << "ERROR CREATING AUDIO.SH IN : " + path_project + "/DVD/GENE/";
		return;
	}
	else
	{
		QFile wmyficext;
		QTextStream outext(&wmyficext);

		QTextStream out(&wmyfic);
		out << "cd \"" + path_project + "/DVD/GENE/\"" << endl;

		wg_int_001 = 0;
		while ( wg_int_001 <= nbre_menuth )
		{
			if ( table_menus_property[wg_int_001][4] != "" ) // *** BANDE SON ***
			{
				wmyficext.setFileName(path_project + "/DVD/GENE/extinfo.sh");
				wmyficext.open( QIODevice::WriteOnly );
				outext << "mplayer -identify -quiet -msglevel all=-1 -frames 0 \"" + table_menus_property[wg_int_001][4] + "\"" << endl;
				outext << "rm -f " + path_project + "/DVD/GENE/extinfo.sh" << endl;
				outext << "exit" << endl;
				wg_string_003 = "";
				QString programf = "bash";
				QStringList argumentsf;
				argumentsf << path_project + "/DVD/GENE/extinfo.sh";

			      	proc_ffmpeg.setProcessChannelMode(QProcess::MergedChannels);
				proc_ffmpeg.start(programf,argumentsf);

				proc_ffmpeg.waitForFinished(-1);
				QByteArray buffer(proc_ffmpeg.readAllStandardOutput());
				wg_string_003 = wg_string_003 + buffer;
	
				wg_int_002 = wg_string_003.lastIndexOf( "ID_LENGTH=" );
				if ( wg_int_002 > 0 )
				{
					wg_string_004 = "";
					wg_int_002 = wg_int_002 + 10;
					while ( wg_string_003.mid(wg_int_002,1) != "." )
					{
						wg_string_004 = wg_string_004 + wg_string_003.mid(wg_int_002,1);
						wg_int_002++;
					}
				}
			}

			wg_int_003 = 0;
			is_anim_thumb = 0;

			while ( table_menus[wg_int_001][wg_int_003][0] != "$$$" && is_anim_thumb == 0 )
			{
				if ( table_menus[wg_int_001][wg_int_003][14] != "0" || table_menus[wg_int_001][wg_int_003][4].right(4) == ".gif" || table_menus[wg_int_001][wg_int_003][4].right(4) == ".GIF" )
				{
					is_anim_thumb = 1;
				}
				wg_int_003++;
			}

			if ( table_menus_property[wg_int_001][4] == "" )
			{
				out << "sox -n -t wav -c 2 silent.wav trim 0 1" << endl;
				out << "ffmpeg -i silent.wav -y -acodec " + global_audio + " -ab 192k " + QString::number(wg_int_001) + ".mp2" << endl;
			}
			else
			{
				out << "ffmpeg -i \"" + table_menus_property[wg_int_001][4] + "\" -y -acodec " + global_audio + " -ab 192k " + QString::number(wg_int_001) + ".mp2" << endl;
			}

			if ( is_anim_thumb == 0 )
			{
				// *** MENU SANS VIGNETTES ANIMES ***
				if ( dvd_standard == "pal" )
				{
					if ( table_menus_property[wg_int_001][0].right(4) != ".MPG" && table_menus_property[wg_int_001][0].right(4) != ".mpg" && table_menus_property[wg_int_001][0].right(4) != ".AVI" && table_menus_property[wg_int_001][0].right(4) != ".avi" )
					{
						if ( dvdxsize == 720 )
						{
							out << "jpegtopnm " + path_project + "/DVD/TEMP/FD" + QString::number(wg_int_001) + ".jpg | ppmtoy4m -n 1 -F25:1 -S 420mpeg2 -I t -A 59:54 -L | mpeg2enc --no-constraints -f 8 -n p -F 3 -b 8500 -q 3 -M " + QString::number(nbre_threads) + " -a 2 -o " + QString::number(wg_int_001) + ".m2v" << endl;
							//out << "jpeg2yuv -f 25 -I p -n 1 -j " + path_project + "/DVD/TEMP/FD" + QString::number(wg_int_001) + ".jpg | mpeg2enc --no-constraints -f 8 -n p -F 3 -b 8500 -q 3 -M " + QString::number(nbre_threads) + " -a 2 -o " + QString::number(wg_int_001) + ".m2v" << endl;
						}
						else
						{
							out << "jpegtopnm " + path_project + "/DVD/TEMP/FD" + QString::number(wg_int_001) + ".jpg | ppmtoy4m -n 1 -F25:1 -S 420mpeg2 -I t -A 59:54 -L | mpeg2enc --no-constraints -f 8 -n p -F 3 -b 8500 -q 3 -a 3 -o " + QString::number(wg_int_001) + ".m2v" << endl;
							//out << "jpeg2yuv -f 25 -I p -n 1 -j " + path_project + "/DVD/TEMP/FD" + QString::number(wg_int_001) + ".jpg | mpeg2enc --no-constraints -f 8 -n p -F 3 -b 8500 -q 3 -M " + QString::number(nbre_threads) + " -a 3 -o " + QString::number(wg_int_001) + ".m2v" << endl;
						}
					}
					else
					{
						QDir wl_dircount(path_project + "/DVD/MAIN");
						QStringList filters;
						filters << QString::number(wg_int_001) + "-*.jpg";
						wl_dircount.setNameFilters(filters);
						isanim = wl_dircount.count();

						int wl_nbrefois = (wg_string_004.toInt()*25)/isanim;

						if ( wl_nbrefois < 1 )
						{
							wl_nbrefois = 1;
						}

						if ( dvdxsize == 720 )
						{
							if ( combo_format_dvd->currentIndex() < 2 )
							{
								out << "mencoder -quiet -msglevel all=-1 \"mf://" + path_project +"/DVD/MAIN/" + QString::number(wg_int_001) + "-*.jpg\" -of rawvideo -mf w=720:h=576:fps=25:type=jpg -ovc lavc -lavcopts vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:vstrict=0:aspect=4/3:threads=" + QString::number(nbre_threads) + ":vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=7000:keyint=15 -nosound -o " + QString::number(wg_int_001) + ".m2v | perl " + qApp->applicationDirPath() + "/fake.pl" << endl;
							}
							else
							{
								out << "mencoder -quiet -msglevel all=-1 \"mf://" + path_project +"/DVD/MAIN/" + QString::number(wg_int_001) + "-*.jpg\" -of rawvideo -mf w=720:h=576:fps=25:type=jpg -ovc lavc -lavcopts vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:vstrict=0:aspect=4/3:threads=" + QString::number(nbre_threads) + ":vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=7000:keyint=18 -nosound -o " + QString::number(wg_int_001) + ".m2v | perl " + qApp->applicationDirPath() + "/fake.pl" << endl;
							}
							//out << "jpeg2yuv -f 25 -I p -j " + path_project + "/DVD/TEMP/FD" + QString::number(wg_int_001) + ".jpg | mpeg2enc --no-constraints -f 8 -n p -F 3 -b 8500 -q 3 -M " + QString::number(nbre_threads) + " -a 3 -o " + QString::number(wg_int_001) + ".m2v" << endl;
						}
						else
						{
							out << "mencoder -quiet -msglevel all=-1 \"mf://" + path_project +"/DVD/MAIN/" + QString::number(wg_int_001) + "-*.jpg\" -of rawvideo -mf w=720:h=576:fps=25:type=jpg -ovc lavc -lavcopts vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:vstrict=0:aspect=16/9:threads=" + QString::number(nbre_threads) + ":vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=7000:keyint=15 -nosound -o " + QString::number(wg_int_001) + ".m2v | perl " + qApp->applicationDirPath() + "/fake.pl" << endl;
						}

						if ( wl_nbrefois > 1 )
						{
							out << "cat " + QString::number(wg_int_001) + ".m2v > a-" + QString::number(wg_int_001) + ".m2v"  << endl;
							wg_int_003 = 1;
							while ( wg_int_003 < wl_nbrefois )
							{
								out << "cat a-" + QString::number(wg_int_001) + ".m2v >> " + QString::number(wg_int_001) + ".m2v"  << endl;
								wg_int_003++;
							}
						}
					}
				}
				else
				{
					if ( table_menus_property[wg_int_001][0].right(4) != ".MPG" && table_menus_property[wg_int_001][0].right(4) != ".mpg" && table_menus_property[wg_int_001][0].right(4) != ".AVI" && table_menus_property[wg_int_001][0].right(4) != ".avi" )
					{
						out << "jpegtopnm " + path_project + "/DVD/TEMP/FD" + QString::number(wg_int_001) + ".jpg | ppmtoy4m -n 1 -F30000:1001 -S 420mpeg2 -I t -A 10:11 -L | mpeg2enc --no-constraints -f 8 -b 8500 -q 3 -n n -F 4 -a 2 -o " + QString::number(wg_int_001) + ".m2v" << endl;
						//out << "jpeg2yuv -f 25 -I p -n 1 -j " + path_project + "/DVD/TEMP/FD" + QString::number(wg_int_001) + ".jpg | mpeg2enc --no-constraints -f 8 -n n -F 4 -b 8500 -q 3 -M " + QString::number(nbre_threads) + " -a 2 -o " + QString::number(wg_int_001) + ".m2v" << endl;
					}
					else
					{
						if ( combo_format_dvd->currentIndex() < 2 )
						{
							out << "mencoder -quiet -msglevel all=-1 \"mf://" + path_project +"/DVD/MAIN/" + QString::number(wg_int_001) + "-*.jpg\" -of rawvideo -mf w=720:h=480:fps=30000/1001:type=jpg -ovc lavc -lavcopts vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:vstrict=0:aspect=4/3:threads=" + QString::number(nbre_threads) + ":vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=7000:keyint=15 -nosound -o " + QString::number(wg_int_001) + ".m2v | perl " + qApp->applicationDirPath() + "/fake.pl" << endl;
						}
						else
						{
							out << "mencoder -quiet -msglevel all=-1 \"mf://" + path_project +"/DVD/MAIN/" + QString::number(wg_int_001) + "-*.jpg\" -of rawvideo -mf w=720:h=480:fps=30000/1001:type=jpg -ovc lavc -lavcopts vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:vstrict=0:aspect=4/3:threads=" + QString::number(nbre_threads) + ":vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=7000:keyint=18 -nosound -o " + QString::number(wg_int_001) + ".m2v | perl " + qApp->applicationDirPath() + "/fake.pl" << endl;
						}
					}
				}
			}
			else
			{
				// *** MENU AVEC VIGNETTES ANIMES ***
				if ( dvd_standard == "pal" )
				{
					QDir wl_dircount(path_project + "/DVD/MAIN");
					QStringList filters;
					filters << "MX" + QString::number(wg_int_001) + "-*.jpg";
					wl_dircount.setNameFilters(filters);
					isanim = wl_dircount.count();

					int wl_nbrefois = (wg_string_004.toInt()*25)/isanim;

					if ( wl_nbrefois < 1 )
					{
						wl_nbrefois = 1;
					}

					if ( dvdxsize == 720 )
					{
						if ( combo_format_dvd->currentIndex() < 2 )
						{
							out << "mencoder -quiet -msglevel all=-1 \"mf://" + path_project +"/DVD/MAIN/MX" + QString::number(wg_int_001) + "-*.jpg\" -of rawvideo -mf w=720:h=576:fps=25:type=jpg -ovc lavc -lavcopts vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:vstrict=0:aspect=4/3:threads=" + QString::number(nbre_threads) + ":vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=7000:keyint=15 -nosound -o " + QString::number(wg_int_001) + ".m2v | perl " + qApp->applicationDirPath() + "/fake.pl" << endl;
						}
						else
						{
							out << "mencoder -quiet -msglevel all=-1 \"mf://" + path_project +"/DVD/MAIN/MX" + QString::number(wg_int_001) + "-*.jpg\" -of rawvideo -mf w=720:h=576:fps=25:type=jpg -ovc lavc -lavcopts vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:vstrict=0:aspect=4/3:threads=" + QString::number(nbre_threads) + ":vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=7000:keyint=18 -nosound -o " + QString::number(wg_int_001) + ".m2v | perl " + qApp->applicationDirPath() + "/fake.pl" << endl;
						}
					}
					else
					{
						out << "mencoder -quiet -msglevel all=-1 \"mf://" + path_project +"/DVD/MAIN/MX" + QString::number(wg_int_001) + "-*.jpg\" -of rawvideo -mf w=720:h=576:fps=25:type=jpg -ovc lavc -lavcopts vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:vstrict=0:aspect=16/9:threads=" + QString::number(nbre_threads) + ":vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=7000:keyint=15 -nosound -o " + QString::number(wg_int_001) + ".m2v | perl " + qApp->applicationDirPath() + "/fake.pl" << endl;
					}

					if ( wl_nbrefois > 1 )
					{
						out << "cat " + QString::number(wg_int_001) + ".m2v > a-" + QString::number(wg_int_001) + ".m2v"  << endl;
						wg_int_003 = 1;
						while ( wg_int_003 < wl_nbrefois )
						{
							out << "cat a-" + QString::number(wg_int_001) + ".m2v >> " + QString::number(wg_int_001) + ".m2v"  << endl;
							wg_int_003++;
						}
					}
				}
				else
				{
					if ( combo_format_dvd->currentIndex() < 2 )
					{
						out << "mencoder -quiet -msglevel all=-1 \"mf://" + path_project +"/DVD/MAIN/MX" + QString::number(wg_int_001) + "-*.jpg\" -of rawvideo -mf w=720:h=480:fps=30000/1001:type=jpg -ovc lavc -lavcopts vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:vstrict=0:aspect=4/3:threads=" + QString::number(nbre_threads) + ":vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=7000:keyint=15 -nosound -o " + QString::number(wg_int_001) + ".m2v | perl " + qApp->applicationDirPath() + "/fake.pl" << endl;
					}
					else
					{
						out << "mencoder -quiet -msglevel all=-1 \"mf://" + path_project +"/DVD/MAIN/MX" + QString::number(wg_int_001) + "-*.jpg\" -of rawvideo -mf w=720:h=480:fps=30000/1001:type=jpg -ovc lavc -lavcopts vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:vstrict=0:aspect=4/3:threads=" + QString::number(nbre_threads) + ":vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=7000:keyint=18 -nosound -o " + QString::number(wg_int_001) + ".m2v | perl " + qApp->applicationDirPath() + "/fake.pl" << endl;
					}
				}
			}
			out << "mplex -f 8 -v 0 -o /dev/stdout " + QString::number(wg_int_001) + ".m2v " + QString::number(wg_int_001) + ".mp2 | spumux -m dvd -v 2 " + QString::number(wg_int_001) +  ".xml > " + QString::number(wg_int_001) +  ".mpg" << endl;
			out << "echo GIBOSTEP" << endl;
			wg_int_001++;
		}
		out << "exit" << endl;
		wmyfic.close();
		//
		progress_current_dvd_3->setMaximum(wg_int_001); //+(nbre_menuth-2));
		QString program = "bash";
		QStringList arguments;
       		arguments << path_project + "/DVD/GENE/audio.sh";
	      	renderProcess.setProcessChannelMode(QProcess::MergedChannels);
	      	renderProcess.start(program,arguments);
	}
}

void mainfrm::f_gene_dvdauthorxml()
{
	// *** RECHERCHE SI TRANSITIONS ENTRE MENUS ***

	wg_int_001 = 0;
	float wl_lumavalue;
	QImage wl_img_001(720,576,QImage::Format_ARGB32_Premultiplied);
	QImage wl_img_002(720,576,QImage::Format_ARGB32_Premultiplied);
	QImage wl_img_003(720,576,QImage::Format_ARGB32_Premultiplied);
	QImage wl_img_004(720,576,QImage::Format_ARGB32_Premultiplied);

	int i,j,duration,progress,x,y;
	int type_trans;
	int wl_int_001;
	int wl_int_002;
	int wl_int_003;
	int wl_int_004;
	int wl_int_005;
	int wl_int_006;
	int wl_int_007;
	int wl_int_008;
	int wl_int_009 = 0; // *** UTILISER COMME INCREMENT DE POSITION DES TRANSITIONS ***

	QString invert;
	QString wl_string_001;
	QString wl_string_002;

	QColor tmpcolor1;
	QColor tmpcolor2;
	QColor tmpcolor3;
	QColor mycolor;
	QColor mycolor2;

	int valuefade;

	QString wl_tabpnt[nbre_menuth+1];
	QString wl_tab_save_tra[100];

	QRgb srcPixel;
	QRgb srcPixel2;
	QRgb srcPixel3;
	QRgb dstPixel;
	
	QString wl_str_002,wl_str_003,wl_str_004;

	QFile wmyficext;
	QTextStream outext(&wmyficext);
	wmyficext.setFileName(path_project + "/DVD/GENE/maketrans.sh");
	wmyficext.open( QIODevice::WriteOnly );
	outext << "cd \"" + path_project + "/DVD/TEMP/\"" << endl;

	QString programf = "bash";
	QStringList argumentsf;

	while ( wg_int_001 <= nbre_menuth )
	{
		if ( table_menus_property[wg_int_001][5].left(13) == "Transition : " ) // *** INTRODUCTION VIDEO PAR TRANSITION ***
		{
			// *** RECHERCHE LES MENUS QUI POINTENT VERS CE MENU ***
			wl_int_001 = 0;
			wl_int_002 = 0;
			wl_int_003 = 0;
			wl_int_004 = 0;

			while ( wl_int_003 <= nbre_menuth )
			{
				wl_tabpnt[wl_int_003] = "0";
				wl_int_003++;
			}

			if ( wg_int_001 == 0 )
			{
				wl_tabpnt[0] = "-1";
			}

			while ( wl_int_004 <= nbre_menuth )
			{
				wl_int_002 = 0;
				while ( table_menus[wl_int_004][wl_int_002][0] != "$$$" )
				{
					if ( wg_int_001 != 0 )
					{
						if (table_menus[wl_int_004][wl_int_002][5] == "!M!Menu " + QString::number(wg_int_001) )
						{
							wl_tabpnt[wl_int_004] = "1";
						}
					}
					else
					{
						if (table_menus[wl_int_004][wl_int_002][5] == "!M!" + wg_str_int_003 )
						{
							wl_tabpnt[wl_int_004] = "1";
						}
					}
					wl_int_002++;
				}
				wl_int_004++;
			}

			wl_int_001 = 0;

			while ( wl_int_001 <= nbre_menuth )
			{
				if ( wl_tabpnt[wl_int_001] != "0" )
				{
					if ( wg_int_001 == 0 && wl_tabpnt[wl_int_001] == "-1" )
					{
						wl_img_001.fill(0);

						if ( table_menus_property[wg_int_001][0].right(4) != ".MPG" && table_menus_property[wg_int_001][0].right(4) != ".mpg" && table_menus_property[wg_int_001][0].right(4) != ".AVI" && table_menus_property[wg_int_001][0].right(4) != ".avi" )
						{
							if ( wl_img_002.load(path_project+"/DVD/MAIN/MX" + QString::number(wg_int_001) + "-0001.jpg") == false )
							{
								wl_img_002.load(path_project+"/DVD/TEMP/FD" + QString::number(wg_int_001) + ".jpg");
							}
						}
						else
						{
					   		wg_int_002 = table_menus_property[wg_int_001][0].lastIndexOf( '/' );
					    		if ( wg_int_002 != -1 )
					    		{
								if (wl_img_002.load(path_project+"/DVD/MAIN/MX" + QString::number(wg_int_001) + "-0001.jpg") == false )
								{
									wl_img_002.load(path_project+"/DVD/MAIN/" + QString::number(wg_int_001) + "-0001.jpg");
								}
							}
						}
					}
					else
					{
						if ( table_menus_property[wl_int_001][0].right(4) != ".MPG" && table_menus_property[wl_int_001][0].right(4) != ".mpg" && table_menus_property[wl_int_001][0].right(4) != ".AVI" && table_menus_property[wl_int_001][0].right(4) != ".avi" )
						{
							if ( wl_img_001.load(path_project+"/DVD/MAIN/MX" + QString::number(wl_int_001) + "-0001.jpg") == false )
							{
								wl_img_001.load(path_project+"/DVD/TEMP/FD" + QString::number(wl_int_001) + ".jpg");
							}

							if ( wl_img_002.load(path_project+"/DVD/MAIN/MX" + QString::number(wg_int_001) + "-0001.jpg") == false )
							{
								wl_img_002.load(path_project+"/DVD/TEMP/FD" + QString::number(wg_int_001) + ".jpg");
							}
						}
						else
						{
							if ( wl_img_001.load(path_project+"/DVD/MAIN/MX" + QString::number(wl_int_001) + "-0001.jpg") == false )
							{
								wl_img_001.load(path_project+"/DVD/TEMP/FD" + QString::number(wl_int_001) + ".jpg");
							}
	
							if ( wl_img_002.load(path_project+"/DVD/MAIN/MX" + QString::number(wg_int_001) + "-0001.jpg") == false )
							{
								wl_img_002.load(path_project+"/DVD/TEMP/FD" + QString::number(wg_int_001) + ".jpg");
							}

						}
					}

					// *** RECUPERATION DES INFOS DE TRANSITION ***
					wg_string_001 = "";
					j = 13;

					while ( table_menus_property[wg_int_001][5].mid(j,1) != " " )
					{
						wg_string_001 = wg_string_001 + table_menus_property[wg_int_001][5].mid(j,1);
						j++;
					}

					if ( wg_string_001 != "crossfade" )
					{
						wl_img_003.load(qApp->applicationDirPath()+"/Bibliotheque/Luma/" + wg_string_001 + ".png");
						wl_img_003 = wl_img_003.scaled(dvdxsize, dvdysize, Qt::IgnoreAspectRatio, Qt::FastTransformation);
						type_trans = 0;
					}
					else
					{
						type_trans = 1;
					}

					wl_str_004 = table_menus_property[wg_int_001][5];
				      	i = wl_str_004.lastIndexOf(" Duree : ");

					wg_string_002 = "";

					if ( i != -1 )
					{
						j = i + 9;
						while ( table_menus_property[wg_int_001][5].mid(j,1) != " " )
						{
							wg_string_002 = wg_string_002 + table_menus_property[wg_int_001][5].mid(j,1);
							j++;
						}
						duration = wg_string_002.toInt()*25;
						if ( duration < 25 )
						{
							duration = 25;
						}
					}
					else
					{
						duration = 25;
					}

				      	i = table_menus_property[wg_int_001][5].lastIndexOf(" Sens : ");

					if ( i != -1 )
					{
						wg_string_002 = "";
						j = i + 8;
						wg_string_002 = wg_string_002 + table_menus_property[wg_int_001][5].mid(j,1);
						invert = wg_string_002;
					}
					else
					{
						invert = "0";
					}

					if ( invert == "0" )
					{
						progress = (float)((float)100/(float)duration);
					}
					else
					{
						progress = (float)100 - (float)((float)100/(float)duration);
					}
					// *** CALCUL DE LA TRANSITION ***

					wg_int_002 = 0;

					label_39->setText(tr("Generation de la transition du menu : ")+QString::number(wg_int_001+1) + " << " + QString::number(wl_int_001+1));
					progress_current_dvd_3->setValue(0);
					progress_current_dvd_3->setMaximum(duration-1);

					while ( wg_int_002 < duration )
					{
						if ( type_trans == 0 )
						{
							wl_lumavalue = (float)((float)255/(float)100)*(float)progress;
							mycolor.setRed(wl_lumavalue);
							mycolor.setGreen(wl_lumavalue);
							mycolor.setBlue(wl_lumavalue);

							if ( invert == "0" )
							{
								if ( progress <= 95 )
								{
									mycolor2.setRed((float)((float)255/(float)100)*(float)(progress+5));
									mycolor2.setGreen((float)((float)255/(float)100)*(float)(progress+5));
									mycolor2.setBlue((float)((float)255/(float)100)*(float)(progress+5));
								}
								else
								{
									mycolor2.setRed(255);
									mycolor2.setGreen(255);
									mycolor2.setBlue(255);
								}
							}
							else
							{
								if ( progress >= 5 )
								{
									mycolor2.setRed((float)((float)255/(float)100)*(float)(progress-5));
									mycolor2.setGreen((float)((float)255/(float)100)*(float)(progress-5));
									mycolor2.setBlue((float)((float)255/(float)100)*(float)(progress-5));
								}
								else
								{
									mycolor2.setRed(0);
									mycolor2.setGreen(0);
									mycolor2.setBlue(0);
								}
							}

							for (y = 0; y < wl_img_001.height(); y++)
							{
								for (x = 0; x < wl_img_001.width(); x++) 
								{
									srcPixel = wl_img_001.pixel(x, y);
									srcPixel2 = wl_img_002.pixel(x, y);
									srcPixel3 = wl_img_003.pixel(x, y);
									tmpcolor1 = srcPixel;
									tmpcolor2 = srcPixel2;
									tmpcolor3 = srcPixel3;
									if ( invert == "0" )
									{
										if ( tmpcolor3.value() > mycolor.value() )
										{
											if ( tmpcolor3.value() <= mycolor2.value() )
											{
												valuefade = 100 - (float)(((float)tmpcolor3.value()/(float)2.5)-((float)mycolor.value()/(float)2.5))*(float)20;
												if (valuefade > 100 || valuefade < 0)
												{
													wl_img_004.setPixel(x, y, srcPixel);
												}
												else
												{
													tmpcolor3.setRed(tmpcolor1.red() * (1-(float)((float)valuefade/(float)100)) + tmpcolor2.red() * (float)((float)valuefade/(float)100));
													tmpcolor3.setGreen(tmpcolor1.green() * (1-(float)((float)valuefade/(float)100)) + tmpcolor2.green() * (float)((float)valuefade/(float)100));
													tmpcolor3.setBlue(tmpcolor1.blue() * (1-(float)((float)valuefade/(float)100)) + tmpcolor2.blue() * (float)((float)valuefade/(float)100));
													dstPixel = tmpcolor3.rgb();
													wl_img_004.setPixel(x, y, dstPixel);
												}
											}
											else
											{
												wl_img_004.setPixel(x, y, srcPixel);
											}
										}
										else
										{
											wl_img_004.setPixel(x, y, srcPixel2);
										}
									}
									else
									{
										if ( tmpcolor3.value() > mycolor.value() )
										{
											if ( tmpcolor3.value() >= mycolor2.value() )
											{
												valuefade = (float)(((float)tmpcolor3.value()/(float)2.5)-((float)mycolor.value()/(float)2.5))*(float)20;
												if (valuefade > 100 || valuefade < 0)
												{
													wl_img_004.setPixel(x, y, srcPixel2);
												}
												else
												{
													tmpcolor3.setRed(tmpcolor1.red() * (1-(float)((float)valuefade/(float)100)) + tmpcolor2.red() * (float)((float)valuefade/(float)100));
													tmpcolor3.setGreen(tmpcolor1.green() * (1-(float)((float)valuefade/(float)100)) + tmpcolor2.green() * (float)((float)valuefade/(float)100));
													tmpcolor3.setBlue(tmpcolor1.blue() * (1-(float)((float)valuefade/(float)100)) + tmpcolor2.blue() * (float)((float)valuefade/(float)100));
													QRgb dstPixel(tmpcolor3.rgb());
													wl_img_004.setPixel(x, y, dstPixel);
												}
											}
											else
											{
												wl_img_004.setPixel(x, y, srcPixel2);
											}
										}
										else
										{
											wl_img_004.setPixel(x, y, srcPixel);
										}
									}
									/*if ( invert == "0" )
									{
										if ( tmpcolor3.value() > mycolor.value() )
										{
											wl_img_004.setPixel(x, y, srcPixel);
										}
										else
										{
											wl_img_004.setPixel(x, y, srcPixel2);
										}
									}
									else
									{
										if ( tmpcolor3.value() > mycolor.value() )
										{
											wl_img_004.setPixel(x, y, srcPixel2);
										}
										else
										{
											wl_img_004.setPixel(x, y, srcPixel);
										}
									}*/
								}
							}
						}
						else
						{
							// *** Fondu enchaine ***
							for (y = 0; y < wl_img_001.height(); y++)
							{
								for (x = 0; x < wl_img_001.width(); x++)
								{
									srcPixel = wl_img_001.pixel(x, y);
									srcPixel2 = wl_img_002.pixel(x, y);
									tmpcolor1 = srcPixel;
									tmpcolor2 = srcPixel2;
									tmpcolor3.setRed(tmpcolor1.red() * (1-(float)((float)progress/(float)100)) + tmpcolor2.red() * (float)((float)progress/(float)100));
									tmpcolor3.setGreen(tmpcolor1.green() * (1-(float)((float)progress/(float)100)) + tmpcolor2.green() * (float)((float)progress/(float)100));
									tmpcolor3.setBlue(tmpcolor1.blue() * (1-(float)((float)progress/(float)100)) + tmpcolor2.blue() * (float)((float)progress/(float)100));
									dstPixel = tmpcolor3.rgb();
									wl_img_004.setPixel(x, y, dstPixel);
								}				
							}
						}
						if ( invert == "0" )
						{
							progress = (float)progress + (float)((float)100/(float)duration);
						}
						else
						{
							progress = (float)progress - (float)((float)100/(float)duration);
						}

						// *** SAUVEGARDE DE L'IMAGE GENEREE ***
						wl_str_002 = "0000";
						wl_str_003 = QString::number(wg_int_002+1);
						wl_str_002.replace(4-wl_str_003.length(),wl_str_003.length(),wl_str_003);

						wl_img_004.save(path_project+"/DVD/TEMP/TR" + QString::number(wg_int_001) + "-" + QString::number(wl_int_001) + "-" + wl_str_002 + ".jpg","JPEG",100);
						wg_int_002++;

						if ( wg_int_002 >= duration )	
						{
							// *** RAJOUTES QUELQUES FRAMES A CAUSE DU FRAMEDROP GENERE L'ENCODAGE ***
							wl_int_002 = 0;
							while ( wl_int_002 < 20 )
							{
								wl_str_002 = "0000";
								wl_str_003 = QString::number(wg_int_002+wl_int_002+1);
								wl_str_002.replace(4-wl_str_003.length(),wl_str_003.length(),wl_str_003);

								wl_img_004.save(path_project+"/DVD/TEMP/TR" + QString::number(wg_int_001) + "-" + QString::number(wl_int_001) + "-" + wl_str_002 + ".jpg","JPEG",100);
								wl_int_002++;
							}
						}

						progress_current_dvd_3->setValue(wg_int_002);
					}
					// *** GENERATION DE LA VIDEO DE TRANSITION ***

					QString wl_fps;
					QString wl_fps_int;

					if ( combo_format_dvd->currentIndex() > 1 )
					{
						wl_fps = "30000/1001";
						wl_fps_int = "29.97";
					}
					else
					{
						wl_fps = "25";
						wl_fps_int = "25";
					}

				      	int i = table_menus_property[wg_int_001][5].lastIndexOf(" Duree : ");
					wl_str_002 = "";

					if ( i != -1 )
					{
						int j = i + 9;
						while ( table_menus_property[wg_int_001][5].mid(j,1) != " " )
						{
							wl_str_002 = wl_str_002 + table_menus_property[wg_int_001][5].mid(j,1);
							j++;
						}
					}
					else
					{
						wl_str_002 = "1";
					}

					if ( table_menus_property[wg_int_001][8] != "" )
					{
						outext << "rm -f forcesilent.mp2" << endl;
						outext << "rm -f forcesilent.wav" << endl;
						outext << "ffmpeg -i \"" + table_menus_property[wg_int_001][8] + "\" -y -t " + wl_str_002 + " -acodec " + global_audio + " forcesilent.mp2" << endl;
					}
					else
					{
						outext << "rm -f forcesilent.mp2" << endl;
						outext << "rm -f forcesilent.wav" << endl;
						outext << "sox -n -t wav -c 2 forcesilent.wav trim 0 " + wl_str_002 << endl;
						outext << "ffmpeg -i forcesilent.wav -y -acodec " + global_audio + " -ab 192k forcesilent.mp2" << endl;
					}

					if ( dvdxsize == 720 )
					{
						if ( combo_format_dvd->currentIndex() == 0 || combo_format_dvd->currentIndex() == 1 )
						{
							outext << "ffmpeg -r " + wl_fps_int + " -i \"" + path_project +"/DVD/TEMP/TR" + QString::number(wg_int_001) + "-" + QString::number(wl_int_001) + "-%04d.jpg\" -i forcesilent.mp2 -y -target pal-dvd -acodec " + global_audio + " -aspect 4:3 -sameq -cmp 2 -subcmp 2 -r " + wl_fps_int + " \"" + path_project + "/DVD/TEMP/TRS" + QString::number(wg_int_001) + "-" + QString::number(wl_int_001) + ".mpg\"" << endl;
							//outext << "ffmpeg -i \"" + path_project +"/DVD/TEMP/ATRS" + QString::number(wg_int_001) + ".mpg\" -y -target pal-dvd -b 8000k -minrate 8000k -maxrate 8000k -aspect 4:3 -sameq -cmp 2 -subcmp 2 -r " + wl_fps_int + " \"" + path_project + "/DVD/TEMP/TRS" + QString::number(wg_int_001) + "-" + QString::number(wl_int_001) + ".mpg\"" << endl;
						}
						else
						{
							outext << "ffmpeg -r " + wl_fps_int + " -i \"" + path_project +"/DVD/TEMP/TR" + QString::number(wg_int_001) + "-" + QString::number(wl_int_001) + "-%04d.jpg\" -i forcesilent.mp2 -y -target ntsc-dvd -acodec " + global_audio + " -aspect 4:3 -sameq -cmp 2 -subcmp 2 -r " + wl_fps_int + " \"" + path_project + "/DVD/TEMP/TRS" + QString::number(wg_int_001) + "-" + QString::number(wl_int_001) + ".mpg\"" << endl;
							//outext << "ffmpeg -i \"" + path_project +"/DVD/TEMP/ATRS" + QString::number(wg_int_001) + ".mpg\" -y -target ntsc-dvd -b 8000k -minrate 8000k -maxrate 8000k -aspect 4:3 -sameq -cmp 2 -subcmp 2 -r " + wl_fps_int + " \"" + path_project + "/DVD/TEMP/TRS" + QString::number(wg_int_001) + "-" + QString::number(wl_int_001) + ".mpg\"" << endl;
						}
					}
					else
					{
						//outext << "ffmpeg -r " + wl_fps_int + " -i \"" + path_project +"/DVD/TEMP/TR" + QString::number(wg_int_001) + "-" + QString::number(wl_int_001) + "-%04d.jpg\" -i forcesilent.mp2 -y -vcodec mpeg2video -acodec " + global_audio + " -aspect 16:9 -sameq -cmp 2 -subcmp 2 -r " + wl_fps_int + " \"" + path_project + "/DVD/TEMP/ATRS" + QString::number(wg_int_001) + ".mpg\"" << endl;
						if ( combo_format_dvd->currentIndex() == 0 || combo_format_dvd->currentIndex() == 1 )
						{
							outext << "ffmpeg -r " + wl_fps_int + " -i \"" + path_project +"/DVD/TEMP/TR" + QString::number(wg_int_001) + "-" + QString::number(wl_int_001) + "-%04d.jpg\" -i forcesilent.mp2 -y -target pal-dvd -acodec " + global_audio + " -aspect 16:9 -sameq -cmp 2 -subcmp 2 -r " + wl_fps_int + " \"" + path_project + "/DVD/TEMP/TRS" + QString::number(wg_int_001) + "-" + QString::number(wl_int_001) + ".mpg\"" << endl;
							//outext << "ffmpeg -i \"" + path_project +"/DVD/TEMP/ATRS" + QString::number(wg_int_001) + ".mpg\" -y -target pal-dvd -b 8000k -minrate 8000k -maxrate 8000k -aspect 16:9 -sameq -cmp 2 -subcmp 2 -r " + wl_fps_int + " \"" + path_project + "/DVD/TEMP/TRS" + QString::number(wg_int_001) + "-" + QString::number(wl_int_001) + ".mpg\"" << endl;
						}
						else
						{
							outext << "ffmpeg -r " + wl_fps_int + " -i \"" + path_project +"/DVD/TEMP/TR" + QString::number(wg_int_001) + "-" + QString::number(wl_int_001) + "-%04d.jpg\" -i forcesilent.mp2 -y -target ntsc-dvd -acodec " + global_audio + " -aspect 16:9 -sameq -cmp 2 -subcmp 2 -r " + wl_fps_int + " \"" + path_project + "/DVD/TEMP/TRS" + QString::number(wg_int_001) + "-" + QString::number(wl_int_001) + ".mpg\"" << endl;
							//outext << "ffmpeg -i \"" + path_project +"/DVD/TEMP/ATRS" + QString::number(wg_int_001) + ".mpg\" -y -target ntsc-dvd -b 8000k -minrate 8000k -maxrate 8000k -aspect 16:9 -sameq -cmp 2 -subcmp 2 -r " + wl_fps_int + " \"" + path_project + "/DVD/TEMP/TRS" + QString::number(wg_int_001) + "-" + QString::number(wl_int_001) + ".mpg\"" << endl;
						}
					}

					wl_tab_save_tra[wl_int_009] = QString::number(wg_int_001) + "-" + QString::number(wl_int_001);
					wl_int_009++;

				}
				wl_int_001++; // *** BOUCLAGE TRANSITION POINTAGE MENU ***
			}
		}
		wg_int_001++;
	}
	progress_current_dvd_3->setValue(progress_current_dvd_3->maximum());
	outext << "exit" << endl;

	wmyficext.close();

	argumentsf.clear();
	argumentsf << path_project + "/DVD/GENE/maketrans.sh";

	proc_ffmpeg.setProcessChannelMode(QProcess::MergedChannels);
	proc_ffmpeg.start(programf,argumentsf);

	proc_ffmpeg.waitForFinished(-1);

	// *** CALCUL DU NOMBRE DE TRANSITIONS PAR MEDIAS ***
	int wl_nbre_transm = 0;
	wl_int_001 = 0;
	while ( wl_int_001 <= nbre_menuth )
	{
		if ( table_menus_property[wl_int_001][5] != "" && table_menus_property[wl_int_001][5].left(13) != "Transition : " )
		{
			wl_nbre_transm++;
		}
		wl_int_001++;
	}

	// *** CREATION LIST DES MEDIAS ***
	QStringList listmedia;
	QStringList wl_explode_playlist;
	QString wl_str_001;
	QString wl_str_222;
	QString wl_str_bannonce = "";
	wg_int_001=0;

	while ( wg_int_001 < nbre_medias )
	{
		listmedia << table_hdl_medias[wg_int_001]->pathname_media;
		wg_int_001++;
	}

	// *** GENERATION DE LA STRUCTURE DE DVDAUTHOR.XML ***
	step_render = 2;
      	QFile wmyfic(path_project + "/DVD/GENE/dvdauthor.xml");

	QString tab_order_bt[23];

	if ( !wmyfic.open( QIODevice::WriteOnly ))
	{
		qDebug() << "ERROR CREATING DVDAUTHOR.XML IN : " + path_project + "/DVD/GENE/";
		return;
	}
	else
	{
		QTextStream out(&wmyfic);
		// *** GENERATION DU MAIN MENU ***
		out << "<?xml version=\"1.0\" encoding=\"utf-8\"?>" << endl;
		out << "<dvdauthor>" << endl; //jumppad=\"1\"
		out << "<vmgm>" << endl;

		int wl_cumul_annonce=0;

		// *** RECHERCHE SI BANDE ANNONCE SUR DVD ***
		wg_int_001=0;

		while ( wg_int_001 < nbre_medias && wg_int_001 < 999 )
		{
			if ( table_hdl_medias[wg_int_001]->isdvdintro == 1 )
			{
				out << "<fpc>jump title 1;</fpc>" << endl;
				wl_int_008 = table_hdl_medias[wg_int_001]->pathname_media.lastIndexOf( '/' );
    	  			wg_string_002 = table_hdl_medias[wg_int_001]->pathname_media.mid(wl_int_008 + 1, table_hdl_medias[wg_int_001]->pathname_media.length() - (wl_int_008 + 1));
				wl_str_bannonce = "<pgc>\n<vob file=\"" + path_project + "/DVD/MEDIAS/" + wg_string_002 + "\" pause=\"0\"></vob>\n<post>audio=0; g5=0 ;call vmgm menu ;</post>\n</pgc>\n";
				wl_cumul_annonce=1;
				wg_int_001 = 999;
			}
			wg_int_001++;
		}

		out << "<menus>" << endl;
		out << "<audio format=\"" + global_audio + "\" channels=\"2\" samplerate=\"48khz\" />";

		// *** POINT D'ENTREE DU DVD ***

		if ( combo_format_dvd->currentIndex() > 1 )
		{
			wl_str_001 = "720x480";
		}
		else
		{
			wl_str_001 = "720x576";
		}
		out << "<video format=\"" + dvd_standard + "\" resolution=\"" + wl_str_001 + "\" ></video>" << endl;
		out << "<pgc entry=\"title\">" << endl;
		if ( table_menus_property[0][5] != "" )
		{
			wg_int_003 = table_menus_property[0][5].lastIndexOf( '/' );
  			wg_string_001 = QString::number(0) + table_menus_property[0][5].mid(wg_int_003 + 1, table_menus_property[0][5].length() - (wg_int_003 + 1));

			if ( table_menus_property[0][5].left(13) == "Transition : " )
			{
				out << "<vob file=\"" + path_project + "/DVD/TEMP/TRS0-0.mpg\" pause=\"0\"></vob>" << endl;
			}
			else
			{
				out << "<vob file=\"" + path_project + "/DVD/MEDIAS/" + wg_string_001 + "\" pause=\"0\"></vob>" << endl;
			}
		}
		out << "<post>g5=0;jump titleset 1 menu;</post>"  << endl;
		out << "</pgc>" << endl;
		out << "</menus>" << endl;
		out << "</vmgm>" << endl;

		out << "<titleset>" << endl;
		out << "<menus>" << endl;
		out << "<audio format=\"" + global_audio + "\" channels=\"2\" samplerate=\"48khz\" />" << endl;
		if ( combo_format_dvd->currentIndex() == 0 || combo_format_dvd->currentIndex() == 2 )
		{
			out << "<video aspect=\"4:3\"/>" << endl;
		}
		else
		{
			out << "<video aspect=\"16:9\"/>" << endl;
		}
		out << "<pgc entry=\"root\">" << endl;
		out << "<pre> {" << endl;
		out << "if ( g5 == 0 ) jump menu 2;" << endl;
		out << "if ( g5 == 1 ) jump menu 2;" << endl;
		wg_int_001 = 0;
		while ( wg_int_001 < nbre_menuth )
		{
			out << "if ( g5 == " + QString::number(wg_int_001+2) + " ) jump menu " + QString::number(wg_int_001+3) + ";" << endl;
			wg_int_001++;
		}
		out << "} </pre>" << endl;
		out << "</pgc>" << endl;
		wg_int_001 = 0;
		wl_int_001 = nbre_menuth+2;
		wl_int_002 = 0;
		wl_int_003 = 0;
		wl_int_004 = 0;
		wl_int_005 = 0;
		wl_int_006 = 0; // *** RECHERCHE SOUNDTRACK ***
		wl_int_007 = 1; // *** BOUTON SUIVI MEDIAS ***
		wl_int_008 = 0;
		QString wl_audiojump;
		QString wl_tab_medias[300];

		while ( wg_int_001 <= nbre_menuth )
		{
			out << "<pgc>" << endl;
			out << "<pre> { if ( g4 gt 0 ) button=g4; } </pre>" << endl; 
			/*out << "if ( g2 gt 0 )  { " << endl;
			out << "if ( g2 eq 1 ) jump titleset 1 menu entry root;" << endl;
			out << "jump title 1;		}" << endl;
			out << "} </pre>" << endl;*/

			wl_int_004 = 0;
			wl_int_005 = 0;
			while ( table_menus[wg_int_001][wl_int_004][0] != "$$$" )
			{
				if ( table_menus[wg_int_001][wl_int_004][11] == "0" ) // *** TEST SI PAS UN LABEL ***
				{
					wg_int_003 = listmedia.indexOf ( table_menus[wg_int_001][wl_int_004][5], 0 );
					if ( wg_int_003 >= 0 )
					{
						if ( table_menus[wg_int_001][wl_int_004][19] == "" || table_menus[wg_int_001][wl_int_004][19] == wg_str_int_006 )
						{
							wl_audiojump = "";
						}
						else
						{
							wl_int_006 = 0;

							while ( wl_int_006 < 10 && table_menus[wg_int_001][wl_int_004][19] != table_hdl_medias[wg_int_003]->table_soundtrack[wl_int_006] )
							{
								wl_int_006++;
							}

							wl_audiojump = " audio=" + QString::number(wl_int_006+1)+";"; //127+
						}

						if ( table_menus[wg_int_001][wl_int_004][9] == "" || table_menus[wg_int_001][wl_int_004][9] == wg_str_int_001 )
						{
							// *** LIRE UN MEDIA ***
							tab_order_bt[table_menus[wg_int_001][wl_int_004][16].toInt()] = "<button name=\"" + QString::number(wl_int_005+1) + "\">{ g4=" + QString::number(wl_int_005+1) + "; " + wl_audiojump + " jump title " + QString::number(wl_int_007+wl_cumul_annonce) + "; }</button>";
						}
						else
						{
							// *** LIRE UN CHAPITRE D'UN MEDIA ***
							wg_int_004 = 0;
							while ( table_hdl_medias[wg_int_003]->chapitres[wg_int_004] != table_menus[wg_int_001][wl_int_004][9] )
							{
								wg_int_004++;
							}
							tab_order_bt[table_menus[wg_int_001][wl_int_004][16].toInt()] = "<button name=\"" + QString::number(wl_int_005+1) + "\">{ g4=" + QString::number(wl_int_005+1) + "; " + wl_audiojump + " jump title " + QString::number(wl_int_007+wl_cumul_annonce) + " chapter " + QString::number(wg_int_004+2) + "; }</button>";
						}
						// *** CONSTRUCTION CHAINE MEDIAS ***

						// *** INSERTION DES INFOS DE BANDES SONS ***
						wg_int_002 = 0;
						while ( wg_int_002 < 8 && table_hdl_medias[wg_int_003]->table_soundtrack[wg_int_002] != "" )
						{
							wl_tab_medias[wl_int_007] = "<audio lang=\"T" + QString::number(wg_int_002+1) + "\" />" + "\n";
							wg_int_002++;
						}

						wl_tab_medias[wl_int_007] = wl_tab_medias[wl_int_007] + "<pgc>" + "\n";

						// *** CONSTRUCTION DE LA LISTE DES CHAPITRES ***
						wg_int_002 = 0;
						wg_string_001 = "0";
						while ( wg_int_002 < table_hdl_medias[wg_int_003]->nbre_chapitres )
						{
							wg_string_001 = wg_string_001 + "," + table_hdl_medias[wg_int_003]->chapitres[wg_int_002];
							wg_int_002++;
						}

						if ( wg_string_001 == "0" )
						{
							wl_int_008 = table_hdl_medias[wg_int_003]->pathname_media.lastIndexOf( '/' );
			    	  			wg_string_002 = table_hdl_medias[wg_int_003]->pathname_media.mid(wl_int_008 + 1, table_hdl_medias[wg_int_003]->pathname_media.length() - (wl_int_008 + 1));
							wl_tab_medias[wl_int_007] = wl_tab_medias[wl_int_007] + "<vob file=\"" + path_project + "/DVD/MEDIAS/" + wg_string_002 + "\"></vob>" + "\n";
						}
						else
						{
							wl_int_008 = table_hdl_medias[wg_int_003]->pathname_media.lastIndexOf( '/' );
			    	  			wg_string_002 = table_hdl_medias[wg_int_003]->pathname_media.mid(wl_int_008 + 1, table_hdl_medias[wg_int_003]->pathname_media.length() - (wl_int_008 + 1));
							wl_tab_medias[wl_int_007] = wl_tab_medias[wl_int_007] + "<vob file=\"" + path_project + "/DVD/MEDIAS/" + wg_string_002 + "\" chapters=\"" + wg_string_001 + "\"></vob>" + "\n";
						}

						if ( table_menus[wg_int_001][wl_int_004][22] != "" )
						{
							wl_str_222 = table_menus[wg_int_001][wl_int_004][22];
							wl_explode_playlist = wl_str_222.split("$*$", QString::SkipEmptyParts);

							for (int i = 0; i < wl_explode_playlist.size(); ++i)
							{
								if ( wl_explode_playlist.at(i).toUtf8().mid(0,2) != "> " )
								{
									wg_int_003 = listmedia.indexOf ( wl_explode_playlist.at(i).toLocal8Bit().constData(), 0 );
									if ( wg_int_003 >= 0 )
									{
										wl_int_008 = table_hdl_medias[wg_int_003]->pathname_media.lastIndexOf( '/' );
						    	  			wg_string_002 = table_hdl_medias[wg_int_003]->pathname_media.mid(wl_int_008 + 1, table_hdl_medias[wg_int_003]->pathname_media.length() - (wl_int_008 + 1));
										wg_int_002 = 0;
										wg_string_001 = "0";
										while ( wg_int_002 < table_hdl_medias[wg_int_003]->nbre_chapitres )
										{
											wg_string_001 = wg_string_001 + "," + table_hdl_medias[wg_int_003]->chapitres[wg_int_002];
											wg_int_002++;
										}
										wl_tab_medias[wl_int_007] = wl_tab_medias[wl_int_007] + "<vob file=\"" + path_project + "/DVD/MEDIAS/" + wg_string_002 + "\" chapters=\"" + wg_string_001 + "\"></vob>\n";
									}
									else
									{
										qDebug() << "ERROR FINDING MEDIA IN RENDER POSITION 1" << wl_explode_playlist.at(i).toUtf8().constData();
									}
								}
								else
								{
									// *** LA PLAYLIST POINTE VERS UN MENU ***
									if ( wl_explode_playlist.at(i).toLocal8Bit().mid(0,2) == wg_str_int_003 )
									{
										wl_tab_medias[wl_int_007] = wl_tab_medias[wl_int_007] + "<post>audio=0; g5=0; call menu;</post>\n";
									}
									else
									{
										wg_int_003 = wl_explode_playlist.at(i).toLocal8Bit().lastIndexOf( " " );
										if (wg_int_003 != -1)
										{
											wl_tab_medias[wl_int_007] = wl_tab_medias[wl_int_007] + "<post>audio=0; g5=" + QString::number(wl_explode_playlist.at(i).toLocal8Bit().mid(wg_int_003,wl_explode_playlist.at(i).toLocal8Bit().length()-wg_int_003).toInt() + 1) + "; call menu;</post>\n";
										}
										else
										{
											wl_tab_medias[wl_int_007] = wl_tab_medias[wl_int_007] + "<post>audio=0; g5=0; call menu;</post>\n";
										}
									}
								}
							}
						}

						wl_tab_medias[wl_int_007] = wl_tab_medias[wl_int_007] + "</pgc>" + "\n";
						wl_int_007++;
					}
					else
					{
						// *** SAUT SUR UN MENU ***

						if ( table_menus[wg_int_001][wl_int_004][5] == "" || table_menus[wg_int_001][wl_int_004][5] == wg_str_int_002 )
						{
							tab_order_bt[table_menus[wg_int_001][wl_int_004][16].toInt()] =  "<button name=\"" + QString::number(wl_int_005+1) + "\">{ g4=" + QString::number(wl_int_005+1) + "; }</button>";
						}
						else
						{
							if ( table_menus[wg_int_001][wl_int_004][5].mid(3,table_menus[wg_int_001][wl_int_004][5].length()-3) == wg_str_int_003 && table_menus_property[0][5] == "" )
							{
								tab_order_bt[table_menus[wg_int_001][wl_int_004][16].toInt()] =  "<button name=\"" + QString::number(wl_int_005+1) + "\">{ g4=" + QString::number(wl_int_005+1) + "; jump menu 2; }</button>";
							}
							else
							{
								if ( table_menus[wg_int_001][wl_int_004][5].mid(3,table_menus[wg_int_001][wl_int_004][5].length()-3) == wg_str_int_003 )
								{
									wg_string_003 = "0";
								}
								else
								{
									wg_string_003 = table_menus[wg_int_001][wl_int_004][5];
									wg_string_003.remove(0,8);
								}

								if ( table_menus_property[wg_string_003.toInt()][5] == "" ) // *** SI PAS D'INTRO VIDEO *** || wg_string_003.toInt() <= wg_int_001
								{
									if ( table_menus[wg_int_001][wl_int_004][5].mid(3,table_menus[wg_int_001][wl_int_004][5].length()-3) == wg_str_int_003 )
									{
										tab_order_bt[table_menus[wg_int_001][wl_int_004][16].toInt()] =  "<button name=\"" + QString::number(wl_int_005+1) + "\">{ g4=" + QString::number(wl_int_005+1) + "; jump menu 2; }</button>";
									}
									else
									{
										tab_order_bt[table_menus[wg_int_001][wl_int_004][16].toInt()] =  "<button name=\"" + QString::number(wl_int_005+1) + "\">{ g4=" + QString::number(wl_int_005+1) + "; jump menu " + QString::number(wg_string_003.toInt() + 2) + "; }</button>";
									}
								}
								else
								{ // *** LE JUMP EMMENE D'ABORD A UNE TRANSITION ***

									wl_int_001 = 0;
									if ( table_menus_property[wg_string_003.toInt()][5].left(13) == "Transition : " )
									{
										wl_string_001 =  wg_string_003 + "-" + QString::number(wg_int_001);
										wl_int_002=0;
										while ( wl_tab_save_tra[wl_int_001] != wl_string_001 ) //wg_int_001
										{
											if ( wl_tab_save_tra[wl_int_001] != "0-0" )
											{
												wl_int_002++;
											}
											wl_int_001++;
										}
										tab_order_bt[table_menus[wg_int_001][wl_int_004][16].toInt()] =  "<button name=\"" + QString::number(wl_int_005+1) + "\">{ g4=" + QString::number(wl_int_005+1) + "; jump menu " + QString::number((nbre_menuth+1)+wl_int_002+2+wl_nbre_transm) + "; }</button>";
									}
									else
									{
										wl_int_003 = 0;

										while ( wl_int_003 <= wg_string_003.toInt() )
										{
											if ( table_menus_property[wl_int_003][5].left(13) != "Transition : " && table_menus_property[wl_int_003][5] != "" )
											{
												wl_int_001++;
											}
											wl_int_003++;
										}
										tab_order_bt[table_menus[wg_int_001][wl_int_004][16].toInt()] =  "<button name=\"" + QString::number(wl_int_005+1) + "\">{ g4=" + QString::number(wl_int_005+1) + "; jump menu " + QString::number((nbre_menuth + 2)+wl_int_001) + "; }</button>";
									}
								}
							}
						}
					}
					wl_int_005++;
				}
				wl_int_004++;
			}

			wl_int_003 = 0;

			while ( wl_int_003 <= wl_int_005 )
			{
				if ( tab_order_bt[wl_int_003] != "" )
				{
					out << tab_order_bt[wl_int_003] << endl;
				}
				wl_int_003++;
			}

			if ( table_menus_property[wg_int_001][7].mid(0,1) == "0" )
			{
				out << "<vob pause=\"inf\" file=\"" + QString::number(wg_int_001) + ".mpg\"></vob>" << endl;
			}
			else
			{
				out << "<vob file=\"" + QString::number(wg_int_001) + ".mpg\"></vob>" << endl;
				out << "<post>g4=button; g2=0; jump cell 1; </post>" << endl;
			}
			out << "</pgc>" << endl;

			wg_int_001++;
		}

		// *** POINT DE BOUCLAGE POUR LES VIDEOS D'INTRODUCTION ***

		wl_int_001 = 0;

		while ( wl_int_001 <= nbre_menuth )
		{
			if ( table_menus_property[wl_int_001][5] != "" && table_menus_property[wl_int_001][5].left(13) != "Transition : " )
			{
				out << "<pgc>" << endl;

				wg_int_003 = table_menus_property[wl_int_001][5].lastIndexOf( '/' );
    	  			wg_string_001 = QString::number(wl_int_001) + table_menus_property[wl_int_001][5].mid(wg_int_003 + 1, table_menus_property[wl_int_001][5].length() - (wg_int_003 + 1));
				out << "<vob file=\"" + path_project + "/DVD/MEDIAS/" + wg_string_001 + "\" pause=\"0\"></vob>" << endl;
				out << "<post>audio=0; jump menu " + QString::number(wl_int_001+2) + ";</post>" << endl;
				out << "</pgc>" << endl;
			}
			wl_int_001++;
		}

		wl_int_001 = 0;

		while ( wl_int_001 < wl_int_009 )
		{
			if ( wl_tab_save_tra[wl_int_001] != "0-0" )
			{
				out << "<pgc>" << endl;

				out << "<vob file=\"" + path_project + "/DVD/TEMP/TRS" + wl_tab_save_tra[wl_int_001] + ".mpg\" pause=\"0\"></vob>" << endl;

				wl_string_001 =  wl_tab_save_tra[wl_int_001];
				wl_int_002 = 0;

				wl_string_002 = "";

				while ( wl_string_001.mid(wl_int_002,1) != "-" && wl_int_002 < wl_string_001.length() ) //wg_int_001
				{
					wl_string_002 = wl_string_002 + wl_string_001.mid(wl_int_002,1);
					wl_int_002++;
				}

				out << "<post>audio=0; jump menu " + QString::number(wl_string_002.toInt()+2) + ";</post>" << endl;
				out << "</pgc>" << endl;
			}
			wl_int_001++;
		}

		out << "</menus>" << endl;
		out << "<titles>" << endl;

		if ( combo_format_dvd->currentIndex() == 0 || combo_format_dvd->currentIndex() == 2 )
		{
			if ( combo_format_dvd->currentIndex() == 0 )
			{
				wg_string_003 = "<video format=\"pal\" aspect=\"4:3\" />";
			}
			else
			{
				wg_string_003 = "<video format=\"ntsc\" aspect=\"4:3\" />";
			}
		}
		else
		{
			if ( combo_format_dvd->currentIndex() == 1 )
			{
				wg_string_003 = "<video format=\"pal\" aspect=\"16:9\" />";
			}
			else
			{
				wg_string_003 = "<video format=\"ntsc\" aspect=\"16:9\" />";
			}
		}

		out << wg_string_003 << endl;

		QTime wl_time_001(0,0,0);

		wg_int_001=1;

		if ( wl_str_bannonce != "" )
		{
			out << wl_str_bannonce;
		}

		while ( wg_int_001 < wl_int_007 )
		{
			out << wl_tab_medias[wg_int_001]; 
			wg_int_001++;
		}		

		/*while ( wg_int_001 < nbre_medias )
		{
			// *** INSERTION DES INFOS DE BANDES SONS ***
			wg_int_002 = 0;
			while ( wg_int_002 < 8 && table_hdl_medias[wg_int_001]->table_soundtrack[wg_int_002] != "" )
			{
				out << "<audio lang=\"T" + QString::number(wg_int_002+1) + "\" />" << endl;
				wg_int_002++;
			}

			out << "<pgc>" << endl;

			// *** CONSTRUCTION DE LA LISTE DES CHAPITRES ***
			wg_int_002 = 0;
			wg_string_001 = "0";
			while ( wg_int_002 < table_hdl_medias[wg_int_001]->nbre_chapitres )
			{
				wg_string_001 = wg_string_001 + "," + table_hdl_medias[wg_int_001]->chapitres[wg_int_002];
				wg_int_002++;
			}

			if ( wg_string_001 == "0" )
			{
				wg_int_003 = table_hdl_medias[wg_int_001]->pathname_media.lastIndexOf( '/' );
    	  			wg_string_002 = table_hdl_medias[wg_int_001]->pathname_media.mid(wg_int_003 + 1, table_hdl_medias[wg_int_001]->pathname_media.length() - (wg_int_003 + 1));
				out << "<vob file=\"" + path_project + "/DVD/MEDIAS/" + wg_string_002 + "\"></vob>" << endl;
			}
			else
			{
				wg_int_003 = table_hdl_medias[wg_int_001]->pathname_media.lastIndexOf( '/' );
    	  			wg_string_002 = table_hdl_medias[wg_int_001]->pathname_media.mid(wg_int_003 + 1, table_hdl_medias[wg_int_001]->pathname_media.length() - (wg_int_003 + 1));
				out << "<vob file=\"" + path_project + "/DVD/MEDIAS/" + wg_string_002 + "\" chapters=\"" + wg_string_001 + "\"></vob>" << endl;
			}

			if ( table_hdl_medias[wg_int_001]->wl_quoifaire_after == "" )
			{
				out << "<post>audio=0; call vmgm menu 1;</post>" << endl;
			}
			else
			{
				if ( table_hdl_medias[wg_int_001]->wl_quoifaire_after == wg_str_int_003 )
				{
					out << "<post>audio=0; call menu 1;</post>" << endl;
				}
				else
				{
					if ( table_hdl_medias[wg_int_001]->wl_quoifaire_after.left(4) == "Menu" )
					{
						wl_int_001 = table_hdl_medias[wg_int_001]->wl_quoifaire_after.lastIndexOf( ' ' );
						wl_int_002 = table_hdl_medias[wg_int_001]->wl_quoifaire_after.mid(wl_int_001+1,table_hdl_medias[wg_int_001]->wl_quoifaire_after.length()-(wl_int_001+1)).toInt();
						out << "<post>audio=0; call menu " + QString::number(wl_int_002+1) + ";</post>" << endl;
					}
					else
					{
						if ( table_hdl_medias[wg_int_001]->wl_quoifaire_after == wg_str_int_005 )
						{
							// *** PAUSE DE LA LECTURE ***
						}
						else
						{
							//  *** RECHERCHE DE LA POSITION DU MEDIA ***
							wl_int_002=0;
							while ( wl_int_002 < nbre_medias && table_hdl_medias[wl_int_002]->pathname_media != table_hdl_medias[wg_int_001]->wl_quoifaire_after )
							{
								wl_int_002++;
							}
							if ( table_hdl_medias[wl_int_002]->pathname_media == table_hdl_medias[wg_int_001]->wl_quoifaire_after )
							{
								out << "<post>jump title " + QString::number(wl_int_002+1) + ";</post>" << endl;
							}
							else
							{
								out << "<post>audio=0; call vmgm menu 1;</post>" << endl;
							}
						}
					}
				}
			}

			out << "</pgc>" << endl;
			wg_int_001++;
		}*/

		out << "</titles>" << endl;
		out << "</titleset>" << endl;
		out << "</dvdauthor>"<< endl;

		wmyfic.close();

	     	wmyfic.setFileName(path_project + "/DVD/GENE/launchdvdauthor.sh");
	
		if ( !wmyfic.open( QIODevice::WriteOnly ))
		{
			qDebug() << "ERROR LAUNCHING DVDAUTHOR";
			return;
		}
		else
		{
			QTextStream out(&wmyfic);
			out << "cd \"" + path_project + "/DVD/GENE/\"" << endl;
			out << "dvdauthor -o \"" + path_project + "/RESULT/\" -x dvdauthor.xml" << endl;
			out << "rm -f " + path_project + "/DVD/MAIN/*.*" << endl;
			out << "rm -f " + path_project + "/DVD/TEMP/FD*.jpg" << endl;
			out << "rm -f " + path_project + "/DVD/TEMP/TR*.jpg" << endl;
			out << "rm -f " + path_project + "/DVD/TEMP/ATR*.mpg" << endl;
			out << "exit" << endl;
			wmyfic.close();

			QString program = "bash";
			QStringList arguments;
	       		arguments << path_project + "/DVD/GENE/launchdvdauthor.sh";
		      	renderProcess.setProcessChannelMode(QProcess::MergedChannels);
		      	renderProcess.start(program,arguments);
		}
	}
}

void mainfrm::f_gene_mencoder()
{
	smenuBar->setDisabled(true);
	label_14->setText("Progression de la video actuelle");
	QString wl_audio_delay;
	// *** GENERATION DES FICHIERS A ENCODER ***
	wg_int_001 = 0;
	step_render = 0;
	int wl_bitrate=0;
	QString wl_str_encfmt="";
	ismultiplex = 0;
      	QFile wmyfic(path_project + "/DVD/GENE/encode.sh");

	if ( !wmyfic.open( QIODevice::WriteOnly ))
	{
		qDebug() << "ERROR CREATING ENCODE.SH IN : " + path_project + "/DVD/GENE/";
		return;
	}
	else
	{
		QString wl_fps;
		QString wl_effects;
		QTextStream out(&wmyfic);
		out << "rm -f " + path_project + "/DVD/GENE/*.wav" << endl;
		out << "rm -f " + path_project + "/DVD/GENE/*.mp2" << endl;
		out << "rm -f " + path_project + "/DVD/GENE/*.mpg" << endl;
		out << "rm -f " + path_project + "/DVD/MAIN/*.*" << endl;
		out << "rm -f " + path_project + "/DVD/TEMP/FD*.*" << endl;
		out << "rm -f " + path_project + "/DVD/TEMP/MS*.*" << endl;
		out << "rm -f " + path_project + "/DVD/TEMP/MC*.*" << endl;
		out << "rm -rf " + path_project + "/RESULT/" << endl;

		out << "cd \"" + path_project + "/DVD/TEMP/\"" << endl;

		if ( combo_format_dvd->currentIndex() > 1 )
		{
			wl_fps = "30000/1001";
		}
		else
		{
			wl_fps = "25";
		}

		while ( wg_int_001 < nbre_medias )
		{
			if ( table_hdl_medias[wg_int_001]->wl_video_sync != "" )
			{
				wl_audio_delay = "-delay " + QString::number((table_hdl_medias[wg_int_001]->wl_video_sync.toFloat()/1000)) + " ";
			}
			else
			{
				wl_audio_delay = "";
			}
			if ( ((float)table_hdl_medias[wg_int_001]->wl_vbitrate_encode.toInt()/(float)1000) > wl_vmax )
			{
				wl_bitrate=wl_vmax;
			}
			else
			{
				wl_bitrate=((float)table_hdl_medias[wg_int_001]->wl_vbitrate_encode.toInt()/(float)1000);
			}

			// *** FABRICATION DE LA CHAINE EFFECTS ***
			wl_effects = ",eq2=1.0:";
			if ( table_hdl_medias[wg_int_001]->contraste < 0 )
			{
				wl_effects = wl_effects+QString::number(1+((float)table_hdl_medias[wg_int_001]->contraste/(float)50))+":";
			}
			else
			{
				if ( table_hdl_medias[wg_int_001]->contraste > 0 )
				{
					wl_effects = wl_effects+QString::number(1+((float)table_hdl_medias[wg_int_001]->contraste/(float)100))+":";
				}
				else
				{
					wl_effects = wl_effects + "1.0:";
				}
			}
			wl_effects = wl_effects + QString::number((float)table_hdl_medias[wg_int_001]->lumiere/(float)100)+":";
			//wl_effects = wl_effects + ",hue=0:";
			if ( table_hdl_medias[wg_int_001]->saturation < 0 )
			{
				wl_effects = wl_effects + QString::number(1+((float)table_hdl_medias[wg_int_001]->saturation/(float)100));
			}
			else
			{
				if ( table_hdl_medias[wg_int_001]->saturation > 0 )
				{
					wl_effects = wl_effects + QString::number(1+((float)(2*table_hdl_medias[wg_int_001]->saturation)/(float)100));
				}
				else
				{
					wl_effects = wl_effects + "1.0";
				}
			}

			/*if ( wl_effects == ",eq2=1.0:0,hue=0:0" )
			{
				wl_effects = "";
			}*/


			if ( (table_hdl_medias[wg_int_001]->isdvd == 0 || table_hdl_medias[wg_int_001]->wl_sub_path != "" || wl_effects != ",eq2=1.0:1.0:0:1.0" || ((float)table_hdl_medias[wg_int_001]->wl_vbitrate_encode.toInt()/(float)1024) > wl_vmax) && table_hdl_medias[wg_int_001]->already_encode == 0 )
			{
				if ( table_hdl_medias[wg_int_001]->isdvd == 1 )
				{
					wl_str_encfmt = "-oac copy -ovc lavc";
				}
				else
				{
					wl_str_encfmt = "-oac lavc -ovc lavc";
				}

				if ( table_hdl_medias[wg_int_001]->wl_sub_path != "" )
				{
					wg_string_002 = "-sub \"" + table_hdl_medias[wg_int_001]->wl_sub_path + "\" ";
				}
				else
				{
					wg_string_002 = "";
				}

				wg_int_002 = table_hdl_medias[wg_int_001]->pathname_media.lastIndexOf( '/' );
    	  			wg_string_001 = table_hdl_medias[wg_int_001]->pathname_media.mid(wg_int_002 + 1, table_hdl_medias[wg_int_001]->pathname_media.length() - (wg_int_002 + 1));
				if ( table_hdl_medias[wg_int_001]->wl_format == "1.3333" )
				{
					if ( combo_format_dvd->currentIndex() < 2 )
					{
						out << "mencoder -v " + wl_str_encfmt + " -of mpeg -mpegopts format=dvd:tsaf -vf scale=" + QString::number(dvdxsize) + ":" + QString::number(dvdysize) + wl_effects + ",harddup" + " -srate 48000 -af lavcresample=48000 " + wl_audio_delay + "-lavcopts vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:threads=" + QString::number(nbre_threads) + ":vrc_buf_size=1835:vrc_maxrate=" + QString::number(wl_vmax) + ":vbitrate=" + QString::number(wl_bitrate) +  ":keyint=15:vstrict=0:acodec=" + global_audio + ":abitrate=192:aspect=4/3 " + wg_string_002 + "-ofps " + wl_fps + " -o \"" + path_project + "/DVD/MEDIAS/" + wg_string_001 + "\" \"" + table_hdl_medias[wg_int_001]->pathname_media + "\" | perl " + qApp->applicationDirPath() + "/fake.pl" << endl; 
					}
					else
					{
						out << "mencoder -v " + wl_str_encfmt + " -of mpeg -mpegopts format=dvd:tsaf -vf scale=" + QString::number(dvdxsize) + ":" + QString::number(dvdysize) + wl_effects + ",harddup" + " -srate 48000 -af lavcresample=48000 " + wl_audio_delay + "-lavcopts vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:threads=" + QString::number(nbre_threads) + ":vrc_buf_size=1835:vrc_maxrate=" + QString::number(wl_vmax) + ":vbitrate=" + QString::number(wl_bitrate) +  ":keyint=18:vstrict=0:acodec=" + global_audio + ":abitrate=192:aspect=4/3 " + wg_string_002 + "-ofps " + wl_fps + " -o \"" + path_project + "/DVD/MEDIAS/" + wg_string_001 + "\" \"" + table_hdl_medias[wg_int_001]->pathname_media + "\" | perl " + qApp->applicationDirPath() + "/fake.pl" << endl; 
					}
				}
				else
				{
					out << "mencoder -v " + wl_str_encfmt + " -of mpeg -mpegopts format=dvd:tsaf:telecine -vf scale=720:576" + wl_effects + ",harddup" + " -srate 48000 -af lavcresample=48000 " + wl_audio_delay + "-lavcopts vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:threads=" + QString::number(nbre_threads) + ":vrc_buf_size=1835:vrc_maxrate=" + QString::number(wl_vmax) + ":vbitrate=" + QString::number(wl_bitrate) + ":keyint=15:vstrict=0:acodec=" + global_audio + ":abitrate=192:aspect=16/9 " + wg_string_002 + "-ofps " + wl_fps + " -o \"" + path_project + "/DVD/MEDIAS/" + wg_string_001 + "\" \"" + table_hdl_medias[wg_int_001]->pathname_media + "\" | perl " + qApp->applicationDirPath() + "/fake.pl" << endl;
				}
				out << "echo GIBOSTEP" << endl;
			}
			else
			{
				if ( table_hdl_medias[wg_int_001]->already_encode == 0 )
				{
					wg_int_002 = table_hdl_medias[wg_int_001]-> pathname_media.lastIndexOf( '/' );
	    	  			wg_string_001 = table_hdl_medias[wg_int_001]-> pathname_media.mid(wg_int_002 + 1, table_hdl_medias[wg_int_001]->pathname_media.length() - (wg_int_002 + 1));
					out << "cp \"" + table_hdl_medias[wg_int_001]-> pathname_media + "\" \"" + path_project + "/DVD/MEDIAS/" + wg_string_001 + "\"" << endl;
					out << "echo GIBOSTEP" << endl;
				}
			}
			wg_int_001++;
		}

		// *** MULTIPLEXAGE DES BANDES SON ***

		wg_int_001 = 0;
		int wl_nbremix = 0;
		QString wl_straudiotrack;
		QString wl_straudiotrack_2;

		while ( wg_int_001 < nbre_medias )
		{
			wl_straudiotrack = "";
			wl_straudiotrack_2 = "";
			wg_int_002 = 0;
			while ( table_hdl_medias[wg_int_001]->table_soundtrack[wg_int_002] != "" && table_hdl_medias[wg_int_001]->already_encode == 0 )
			{
				wl_straudiotrack = wl_straudiotrack + "-i \"" + table_hdl_medias[wg_int_001]->table_soundtrack[wg_int_002] + "\" ";
				wl_straudiotrack_2 = wl_straudiotrack_2 + "-acodec " + global_audio + " -ab 192000 -ar 48000 -newaudio ";
				wg_int_002++;
			}
			wg_int_002 = table_hdl_medias[wg_int_001]-> pathname_media.lastIndexOf( '/' );
  			wg_string_001 = table_hdl_medias[wg_int_001]->pathname_media.mid(wg_int_002 + 1, table_hdl_medias[wg_int_001]->pathname_media.length() - (wg_int_002 + 1));
			if ( wl_straudiotrack != "" )
			{
				out << "echo GIBOTRACK" << endl;
				out << "echo PROGMUX" << table_hdl_medias[wg_int_001]->wl_duree << endl;
				if ( combo_format_dvd->currentIndex() == 0 || combo_format_dvd->currentIndex() == 1 )
				{
					out << "ffmpeg -i \"" + path_project + "/DVD/MEDIAS/" + wg_string_001 + "\" " + wl_straudiotrack + "-vcodec copy -acodec copy -y -f vob -target pal-dvd \"" + path_project + "/DVD/MEDIAS/.TP.mpg\" " + wl_straudiotrack_2 << endl;
				}
				else
				{
					out << "ffmpeg -i \"" + path_project + "/DVD/MEDIAS/" + wg_string_001 + "\" " + wl_straudiotrack + "-vcodec copy -acodec copy -y -f vob -target ntsc-dvd \"" + path_project + "/DVD/MEDIAS/.TP.mpg\" " + wl_straudiotrack_2 << endl;
				}
				out << "mv -f \"" + path_project + "/DVD/MEDIAS/.TP.mpg\" \"" + path_project + "/DVD/MEDIAS/" + wg_string_001 + "\"" << endl;
				out << "echo GIBOSTEP" << endl;
				wl_nbremix++;
			}
			wg_int_001++;
		}

		wg_int_002 = 0;

		out << "cd \"" + path_project + "/DVD/MAIN\"" << endl;

		while ( wg_int_002 <= nbre_menuth ) // *** EXTRACTION DES IMAGES DE LA VIDEO POUR L'ARRIERE PLAN ***
		{
			if ( table_menus_property[wg_int_002][0].right(4) == ".MPG" || table_menus_property[wg_int_002][0].right(4) == ".mpg" || table_menus_property[wg_int_002][0].right(4) == ".AVI" || table_menus_property[wg_int_002][0].right(4) == ".avi" )
			{
				if ( combo_format_dvd->currentIndex() > 1 )
				{
					wl_fps = "30000/1001";
				}
				else
				{
					wl_fps = "25";
				}
				out << "ffmpeg -i \"" + table_menus_property[wg_int_002][0] + "\" -y -r " + wl_fps + " -t " + table_menus_property[wg_int_002][7].mid(1,table_menus_property[wg_int_002][7].length()-1) + " -sameq -f image2 \"" + QString::number(wg_int_002) + "-%4d.jpg\"" << endl;
				out << "echo GIBOSTEP" << endl;
				wg_int_001++;
			}

			if ( table_menus_property[wg_int_002][5] != "" && table_menus_property[wg_int_002][5].left(13) != "Transition : " ) // *** INTRODUCTION VIDEO ***
			{
				wg_int_003 = table_menus_property[wg_int_002][5].lastIndexOf( '/' );
    	  			wg_string_001 = QString::number(wg_int_002) + table_menus_property[wg_int_002][5].mid(wg_int_003 + 1, table_menus_property[wg_int_002][5].length() - (wg_int_003 + 1));
				if ( dvdxsize == 720 )
				{
					if ( combo_format_dvd->currentIndex() < 2 )
					{
						out << "mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf -vf scale=" + QString::number(dvdxsize) + ":" + QString::number(dvdysize) + ",harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:threads=" + QString::number(nbre_threads) + ":vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:vstrict=0:acodec=" + global_audio + ":abitrate=192:aspect=4/3 -ofps " + wl_fps + " -o \"" + path_project + "/DVD/MEDIAS/" + wg_string_001 + "\" \"" + table_menus_property[wg_int_002][5] + "\" | perl " + qApp->applicationDirPath() + "/fake.pl" << endl;
					}
					else
					{
						out << "mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf -vf scale=" + QString::number(dvdxsize) + ":" + QString::number(dvdysize) + ",harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:threads=" + QString::number(nbre_threads) + ":vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=18:vstrict=0:acodec=" + global_audio + ":abitrate=192:aspect=4/3 -ofps " + wl_fps + " -o \"" + path_project + "/DVD/MEDIAS/" + wg_string_001 + "\" \"" + table_menus_property[wg_int_002][5] + "\" | perl " + qApp->applicationDirPath() + "/fake.pl" << endl;
					}
				}
				else
				{
					out << "mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf -vf scale=720:576,harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:threads=" + QString::number(nbre_threads) + ":vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:vstrict=0:acodec=" + global_audio + ":abitrate=192:aspect=16/9 -ofps " + wl_fps + " -o \"" + path_project + "/DVD/MEDIAS/" + wg_string_001 + "\" \"" + table_menus_property[wg_int_002][5] + "\" | perl " + qApp->applicationDirPath() + "/fake.pl" << endl;
				}
				out << "echo GIBOSTEP" << endl;
				wg_int_001++;
			}

			wg_int_002++;
		}

		wg_int_002 = 0;

		while ( wg_int_002 <= nbre_menuth )
		{
			wg_int_003 = 0;
			while ( table_menus[wg_int_002][wg_int_003][0] != "$$$" )
			{
				if ( table_menus[wg_int_002][wg_int_003][14] != "0" )
				{
					if ( table_menus[wg_int_002][wg_int_003][4].right(4) != ".MPG" && table_menus[wg_int_002][wg_int_003][4].right(4) != ".mpg" && table_menus[wg_int_002][wg_int_003][4].right(4) != ".AVI" && table_menus[wg_int_002][wg_int_003][4].right(4) != ".avi" && table_menus[wg_int_002][wg_int_003][4].left(5) != "$TXT$" )
					{
						if ( table_menus[wg_int_002][wg_int_003][9] == wg_str_int_001 )
						{
							out << "ffmpeg -i \"" + table_menus[wg_int_002][wg_int_003][5] + "\" -y -r " + wl_fps + " -t " + table_menus_property[wg_int_002][7].mid(1,table_menus_property[wg_int_002][7].length()-1) + " -f image2 \"MB" + QString::number(wg_int_003) + "-" + QString::number(wg_int_002) + "-%4d.jpg\"" << endl;
						}
						else
						{
							out << "ffmpeg -i \"" + table_menus[wg_int_002][wg_int_003][5] + "\" -y -r " + wl_fps + " -t " + table_menus_property[wg_int_002][7].mid(1,table_menus_property[wg_int_002][7].length()-1) + " -ss " + table_menus[wg_int_002][wg_int_003][9] + " -f image2 \"MB" + QString::number(wg_int_003) + "-" + QString::number(wg_int_002) + "-%4d.jpg\"" << endl;
						}
					}
					else
					{
						if ( table_menus[wg_int_002][wg_int_003][4].left(5) != "$TXT$" )
						{
							out << "ffmpeg -i \"" + table_menus[wg_int_002][wg_int_003][4] + "\" -y -r " + wl_fps + " -t " + table_menus_property[wg_int_002][7].mid(1,table_menus_property[wg_int_002][7].length()-1) + " -f image2 \"MB" + QString::number(wg_int_003) + "-" + QString::number(wg_int_002) + "-%4d.jpg\"" << endl;
						}
					}
					out << "echo GIBOSTEP" << endl;
					wg_int_001++;
				}
				wg_int_003++;
			}
			wg_int_002++;
		}
		out << "exit" << endl;
		wmyfic.close();
		//
		progress_current_dvd_2->setMaximum(wg_int_001+wl_nbremix);
		//
		QString program = "bash";
		QStringList arguments;
       		arguments << path_project + "/DVD/GENE/encode.sh";
	      	renderProcess.setProcessChannelMode(QProcess::MergedChannels);
	      	renderProcess.start(program,arguments);
	}
}

// **********************************
// *** FONCTION GLOBALES DE RENDU ***
// **********************************

void mainfrm::render_end(int, QProcess::ExitStatus)
{
	if ( step_render == 0 )
	{
		bt_cancel_encoding->setDisabled(true);
		progress_current_dvd->setValue(100);
		progress_current_dvd_2->setValue(progress_current_dvd_2->maximum());

		if ( iserror == 0 )
		{
			wg_int_001 = 0;
			while ( wg_int_001 < nbre_medias )
			{
				table_hdl_medias[wg_int_001]->already_encode = 1;
				wg_int_001++;
			}
		}

		f_make_menus();
	}
	else
	{
		if ( step_render == 1 )
		{
			f_gene_dvdauthorxml();
		}
		else
		{
			if ( step_render == 2 )
			{
				// *** SAUVEGARDE DE LA LOG ***
				QByteArray buffer(renderProcess.readLine());
				logstring = logstring + buffer;
			     	QFile logfile(path_project + "/logfile.txt");

				if ( !logfile.open( QIODevice::WriteOnly ))
				{
					qDebug() << "ERROR CREATING FILE FOR LOGFILE IN : " + path_project;
					return;
				}
				QTextStream outlog(&logfile);

				outlog << logstring << endl;
				logfile.close();

				if ( iserror == 0 )
				{
					// *** DEZONAGE DU DVD ***
					QFile fd(path_project + "/RESULT/VIDEO_TS/VIDEO_TS.IFO");

					if (fd.open(QIODevice::ReadWrite) == true)
					{
						fd.seek(0x23);

						switch(dvdzone)
						{
						case 0:
							fd.putChar(0x0);
							break;
						case 1:
							fd.putChar(QChar(254).toAscii());
							break;
						case 2:
							fd.putChar(QChar(253).toAscii());
							break;
						case 3:
							fd.putChar(QChar(251).toAscii());
							break;
						case 4:
							fd.putChar(QChar(247).toAscii());
							break;
						case 5:
							fd.putChar(QChar(239).toAscii());
							break;
						case 6:
							fd.putChar(QChar(223).toAscii());
							break;
						}

						fd.close();
					}
					else
					{
						qDebug() << "CAN'T OPEN STREAM TO UNZONE";
					}

					if ( isnotify == 1 )
					{
						QString programf = "notify-send";
						QStringList argumentsf;
						argumentsf << "-i" << qApp->applicationDirPath() + "/Interface/emblem2.png";
						argumentsf << "2ManDVD";
						argumentsf << tr("La generation du DVD est terminee avec succes");
					      	proc_ffmpeg.setProcessChannelMode(QProcess::MergedChannels);
						proc_ffmpeg.start(programf,argumentsf);
					}

					frame_render->hide();
					actionGraver_le_DVD->setEnabled(true);
					actionGenerer_l_image_ISO_du_DVD->setEnabled(true);
					actionRevoir_la_derniere_generation->setEnabled(true);
					frame_endencoding->show();
					frame_endencoding->raise();
				}
				else
				{
					if ( isnotify == 1 )
					{
						QString programf = "notify-send";
						QStringList argumentsf;
						argumentsf << "-i" << qApp->applicationDirPath() + "/Interface/emblem2.png";
						argumentsf << "2ManDVD";
						argumentsf << tr("Erreur pendant la generation du DVD. Veuillez consulter le fichier logfile.txt du dossier de votre projet");
					      	proc_ffmpeg.setProcessChannelMode(QProcess::MergedChannels);
						proc_ffmpeg.start(programf,argumentsf);
					}
					else
					{
						QMessageBox::information(this, name_application, tr("Erreur pendant la generation du DVD. Veuillez consulter le fichier logfile.txt du dossier de votre projet : ") + path_project);
					}
					smenuBar->setEnabled(true);
					actionGraver_le_DVD->setDisabled(true);
					actionGenerer_l_image_ISO_du_DVD->setDisabled(true);
					actionRevoir_la_derniere_generation->setDisabled(true);
					mask_interface->hide();
					frame_render->hide();
				}
			}
		}
	}
}

void mainfrm::f_encoding_end()
{
	// *** ANNULATION DU PROCESS D'ENCODAGE ***
	step_render = 2;
	iserror = 2;
	renderProcess.kill();
}

void mainfrm::render_stdout()
{
	QByteArray buffer(renderProcess.readLine());
	logstring = logstring + buffer;
	if ( step_render == 0 )
	{
		wg_string_003 = buffer;
		wg_int_002 = wg_string_003.lastIndexOf( "%)" );
		if ( wg_int_002 > 0 )
		{
			if ( wg_string_003.mid(wg_int_002-2,1) == " " )
			{
				progress_current_dvd->setValue(wg_string_003.mid(wg_int_002-1,1).toInt());
			}
			else
			{
				progress_current_dvd->setValue(wg_string_003.mid(wg_int_002-2,2).toInt());
			}
		}

		wg_int_002 = wg_string_003.lastIndexOf( "GIBOTRACK" );
		if ( wg_int_002 >= 0 )
		{
			label_14->setText("Multiplexage bande son");
			ismultiplex = 1;
		}

		wg_int_002 = wg_string_003.lastIndexOf( "PROGMUX" );
		if ( wg_int_002 >= 0 )
		{
			wg_string_001 = "";
			while ( wg_string_003.mid(wg_int_002+7,1) != "" )
			{
				wg_string_001 = wg_string_001 + wg_string_003.mid(wg_int_002+7,1);
				wg_int_002++;
			}
			progress_current_dvd_2->setMaximum(wg_string_001.toInt()*25);
		}

		wg_int_002 = wg_string_003.lastIndexOf( "frame= " );
		if ( wg_int_002 >= 0 )
		{
			wg_string_001 = "";
			while ( wg_string_003.mid(wg_int_002+9,1) != "q" && wg_string_003.mid(wg_int_002+9,1) != "f" )
			{
				if ( wg_string_003.mid(wg_int_002+7,1) != " " )
				{
					wg_string_001 = wg_string_001 + wg_string_003.mid(wg_int_002+7,1);
				}
				wg_int_002++;
			}
			progress_current_dvd->setValue(wg_string_001.toInt());
		}

		wg_int_002 = wg_string_003.lastIndexOf( "GIBOSTEP" );
		if ( wg_int_002 >= 0 )
		{
			if ( ismultiplex == 0 )
			{
				progress_current_dvd_2->setValue(progress_current_dvd_2->value()+1);
			}
		}

		wg_int_002 = wg_string_003.lastIndexOf("File not found:");
		if (wg_int_002 != -1)
		{
			wg_int_002 = wg_string_003.lastIndexOf("File not found: 'frameno.avi'");
			if (wg_int_002 == -1)
			{
				iserror = 1;
			}
		}

		wg_int_002 = wg_string_003.lastIndexOf("Seek failed");
		if (wg_int_002 >= 0)
		{
			iserror = 1;
		}

		/*wg_int_002 = wg_string_003.lastIndexOf("Missing video stream");
		if (wg_int_002 > 0)
		{
			iserror = 1;
		}*/

		wg_int_002 = wg_string_003.lastIndexOf("Sorry, this file format is not recognized/supported");
		if (wg_int_002 > 0)
		{
			iserror = 1;
		}
	}
	else
	{
		if ( step_render == 1 )
		{
			wg_string_003 = buffer;
			wg_int_002 = wg_string_003.lastIndexOf( "GIBOSTEP" );
			if ( wg_int_002 >= 0 )
			{
				progress_current_dvd_3->setValue(progress_current_dvd_3->value()+1);
			}

			wg_int_002 = wg_string_003.lastIndexOf("s->numpal");
			if (wg_int_002 >= 0)
			{
				iserror = 1;
			}

			wg_int_002 = wg_string_003.lastIndexOf("ERROR");
			if (wg_int_002 >= 0)
			{
				iserror = 1;
			}
			wg_int_002 = wg_string_003.lastIndexOf("Button coordinates out of range");
			if (wg_int_002 >= 0)
			{
				iserror = 1;
			}
		}
		else
		{
			wg_string_003 = buffer;
			wg_int_002 = wg_string_003.lastIndexOf("Error:");
			if (wg_int_002 >= 0)
			{
				iserror = 1;
			}

			wg_int_002 = wg_string_003.lastIndexOf("Error ");
			if (wg_int_002 >= 0)
			{
				iserror = 1;
			}

			wg_int_002 = wg_string_003.lastIndexOf("ERR:");
			if (wg_int_002 >= 0)
			{
				iserror = 1;
			}

			wg_int_002 = wg_string_003.lastIndexOf("WARN: Partial sector read");
			if (wg_int_002 >= 0)
			{
				iserror = 1;
			}

			wg_int_002 = wg_string_003.lastIndexOf("PCI/DSI information is not where expected");
			if (wg_int_002 >= 0)
			{
				iserror = 1;
			}

			wg_int_002 = wg_string_003.lastIndexOf("Button coordinates out of range");
			if (wg_int_002 >= 0)
			{
				iserror = 1;
			}

			wg_int_002 = wg_string_003.lastIndexOf("Erreur de segmentation");
			if (wg_int_002 >= 0)
			{
				iserror = 1;
			}
		}
	}
}

void mainfrm::f_close_endencoding()
{
	smenuBar->setEnabled(true);
	mask_interface->hide();
	frame_endencoding->hide();
}

void mainfrm::f_view_result()
{
	/*smenuBar->setDisabled(true);
	frame_preview_finish->show();
	frame_preview_finish->raise();

        if ( mplayerProcess.state() == QProcess::Starting || mplayerProcess.state() == QProcess::Running )
	{
		mplayerProcess.kill();
		mplayerProcess.waitForFinished(1000);	
		mplayer_timer->stop();
        }
       	QStringList args;
        args << "-slave";
        //args << "-osdlevel" << "0";
        //args << "-noquiet";
	//args << "-zoom";
	//args << "-double";
	//args << "-tsprobe" << "1";
	//args << "-dr";
	args << "-nocache";
        args << "-wid" << QString::number(frame_player_result->winId()); //
	args << "-vo" << "gl"; //:nomanyfmts";
	args << "-mouse-movements";
	args << "dvdnav:///" + path_project + "/RESULT/";
        mplayerProcess.setProcessChannelMode(QProcess::MergedChannels);
      	mplayerProcess.start("mplayer", args);
      	if(!mplayerProcess.waitForStarted(3000))
      	{
		QMessageBox::information(this, name_application, tr("Impossible de demarrer mplayer. Est t il installe correctement dans /usr/bin ?"));
	}*/
	
       	QStringList args;
        args << "dvd://" + path_project + "/RESULT/";
      	nullProcess.start("xine", args);
      	if(!nullProcess.waitForStarted(3000))
      	{
		QMessageBox::information(this, name_application, tr("Impossible de demarrer xine. Est t il installe correctement dans /usr/bin ?"));
	}
}

void mainfrm::f_dvdnav_1()
{
	QString mycom = "dvdnav up \n";
	mplayerProcess.write( mycom.toUtf8(),mycom.length() );
}

void mainfrm::f_dvdnav_2()
{
	QString mycom = "dvdnav left \n";
	mplayerProcess.write( mycom.toUtf8(),mycom.length() );
}

void mainfrm::f_dvdnav_3()
{
	QString mycom = "dvdnav right \n";
	mplayerProcess.write( mycom.toUtf8(),mycom.length() );
}

void mainfrm::f_dvdnav_4()
{
	QString mycom = "dvdnav down \n";
	mplayerProcess.write( mycom.toUtf8(),mycom.length() );
}

void mainfrm::f_dvdnav_5()
{
	QString mycom = "dvdnav select \n";
	mplayerProcess.write( mycom.toUtf8(),mycom.length() );
}

void mainfrm::f_dvdnav_6()
{
	QString mycom = "pausing_keep dvdnav menu \n";
	mplayerProcess.write( mycom.toUtf8(),mycom.length() );
}

void mainfrm::f_dvdnav_7()
{
	QString mycom = "pausing_keep seek_chapter -2 0 \n";
	mplayerProcess.write( mycom.toUtf8(),mycom.length() );
}

void mainfrm::f_dvdnav_8()
{
	QString mycom = "pausing_keep seek_chapter +1 0 \n";
	mplayerProcess.write( mycom.toUtf8(),mycom.length() );
}

void mainfrm::f_dvdnav_9()
{
	QString mycom = "pausing_keep gui_play \n";
	mplayerProcess.write( mycom.toUtf8(),mycom.length() );
}

// ********************************
// *** CREATION DE L'ISO DU DVD ***
// ********************************

void mainfrm::f_create_iso()
{
	QString wmyprj = QFileDialog::getSaveFileName(this, tr("ISO du DVD"), path_project, tr("Image iso (*.iso)"));
       	if ( wmyprj.isNull() )
       	{
		return;
       	}
	else
	{
		if ( wmyprj.right(4) != ".iso" )
		{
			wmyprj = wmyprj + ".iso";
		}
	      	QFile wmyfic(path_project + "/DVD/GENE/geniso.sh");

		if ( !wmyfic.open( QIODevice::WriteOnly ))
		{
			qDebug() << "ERROR CREATING GENISO.SH IN : " + path_project + "/DVD/GENE/";
			return;
		}
		else
		{
			pb_geniso->setValue(0);
			frame_iso->show();
			frame_iso->raise();

			logstring = "";

			QTextStream out(&wmyfic);
			out << "mkisofs -dvd-video -o \"" + wmyprj + "\" \"" + path_project + "/RESULT/\"" << endl;
			out << "rm -f " + path_project + "/DVD/GENE/geniso.sh" << endl;
			out << "exit" << endl;
			wmyfic.close();

			QString program = "bash";
			QStringList arguments;
			arguments << path_project + "/DVD/GENE/geniso.sh";
		      	isoProcess.setProcessChannelMode(QProcess::MergedChannels);
		      	isoProcess.start(program,arguments);
		}
	}
}

void mainfrm::f_read_outiso()
{
	//if (isoProcess.canReadLine())
        //{
        	QByteArray buffer(isoProcess.readLine());
		wg_string_003 = buffer;
		logstring = logstring + buffer;
		wg_int_002 = wg_string_003.lastIndexOf( "%" );
		if ( wg_int_002 > 0 )
		{
			if ( wg_string_003.mid(wg_int_002-5,1) == " " )
			{
				pb_geniso->setValue(wg_string_003.mid(wg_int_002-4,1).toInt());
			}
			else
			{
				pb_geniso->setValue(wg_string_003.mid(wg_int_002-5,2).toInt());
			}
		}
	//}
}

void mainfrm::f_giso_end(int, QProcess::ExitStatus)
{
	// *** SAUVEGARDE DE LA LOG ***
	QByteArray buffer(isoProcess.readLine());
	wg_string_003 = buffer;
	logstring = logstring + buffer;
     	QFile logfile(path_project + "/logiso.txt");

	if ( !logfile.open( QIODevice::WriteOnly ))
	{
		qDebug() << "ERROR CREATING FILE FOR LOGFILE IN : " + path_project;
		return;
	}
	QTextStream outlog(&logfile);

	outlog << logstring << endl;
	logfile.close();
	pb_geniso->setValue(100);
	if ( isnotify == 1 )
	{
		QString programf = "notify-send";
		QStringList argumentsf;
		argumentsf << "-i" << qApp->applicationDirPath() + "/Interface/emblem2.png";
		argumentsf << "2ManDVD";
		argumentsf << tr("Creation de l'image ISO terminee avec succes");
	      	proc_ffmpeg.setProcessChannelMode(QProcess::MergedChannels);
		proc_ffmpeg.start(programf,argumentsf);
	}
	else
	{
		QMessageBox::information(this, name_application, tr("Image ISO cree"));
	}
	frame_iso->hide();
}

// **********************
// *** GRAVAGE DU DVD ***
// **********************

void mainfrm::f_open_burn()
{
	pb_burn->setPixmap(QPixmap(":/Interface/Interface/dvd_empty.png"));
	frame_endencoding->hide();
	frame_burn->show();
	frame_burn->raise();
}

void mainfrm::f_open_burn_2()
{
	// *** OUVERTURE DE LA FENTRE DE GRAVAGE DEPUIS L'APPLICATION EN EDITION ***
	pb_burn->setPixmap(QPixmap(":/Interface/Interface/dvd_empty.png"));

	top_window->setDisabled(true);
	frame_pro->setDisabled(true);
	smenuBar->setDisabled(true);
	frame_editor->setDisabled(true);
	frame_lst_menus->setDisabled(true);

	frame_burn->show();
	frame_burn->raise();
}

void mainfrm::f_cancel_burn()
{
	frame_burn->hide();
	if ( mask_interface->isVisible() == true )
	{
		frame_endencoding->show();
		frame_endencoding->raise();
	}
	else
	{
		top_window->setEnabled(true);
		frame_pro->setEnabled(true);
		smenuBar->setEnabled(true);
		frame_editor->setEnabled(true);
		frame_lst_menus->setEnabled(true);
	}
}

void mainfrm::f_go_burn()
{
	pb_burn->setPixmap(QPixmap(":/Interface/Interface/dvd_empty.png"));
      	QFile wmyfic(path_project + "/DVD/GENE/burndvd.sh");

	if ( !wmyfic.open( QIODevice::WriteOnly ))
	{
		qDebug() << "ERROR CREATING BURNDVD.SH IN : " + path_project + "/DVD/GENE/";
		return;
	}
	else
	{
		QTextStream out(&wmyfic);
		out << "growisofs -Z " + pathgraveur->text() + " -J -R -dvd-compat -dvd-video " + path_project + "/RESULT\n";
		out << "rm -f " + path_project + "/DVD/GENE/burndvd.sh" << endl;
		out << "exit" << endl;
		wmyfic.close();

		bt_cancel_burn->setDisabled(true);
		bt_go_burn->setDisabled(true);
		pathgraveur->setDisabled(true);

		iserror = 0;

		QString program = "bash";
		QStringList arguments;
		arguments << path_project + "/DVD/GENE/burndvd.sh";
	      	idvProcess.setProcessChannelMode(QProcess::MergedChannels);
	      	idvProcess.start(program,arguments);
	}
}

void mainfrm::f_read_outidv()
{
	if (idvProcess.canReadLine())
        {
        	QByteArray buffer(idvProcess.readLine());
		wg_string_003 = buffer;

		wg_int_002 = wg_string_003.lastIndexOf( "%" );
		if (wg_int_002 != -1)
		{
			if ( wg_string_003.mid (1, 1) == " " )
			{
				wg_string_003 = wg_string_003.mid(2, 1);
			}
			else
			{
				wg_string_003 = wg_string_003.mid(1, 2);
			}
			QPixmap wl_pix_001(":/Interface/Interface/dvd_empty.png");
			QPixmap wl_pix_002(":/Interface/Interface/dvd_theme.png");
			int wl_int_001 = (wg_string_003.toInt()*wl_pix_001.height())/100;
			QPainter p;
			p.begin(&wl_pix_001);
			QFont myfont("DejaVu Sans Condensed");
			myfont.setPixelSize ( 16 );
			myfont.setBold(true);
			p.setFont(myfont);
			p.drawPixmap(0, wl_pix_001.height()-wl_int_001, wl_pix_002, 0, wl_pix_001.height()-wl_int_001, -1, wl_int_001);
			p.drawText(QRect(7,83,50,30), Qt::AlignVCenter | Qt::AlignHCenter, wg_string_003 + "%");
			p.end();
			pb_burn->setPixmap(wl_pix_001);
		}

		wg_int_002 = wg_string_003.lastIndexOf( "error" );
		if (wg_int_002 != -1)
		{
			iserror = 1;
		}

		wg_int_002 = wg_string_003.lastIndexOf( " not recognized" );
		if (wg_int_002 != -1)
		{
			iserror = 1;
		}

		wg_int_002 = wg_string_003.lastIndexOf( "Unable" );
		if (wg_int_002 != -1)
		{
			iserror = 1;
		}
	}
}

void mainfrm::f_idvd_end(int, QProcess::ExitStatus)
{
	QPixmap wl_pix_001(":/Interface/Interface/dvd_theme.png");
	QPainter p;
	p.begin(&wl_pix_001);
	QFont myfont("DejaVu Sans Condensed");
	myfont.setPixelSize ( 16 );
	myfont.setBold(true);
	p.setFont(myfont);
	p.drawText(QRect(7,83,50,30), Qt::AlignVCenter | Qt::AlignHCenter, "100%");
	p.end();
	pb_burn->setPixmap(wl_pix_001);

	bt_cancel_burn->setEnabled(true);
	bt_go_burn->setEnabled(true);
	pathgraveur->setEnabled(true);
	if ( isnotify == 1 )
	{
		QString programf = "notify-send";
		QStringList argumentsf;
		argumentsf << "-i" << qApp->applicationDirPath() + "/Interface/emblem3.png";
		argumentsf << "2ManDVD";
		if ( iserror == 0 )
		{
			argumentsf << tr("Gravure du DVD terminee avec succes");
		}
		else
		{
			argumentsf << tr("Erreur pendant la gravure");
		}
	      	proc_ffmpeg.setProcessChannelMode(QProcess::MergedChannels);
		proc_ffmpeg.start(programf,argumentsf);
	}
	else
	{
		if ( iserror == 0 )
		{
			QMessageBox::information(this, name_application, tr("Gravure du DVD terminee avec succes"));
		}
		else
		{
			QMessageBox::information(this, name_application, tr("Erreur pendant la gravure"));
		}
	}
}

void mainfrm::f_read_ffmpeg()
{
	QByteArray buffer(proc_ffmpeg.readAllStandardOutput());
	wg_string_003 = wg_string_003 + buffer;
}

