#include <windows.h>
#include <winuser.h>
#include <stdio.h>

#define SUNVOX_MAIN
#include "sunvox.h"

int main()
{	
	int noteok;
	
    if( sv_load_dll() )
	return 1;

    int ver = sv_init( 0, 44100, 2, 0 );
    if( ver >= 0 )
    {
	int major = ( ver >> 16 ) & 255;
	int minor1 = ( ver >> 8 ) & 255;
	int minor2 = ( ver ) & 255;
	printf( "SunVox lib version: %d.%d.%d\n", major, minor1, minor2 );
	
	sv_open_slot( 0 );
	
	sv_load( 0, "pcspeaker.sunvox" );
	sv_volume( 0, 256 );
	//sv_play( 0 );
	//sv_stop(0);
		
	printf("Module 1: %s\n", sv_get_module_name(0, 1));
	
	printf( "Line counter: %d\n", sv_get_current_line( 0 ) );
	
		
	// první nástroj = 2!!!	
		
		
	printf("OK\n");		
	// noteok = sv_send_event(0, 1, 120, 126, 1, 0, 0);
	noteok = sv_send_event( 0, 0, 64, 129, 2, 0, 0 );
	printf("note OK %d\n", noteok);
	
	
	
	//noteok = sv_send_event(0, 1, 120, 126, 1, 0, 0);
	//printf("note OK %d\n", noteok);
	sleep(1);
	printf("OK\n");	
	noteok = sv_send_event(0, 1, 61, 126, 2, 0, 0);
	printf("note OK %d\n", noteok);	
	sleep(1000);
	printf("OK\n");	
	noteok = sv_send_event(0, 1, 62, 126, 2, 0, 0);
	printf("note OK %d\n", noteok);
	sleep(1000);
	printf("OK\n");	
	// MessageBox( 0, TEXT("Music!"), TEXT("SunVox DLL"), MB_OK );
	
		
	printf( "Line counter: %d\n", sv_get_current_line( 0 ) );
	
	sv_stop( 0 );

	sv_close_slot( 0 );

	sv_deinit();
    }
    else 
    {
	printf( "sv_init() error %d\n", ver );
    }

    sv_unload_dll();
    
    return 0;
}
