<?php

/*******************************************************************************

 WINBINDER - The native Windows binding for PHP for PHP

 Copyright © Hypervisual - see LICENSE.TXT for details
 Author: Rubem Pechansky (http://winbinder.org/contact.php)

 Sound control

*******************************************************************************/

//------------------------------------------------------------ SYSTEM PARAMETERS

define('PATH_SCRIPT',	dirname(__FILE__) . '/');
define('PATH_DATA',		PATH_SCRIPT);
define('PATH_INC',		PATH_SCRIPT . '../include/');
define('PATH_RES',		PATH_SCRIPT . '../resources/');

//-------------------------------------------------------------------- CONSTANTS

define('APPNAME', 		'Sound tests');

define ('ID_STARTWAV',		101);
define ('ID_LOOPWAV',		102);
define ('ID_STOPWAV',		103);
define ('ID_STARTMIDI',		104);
define ('ID_STARTSYNC',		105);
define ('ID_STOPMIDI',		106);
define ('ID_STOPALL',		107);
define ('ID_SYSTEM',		108);

//----------------------------------------------------------------- DEPENDENCIES

include PATH_INC . "winbinder.php";

//-------------------------------------------------------------- EXECUTABLE CODE

$mainwin = wb_create_window(NULL, AppWindow, APPNAME, WBC_CENTER, WBC_CENTER, 300, 200, WBC_NOTIFY);

wb_create_control($mainwin, PushButton, 'Start WAV', 20, 20, 120, 22, ID_STARTWAV);
wb_create_control($mainwin, PushButton, 'Loop WAV',  20, 50, 120, 22, ID_LOOPWAV);
wb_create_control($mainwin, PushButton, 'Stop WAV',  20, 80, 120, 22, ID_STOPWAV);
wb_create_control($mainwin, PushButton, 'Stop all',  20,110, 120, 22, ID_STOPALL);

wb_create_control($mainwin, PushButton, 'Synchronous',150, 20, 120, 22, ID_STARTSYNC);
wb_create_control($mainwin, PushButton, 'Start MIDI', 150, 50, 120, 22, ID_STARTMIDI);
wb_create_control($mainwin, PushButton, 'Stop MIDI',  150, 80, 120, 22, ID_STOPMIDI);
wb_create_control($mainwin, PushButton, 'System',     150,110, 120, 22, ID_SYSTEM);

$wavfile = PATH_RES . 'click1.wav';
$wavfile2 = PATH_RES . 'fx2.wav';
$midifile = PATH_RES . 'canon.mid';
wb_set_handler($mainwin, 'process_main');
wb_main_loop();

//-------------------------------------------------------------------- FUNCTIONS

function process_main($window, $id, $ctrl=0, $lparam=0, $lparam2=0, $lparam3=0)
{
	global $wavfile, $wavfile2, $midifile;

	switch($id) {

		case ID_STARTWAV:
			wb_play_sound($wavfile);
			break;

		case ID_LOOPWAV:
			wb_play_sound($wavfile, 'loop');
			break;

		case ID_STOPWAV:
			wb_stop_sound('wav');
			break;

		case ID_STARTMIDI:
			wb_play_sound($midifile, 'play');
			break;

		case ID_STARTSYNC:
			wb_play_sound($wavfile2, 'sync');
			break;

		case ID_STOPMIDI:
			wb_stop_sound('midi');
			break;

		case ID_STOPALL:
			wb_stop_sound();
			break;

		case ID_SYSTEM:
			wb_play_sound(WBC_OK);
			break;

		case IDCLOSE:
			wb_destroy_window($window);
			break;
   }
}

//------------------------------------------------------------------ END OF FILE

?>