Exemplo n.º 1
0
bool BassPlayer::initOutputDevice(const int & new_device, const int & frequency) {
    bool res = BASS_Init(new_device, frequency, 0, NULL, NULL);

    if (!res) {
        if (BASS_ErrorGetCode() == BASS_ERROR_ALREADY) {
            res = true;
        } else {
            qDebug() << "Init error: " << BASS_ErrorGetCode();
            // throw "Cannot initialize device";
        }
    }

    if (res) {
        opened_devices.insert(new_device, true);

        BASS_SetConfig(BASS_CONFIG_FLOATDSP, TRUE);
    //    BASS_SetConfig(BASS_CONFIG_NET_PREBUF, 15); // 15 percents prebuf

        setOpenTimeOut(Settings::obj().openTimeOut());
    }

    return res;
}
Exemplo n.º 2
0
void BassSoundEngine::Init()
{
	nowChannel = 0;
	sampleRate_factor = pitch_factor = tempo_factor = 0;
	intended_pitch = 1.0;

	DWORD hr;
	hr = BASS_Init(-1, defaultSampleRate, BASS_DEVICE_LATENCY, base::hwnd, NULL);
	hr = BASS_FX_GetVersion();
	hitWav = BASS_SampleLoad(false, "gamedata\\hit.wav", 0, 0, 16, 0);
#if 1==0
	HSTREAM fs1, fs2;
	fs1 = BASS_StreamCreateFile(false,"D:\\Project DIVA PC\\gamedata\\cg.mp3",0,0,BASS_STREAM_DECODE);
	fs2 = BASS_FX_TempoCreate(fs1, 0);
	hr = BASS_ErrorGetCode();
	hr = BASS_ChannelPlay(fs2, FALSE);
	hr = BASS_ChannelSetAttribute(fs2, BASS_ATTRIB_TEMPO, 50); 
	Sleep(100000);
	hr = BASS_ChannelStop(fs1);
	Sleep(2000);
#endif
	hr = 0;
}
Exemplo n.º 3
0
void setup_BASS()
{
  int i;
  if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
    printf("An incorrect version of BASS was loaded");
    return;
  }
  // setup output - default device
  if (!BASS_Init(-1,44100,0,0,NULL))
    exit(0);

    // this could probably be a simple for loop, but can't figure it out yet
    sounds[0] = BASS_StreamCreateFile(FALSE, "./sound/bang0.mp3", 0, 0, 0);
    sounds[1] = BASS_StreamCreateFile(FALSE, "./sound/bang1.mp3", 0, 0, 0);
    sounds[2] = BASS_StreamCreateFile(FALSE, "./sound/bang2.mp3", 0, 0, 0);
    sounds[3] = BASS_StreamCreateFile(FALSE, "./sound/bang3.mp3", 0, 0, 0);
    sounds[4] = BASS_StreamCreateFile(FALSE, "./sound/bang4.mp3", 0, 0, 0);
    sounds[5] = BASS_StreamCreateFile(FALSE, "./sound/bang5.mp3", 0, 0, 0);
    sounds[6] = BASS_StreamCreateFile(FALSE, "./sound/bang6.mp3", 0, 0, 0);
    sounds[7] = BASS_StreamCreateFile(FALSE, "./sound/fizz_out.wav", 0, 0, 0);
    sounds[8] = BASS_StreamCreateFile(FALSE, "./sound/1812.wav", 0, 0, 0);
    BASS_ChannelSetAttribute(sounds[7], BASS_ATTRIB_VOL, .2);
}
Exemplo n.º 4
0
int main(int argc, char* argv[])
{
	g_thread_init(NULL);
	gdk_threads_init();
	gtk_init(&argc,&argv);

	// check the correct BASS was loaded
	if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
		Error("An incorrect version of BASS was loaded");
		return 0;
	}

	// initialize default output device
	if (!BASS_Init(-1,44100,0,NULL,NULL)) {
		Error("Can't initialize device");
		return 0;
	}

	BASS_SetConfig(BASS_CONFIG_NET_PLAYLIST,1); // enable playlist processing
	BASS_SetConfig(BASS_CONFIG_NET_PREBUF,0); // minimize automatic pre-buffering, so we can do it (and display it) instead
	BASS_SetConfigPtr(BASS_CONFIG_NET_PROXY,proxy); // setup proxy server location

	// initialize GUI
	glade=glade_xml_new(GLADE_PATH"netradio.glade",NULL,NULL);
	if (!glade) return 0;
	win=GetWidget("window1");
	if (!win) return 0;
	glade_xml_signal_autoconnect(glade);

	gdk_threads_enter();
	gtk_main();
	gdk_threads_leave();

	BASS_Free();

    return 0;
}
Exemplo n.º 5
0
int main(int argc, char* argv[])
{
	gtk_init(&argc,&argv);

	// check the correct BASS was loaded
	if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
		Error("An incorrect version of BASS was loaded");
		return 0;
	}

	// initialize default output device
	if (!BASS_Init(-1,44100,0,NULL,NULL)) {
		Error("Can't initialize device");
		return 0;
	}

	// initialize GUI
	glade=glade_xml_new(GLADE_PATH"synth.glade",NULL,NULL);
	if (!glade) return 0;
	win=GetWidget("window1");
	if (!win) return 0;
	glade_xml_signal_autoconnect(glade);

	BASS_GetInfo(&info);
	stream=BASS_StreamCreate(info.freq,2,BASS_SAMPLE_FLOAT,(STREAMPROC*)WriteStream,0); // create a stream (stereo for effects)
	BASS_ChannelSetAttribute(stream,BASS_ATTRIB_NOBUFFER,1); // no buffering for minimum latency
	BASS_ChannelPlay(stream,FALSE); // start it

	g_signal_connect(win,"key-press-event",G_CALLBACK(KeyHandler),NULL);
	g_signal_connect(win,"key-release-event",G_CALLBACK(KeyHandler),NULL);

	gtk_main();

	BASS_Free();

    return 0;
}
Exemplo n.º 6
0
// --[  Method  ]---------------------------------------------------------------
//
//  - Class     : CSoundSystem
//  - prototype : bool Init(HWND hWnd)
//
//  - Purpose   : Initializes sound system.
//
// -----------------------------------------------------------------------------
bool CSoundSystem::Init(HWND hWnd)
{
    if(m_bActive)
    {
        Close();
    }

    if(BASS_Init(-1, 44100, 0, hWnd) != TRUE)
    {
        CLogger::ErrorWindow("CSoundSystem::Init(): BASS_Init() failed.");
        return false;
    }

    if(BASS_Start() != TRUE)
    {
        CLogger::ErrorWindow("CSoundSystem::Init(): BASS_Start() failed.");
        return false;
    }

    BASS_SetGlobalVolumes(100, 100, 100);

    m_bActive = true;
    return m_bActive;
}
Exemplo n.º 7
0
void PrecalcIntro()
{
	//WriteDebug("Precalc Start.\n");
	glEnable(GL_NORMALIZE);

#ifdef INCLUDE_OBJ_BUTTERFLYSMOOTH
	initVertexBlend();
#endif
	InitTextureBuffer();
	InitIntroEditorEffects();
	
	unsigned char * data= raw_precalc;
	//DisplayPrecalcAnim=false;
	pEventList=0;
	pEventNum=0;
	pEventNum=LoadDataFile((void**)&data, &pMaterialList, &pPolySelectList, &pSceneList, &pWorldList, &pEventList, -1);
	//WriteDebug("Status bar project loaded.\n");

	if (setupcfg.music)
	{
#ifdef RELEASETYPE_DEMO
		if (!BASS_Init(1,44100,0,hWnd,NULL)) exit(0);
		str=BASS_StreamCreateFile(true,music,0,music_size,0);
#else
		if (!mvxSystem_Init(hWnd,music,music_size)) exit(0);
#endif
	}
	//WriteDebug("MVX init done.\n");

	data= raw_project;

	DisplayPrecalcAnim=true;
	EventNum=LoadDataFile((void**)&data, &MaterialList, &PolySelectList, &SceneList, &WorldList, &EventList, -1 /*setupcfg.texturedetail/**/);
	glScissor(0,(YRes-XRes/16*9)/2,XRes,XRes/16*9);
	//WriteDebug("Project loaded.\n");
}
Exemplo n.º 8
0
PlaybackWidget::PlaybackWidget(QWidget *parent) : QWidget(parent)
{
    if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
        qDebug() << "Wrong bass version";
    }
    db = &DBI::getInstance();
    //Setup ui
    ui.setupUi(this);
    play = QPixmap(":/imgs/play");
    pause = QPixmap(":/imgs/pause");
    ui.prevBtn->setIcon(QIcon(QPixmap(":/imgs/prev")));
    ui.nextBtn->setIcon(QIcon(QPixmap(":/imgs/next")));
    ui.playBtn->setIcon(QIcon(play));
    connect(ui.playBtn, SIGNAL(released()), SLOT(togglePlay()));
    //Setup Audio output
    if (!BASS_Init(-1,44100,0,0,NULL))
        Error("Can't initialize device");
    curchan = NULL;
    state = STOPPED;
    updateTimer = std::unique_ptr<QTimer>(new QTimer(this));
    connect(updateTimer.get(), SIGNAL(timeout()), SLOT(update()));
    connect(ui.playSlider, SIGNAL(seekTo(float)), SLOT(seek(float)));
    updateTimer->setInterval(50);
}
Exemplo n.º 9
0
int main(int argc, char* argv[])
{
	regex_t fregex;

	gtk_init(&argc,&argv);

	// check the correct BASS was loaded
	if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
		Error("An incorrect version of BASS was loaded");
		return 0;
	}

	// initialize default device
	if (!BASS_Init(-1,44100,0,NULL,NULL)) {
		Error("Can't initialize device");
		return 0;
	}

	// initialize GUI
	glade=glade_xml_new(GLADE_PATH"speakers.glade",NULL,NULL);
	if (!glade) return 0;
	win=GetWidget("window1");
	if (!win) return 0;
	glade_xml_signal_autoconnect(glade);

	{ // check how many speakers the device supports
		BASS_INFO i;
		BASS_GetInfo(&i);
		if (i.speakers<8) {
			gtk_widget_set_sensitive(GetWidget("open4"),FALSE);
			gtk_widget_set_sensitive(GetWidget("swap3"),FALSE);
		}
		if (i.speakers<6) {
			gtk_widget_set_sensitive(GetWidget("open3"),FALSE);
			gtk_widget_set_sensitive(GetWidget("swap2"),FALSE);
		}
		if (i.speakers<4) {
			gtk_widget_set_sensitive(GetWidget("open2"),FALSE);
			gtk_widget_set_sensitive(GetWidget("swap1"),FALSE);
		}
	}

	{ // initialize file selector
		GtkFileFilter *filter;
		filesel=gtk_file_chooser_dialog_new("Open File",GTK_WINDOW(win),GTK_FILE_CHOOSER_ACTION_OPEN,
			GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,GTK_STOCK_OPEN,GTK_RESPONSE_ACCEPT,NULL);
		filter=gtk_file_filter_new();
		gtk_file_filter_set_name(filter,"Playable files");
		regcomp(&fregex,"\\.(mo3|xm|mod|s3m|it|umx|mp[1-3]|ogg|wav|aif)$",REG_ICASE|REG_NOSUB|REG_EXTENDED);
		gtk_file_filter_add_custom(filter,GTK_FILE_FILTER_FILENAME,FileExtensionFilter,&fregex,NULL);
		gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(filesel),filter);
		filter=gtk_file_filter_new();
		gtk_file_filter_set_name(filter,"All files");
		gtk_file_filter_add_pattern(filter,"*");
		gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(filesel),filter);
	}

	gtk_widget_show(win);
	gtk_main();

	gtk_widget_destroy(filesel);
	regfree(&fregex);

	BASS_Free();

    return 0;
}
Exemplo n.º 10
0
Arquivo: main.c Projeto: kusma/cb-bart
int main(){
	MSG message;
	HSTREAM stream = 0;
	object *room;
	object *sphere;
	object *sphere_copy;
	rtt_target *rendertarget;

	rtt_target *fucking_shit;

	int loading;
	int bjork_texture;
	int yo_plus;
	int carlb;
	int i;
	int veldig_kule;
	int greets;
	int mothafuckas;

	vector particles[PARTICLE_COUNT];
	make_random_particles(particles, PARTICLE_COUNT, 200);

	if(!mumps_open("CARL B!!!!1",WIDTH,HEIGHT,32,32,-1,FULLSCREEN)) error("kunne ikke lage bartevindu");
	if(!init_extensions()){
		mumps_close();
		error("kunne ikke bruke fet opengl-extension");
	}
	if (!BASS_Init(-1, 44100, 0, 0, 0)) {
		mumps_close();
		error("kunne ikke åpne fet lyd");
	}
	stream = BASS_StreamCreateFile(FALSE, "data/uglespy.ogg", 0, 0, BASS_MP3_SETPOS | BASS_STREAM_PRESCAN | 0);
	if (!stream) {
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fet lyd 2.0");
	}

	loading = load_texture("loading.jpg", FALSE);
	if(loading==-1){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett bilde");
	}

	glClearColor(0,0,0,0);
	glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
	fullscreen_image(loading);
	glFlush();
	mumps_update();


	room = load_object("cylinder01.kro");
	if(!room){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett objekt");
	}

	sphere = load_object("sphere01.kro");
	if(!sphere){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett objekt");
	}
	sphere_copy = copy_object(sphere);

	bjork_texture = load_texture("bjork.jpg", FALSE);
	if(bjork_texture==-1){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett bilde");
	}
	yo_plus = load_texture("yo_plus.jpg", FALSE);
	if(yo_plus==-1){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett bilde");
	}
	carlb = load_texture("carlb.jpg", FALSE);
	if(carlb==-1){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett bilde");
	}
	veldig_kule = load_texture("veldig_kule.jpg", FALSE);
	if(veldig_kule==-1){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett bilde");
	}
	greets = load_texture("greets.jpg", FALSE);
	if(greets==-1){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett bilde");
	}
	mothafuckas = load_texture("mothefuckas.jpg", FALSE);
	if(mothafuckas==-1){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett bilde");
	}

	rendertarget = init_rtt(512,256,(float)WIDTH/(float)HEIGHT, FALSE, FALSE);
	fucking_shit = init_rtt(512,256,(float)WIDTH/(float)HEIGHT, FALSE, TRUE);
	init_blur(256,256);

	glEnable(GL_NORMALIZE);
	
	BASS_Start();
	BASS_ChannelPlay(stream, FALSE);

	do {
		QWORD pos = BASS_ChannelGetPosition(stream, BASS_POS_BYTE);
		double time = BASS_ChannelBytes2Seconds(stream, pos);

		glViewport(0,0,mumps_width,mumps_height);

		if(time<25.55f){
			glClearColor(1,1,1,0);
			glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
			glMatrixMode(GL_TEXTURE);
			glLoadIdentity();
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();

			gluPerspective(120, ASPECT, 1.f, 500);

			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();

			glFogi(GL_FOG_MODE, GL_EXP2);
			glFogfv(GL_FOG_COLOR,black_color);
			glFogf(GL_FOG_DENSITY, 0.02f);
			glEnable(GL_FOG);

			set_camera(
				vector_make( // pos
					(float)sin(time*0.1f)*50,
					(float)sin(time*1.2f*0.1f+1)*50,
					(float)cos(sin(time*0.1f)-time*0.1f)*50
				),
				vector_make( // look_at
					0, 0, 0
				),
				0
			);

			draw_particles(particles,PARTICLE_COUNT,yo_plus, (float)15);

			if(time<2){
				float alpha = 1.f-time*0.5f;
				glPushAttrib(GL_ALL_ATTRIB_BITS);
				glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

				glColor4f(1,1,1, alpha );
				glEnable(GL_BLEND);
				fullscreen_image(loading);
				glPopAttrib();

			}

			if(time>17.5f){
				float alpha = (time-17.5);

				glPushAttrib(GL_ALL_ATTRIB_BITS);
				glBlendEquationEXT(GL_FUNC_REVERSE_SUBTRACT);
				glBlendFunc( GL_SRC_ALPHA, GL_ONE );

				glColor4f(1,1,1, alpha );
				glEnable(GL_BLEND);
				fullscreen_image(carlb);
				glPopAttrib();
			}
		}else if(time<51.0f){
			float flash = 1.f-(time-25.55f);
			glClearColor(1,1,1,0);
			glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
			glMatrixMode(GL_TEXTURE);
			glLoadIdentity();
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			gluPerspective(90, ASPECT, 1.f, 500);
			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();

			glDisable(GL_FOG);


			gluLookAt(
				sin(time*0.1f)*90,-50,cos(time*0.1f)*90,
				0,-30,0,

				0,1,0
				);

			start_rtt(rendertarget);

			set_light(0, (float)sin(time)*50,0,(float)cos(time)*50,TRUE);
			set_light(1, (float)sin(time+1)*50,0,(float)cos(time+1)*50,TRUE);

			glEnable(GL_LIGHTING);
			glEnable(GL_DEPTH_TEST);

			glPushMatrix();
			glTranslatef(100,0,-100);
			draw_object(room);
			glPopMatrix();

			glPushMatrix();
			glTranslatef(0,-30,0);
			glScalef(0.7f,0.7f,0.7f);
			glRotatef(time*15,1,0,1);
			glRotatef(time*15,1,0,0);
			glRotatef(time*15.2f,0,1,0);

			glRotatef(time*15,0,0,1);
			glRotatef(time*25,1,0,0);
			glRotatef(time*15.2f,0,1,0);

			blob_distort(sphere, sphere_copy, vector_make((float)sin(time),time,-time), vector_make(
				(float)(1+sin(time))*0.1f,
				(float)(1+sin(time))*0.1f,
				(float)(1+sin(time))*0.1f
				),vector_make(0.3f,0.3f,0.3f) );
			draw_object(sphere_copy);
			glPopMatrix();

			end_rtt(rendertarget);

			i = blur((float)sin(time*0.3f)*0.3f, 0.1f+(1+(float)sin(time*0.1f))*0.2f, 0.2f, FALSE, rendertarget->texture);

			fullscreen_image(i);

			glEnable(GL_COLOR_MATERIAL);
			glColor4f(1,1,1, (1+(float)sin(time*0.5f))*0.3f );
			glBlendFunc( GL_SRC_ALPHA, GL_ONE );
			glEnable(GL_BLEND);
			fullscreen_image(bjork_texture);
			glDisable(GL_BLEND);


			if(time>38.35f){
				flash = 1.f-(time-38.4f);
				if(time>44.75f){
					flash = 1.f-(time-44.75f);
				}
			}

			if(flash<0) flash = 0;
			superflash(flash);

			if(time>38.35f){
				overlay(veldig_kule, 1);
			}
		}else if(time<(60+16.8f)){
			float flash = (1.f-(time-51.f));
			float flash2 = sin(-(3.1415f/2)+(time-51.f)*(117.5f/60.f)*8);
			if(flash<0) flash = 0;

			flash *= flash;


			flash2 *= (1+flash2)*0.5f;
			flash2 *= 20;

			start_rtt(fucking_shit);
			draw_dilldallscene(room, sphere, sphere_copy,time,flash,flash2);
			end_rtt(fucking_shit);

			glClearColor(0,0,0,0);
			glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

			draw_dilldallscene(room, sphere, sphere_copy,time,flash,flash2);

			glLoadIdentity();

			glEnable(GL_COLOR_MATERIAL);
			glColor4f(1,1,1, 0.5+(1+(float)sin(time*0.5f))*0.5f );
			glBlendFunc( GL_SRC_ALPHA, GL_ONE );
			glEnable(GL_BLEND);
			fullscreen_image_flip(fucking_shit->texture,1);
			fullscreen_image_flip(fucking_shit->texture,2);
			fullscreen_image_flip(fucking_shit->texture,3);
			glDisable(GL_BLEND);

			fuss(50,time, 1, 1, 0.1f);
			if(time>(60+3.9f)){
				flash=(1.f-(time-(60+3.9f)));
				overlay(greets, 1);
			}
			superflash(flash);
		}else{
			float flash = (1.f-(time-(60+16.8f)));
			fullscreen_image(mothafuckas);
			superflash(flash);
			if(time>(60+23.f)){
				float flash = (time-(60+23.f));
				superflash2(flash*0.5f);
			}
		}
		glFlush();
		mumps_update();

		if(time>60+30) PostQuitMessage(0);

		while(PeekMessage(&message,NULL,0,0,PM_REMOVE)){
			TranslateMessage(&message);
			DispatchMessage(&message);
		    if(message.message == WM_QUIT) break;
		}
	}while(message.message!=WM_QUIT && !GetAsyncKeyState(VK_ESCAPE));
	BASS_StreamFree(stream);
	BASS_Free();
	mumps_close();
	MessageBox(NULL,"Frigi minnet ditt sjøl, taper","In your face",MB_OK);
	return 0;
}
Exemplo n.º 11
0
// window procedure
long FAR PASCAL SpectrumWindowProc(HWND h, UINT m, WPARAM w, LPARAM l)
{
	switch (m) {
		case WM_PAINT:
			if (GetUpdateRect(h,0,0)) {
				PAINTSTRUCT p;
				HDC dc;
				if (!(dc=BeginPaint(h,&p))) return 0;
				BitBlt(dc,0,0,SPECWIDTH,SPECHEIGHT,specdc,0,0,SRCCOPY);
				EndPaint(h,&p);
			}
			return 0;

		case WM_LBUTTONUP:
			specmode=(specmode+1)%4; // swap spectrum mode
			memset(specbuf,0,SPECWIDTH*SPECHEIGHT);	// clear display
			return 0;

		case WM_CREATE:
			win=h;
			// initialize BASS
			if (!BASS_Init(-1,44100,0,win,NULL)) {
				Error("Can't initialize device");
				return -1;
			}
			if (!PlayFile()) { // start a file playing
				BASS_Free();
				return -1;
			}
			{ // create bitmap to draw spectrum in (8 bit for easy updating)
				BYTE data[2000]={0};
				BITMAPINFOHEADER *bh=(BITMAPINFOHEADER*)data;
				RGBQUAD *pal=(RGBQUAD*)(data+sizeof(*bh));
				int a;
				bh->biSize=sizeof(*bh);
				bh->biWidth=SPECWIDTH;
				bh->biHeight=SPECHEIGHT; // upside down (line 0=bottom)
				bh->biPlanes=1;
				bh->biBitCount=8;
				bh->biClrUsed=bh->biClrImportant=256;
				// setup palette
				for (a=1;a<128;a++) {
					pal[a].rgbGreen=256-2*a;
					pal[a].rgbRed=2*a;
				}
				for (a=0;a<32;a++) {
					pal[128+a].rgbBlue=8*a;
					pal[128+32+a].rgbBlue=255;
					pal[128+32+a].rgbRed=8*a;
					pal[128+64+a].rgbRed=255;
					pal[128+64+a].rgbBlue=8*(31-a);
					pal[128+64+a].rgbGreen=8*a;
					pal[128+96+a].rgbRed=255;
					pal[128+96+a].rgbGreen=255;
					pal[128+96+a].rgbBlue=8*a;
				}
				// create the bitmap
				specbmp=CreateDIBSection(0,(BITMAPINFO*)bh,DIB_RGB_COLORS,(void**)&specbuf,NULL,0);
				specdc=CreateCompatibleDC(0);
				SelectObject(specdc,specbmp);
			}
			// setup update timer (40hz)
			timer=timeSetEvent(25,25,(LPTIMECALLBACK)&UpdateSpectrum,0,TIME_PERIODIC);
			break;

		case WM_DESTROY:
			if (timer) timeKillEvent(timer);
			BASS_Free();
			if (specdc) DeleteDC(specdc);
			if (specbmp) DeleteObject(specbmp);
			PostQuitMessage(0);
			break;
	}
	return DefWindowProc(h, m, w, l);
}
Exemplo n.º 12
0
int main(int argc, char *argv[])
{
	int ret = 0;
	try {
		// initialize directx 
		IDirect3D9 *d3d = Direct3DCreate9(D3D_SDK_VERSION);
		if (!d3d)
			throw std::string("This application requires DirectX 9");

		// create a window
		HWND hwnd = CreateWindowEx(0, "static", "GNU Rocket Example",
		    WS_POPUP | WS_VISIBLE, 0, 0, width, height, 0, 0,
		    GetModuleHandle(0), 0);

		// create the device
		IDirect3DDevice9 *device = NULL;
		static D3DPRESENT_PARAMETERS present_parameters = {width,
		    height, D3DFMT_X8R8G8B8, 3, D3DMULTISAMPLE_NONE, 0,
		    D3DSWAPEFFECT_DISCARD, 0, WINDOWED, 1, D3DFMT_D24S8,
		    0, WINDOWED ? 0 : D3DPRESENT_RATE_DEFAULT, 0
		};
		if (FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT,
		    D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING,
		    &present_parameters, &device)))
			throw std::string("Failed to create device");

		// init BASS
		int soundDevice = 1;
		if (!BASS_Init(soundDevice, 44100, 0, hwnd, 0))
			throw std::string("Failed to init bass");

		// load tune
		HSTREAM stream = BASS_StreamCreateFile(false, "tune.ogg", 0, 0,
		    BASS_MP3_SETPOS | (!soundDevice ? BASS_STREAM_DECODE : 0));
		if (!stream)
			throw std::string("Failed to open tune");

		// let's just assume 150 BPM (this holds true for the included tune)
		float bpm = 150.0f;

		// setup timer and construct sync-device
		BassTimer timer(stream, bpm, 8);
		std::auto_ptr<sync::Device> syncDevice = std::auto_ptr<sync::Device>(
		    sync::createDevice("sync", timer));
		if (!syncDevice.get())
			throw std::string("Failed to connect to host?");

		// get tracks
		sync::Track &clearRTrack = syncDevice->getTrack("clear.r");
		sync::Track &clearGTrack = syncDevice->getTrack("clear.g");
		sync::Track &clearBTrack = syncDevice->getTrack("clear.b");

		sync::Track &camRotTrack  = syncDevice->getTrack("cam.rot");
		sync::Track &camDistTrack = syncDevice->getTrack("cam.dist");

		LPD3DXMESH cubeMesh = NULL;
		if (FAILED(D3DXCreateBox(device, 1.0f, 1.0f, 1.0f, &cubeMesh, NULL)))
			return -1;

		// let's roll!
		BASS_Start();
		timer.play();

		bool done = false;
		while (!done) {
			float row = float(timer.getRow());
			if (!syncDevice->update(row))
				done = true;

			// setup clear color
			D3DXCOLOR clearColor(clearRTrack.getValue(row), clearGTrack.getValue(row), clearBTrack.getValue(row), 0.0);

			// paint the window
			device->BeginScene();
			device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, clearColor, 1.0f, 0);

/*			D3DXMATRIX world;
			device->SetTransform(D3DTS_WORLD, &world); */

			float rot = camRotTrack.getValue(row);
			float dist = camDistTrack.getValue(row);
			D3DXVECTOR3 eye(sin(rot) * dist, 0, cos(rot) * dist);
			D3DXVECTOR3 at(0, 0, 0);
			D3DXVECTOR3 up(0, 1, 0);
			D3DXMATRIX view;
			D3DXMatrixLookAtLH(&view, &(eye + at), &at, &up);
			device->SetTransform(D3DTS_WORLD, &view);

			D3DXMATRIX proj;
			D3DXMatrixPerspectiveFovLH(&proj, D3DXToRadian(60), 4.0f / 3, 0.1f, 1000.f);
			device->SetTransform(D3DTS_PROJECTION, &proj);

			cubeMesh->DrawSubset(0);

			device->EndScene();
			device->Present(0, 0, 0, 0);

			BASS_Update(0); // decrease the chance of missing vsync
			MSG msg;
			while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
				TranslateMessage(&msg);
				DispatchMessage(&msg);

				if (WM_QUIT == msg.message) done = true;
				if ((WM_KEYDOWN == msg.message) && (VK_ESCAPE == LOWORD(msg.wParam))) done = true;
			}
		}

		BASS_StreamFree(stream);
		BASS_Free();

		device->Release();
		d3d->Release();
		DestroyWindow(hwnd);
	} catch (const std::exception &e) {
#ifdef _CONSOLE
		fprintf(stderr, "*** error: %s\n", e.what());
#else
		MessageBox(NULL, e.what(), NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
#endif
		ret = -1;
	} catch (const std::string &str) {
#ifdef _CONSOLE
		fprintf(stderr, "*** error: %s\n", str.c_str());
#else
		MessageBox(NULL, e.what(), NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
#endif
		ret = -1;
	}

	return ret;
}
Exemplo n.º 13
0
BOOL CALLBACK dialogproc(HWND h,UINT m,WPARAM w,LPARAM l)
{
	switch (m) {
		case WM_COMMAND:
			switch (LOWORD(w)) {
				case IDCANCEL:
					DestroyWindow(h);
					break;
				case 10:
					{
						BASS_CHANNELINFO info;
						char file[MAX_PATH]="";
						ofn.lpstrFilter="playable files\0*.mo3;*.xm;*.mod;*.s3m;*.it;*.mtm;*.umx;*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aif\0All files\0*.*\0\0";
						ofn.lpstrFile=file;
						if (GetOpenFileName(&ofn)) {
							// free both MOD and stream, it must be one of them! :)
							BASS_MusicFree(chan);
							BASS_StreamFree(chan);
							if (!(chan=BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_LOOP|floatable))
								&& !(chan=BASS_MusicLoad(FALSE,file,0,0,BASS_SAMPLE_LOOP|BASS_MUSIC_RAMPS|floatable,1))) {
								// whatever it is, it ain't playable
								MESS(10,WM_SETTEXT,0,"click here to open a file...");
								Error("Can't play the file");
								break;
							}
							BASS_ChannelGetInfo(chan,&info);
							if (info.chans!=2) { // only stereo is allowed
								MESS(10,WM_SETTEXT,0,"click here to open a file...");
								BASS_MusicFree(chan);
								BASS_StreamFree(chan);
								Error("only stereo sources are supported");
								break;
							}
							MESS(10,WM_SETTEXT,0,file);
							// setup DSPs on new channel and play it
							SendMessage(win,WM_COMMAND,11,0);
							SendMessage(win,WM_COMMAND,12,0);
							SendMessage(win,WM_COMMAND,13,0);
							BASS_ChannelPlay(chan,FALSE);
						}
					}
					break;
				case 11: // toggle "rotate"
					if (MESS(11,BM_GETCHECK,0,0)) {
						rotpos=0.7853981f;
						rotdsp=BASS_ChannelSetDSP(chan,&Rotate,0,2);
					} else
						BASS_ChannelRemoveDSP(chan,rotdsp);
					break;
				case 12: // toggle "echo"
					if (MESS(12,BM_GETCHECK,0,0)) {
						memset(echbuf,0,sizeof(echbuf));
						echpos=0;
						echdsp=BASS_ChannelSetDSP(chan,&Echo,0,1);
					} else
						BASS_ChannelRemoveDSP(chan,echdsp);
					break;
				case 13: // toggle "flanger"
					if (MESS(13,BM_GETCHECK,0,0)) {
						memset(flabuf,0,sizeof(flabuf));
						flapos=0;
					    flas=FLABUFLEN/2;
					    flasinc=0.002f;
						fladsp=BASS_ChannelSetDSP(chan,&Flange,0,0);
					} else
						BASS_ChannelRemoveDSP(chan,fladsp);
					break;
			}
			break;

		case WM_INITDIALOG:
			win=h;
			memset(&ofn,0,sizeof(ofn));
			ofn.lStructSize=sizeof(ofn);
			ofn.hwndOwner=h;
			ofn.nMaxFile=MAX_PATH;
			ofn.Flags=OFN_HIDEREADONLY|OFN_EXPLORER;
			// enable floating-point DSP
			BASS_SetConfig(BASS_CONFIG_FLOATDSP,TRUE);
			// initialize - default device
			if (!BASS_Init(-1,44100,0,win,NULL)) {
				Error("Can't initialize device");
				DestroyWindow(win);
				break;
			}
			// check for floating-point capability
			floatable=BASS_StreamCreate(44100,2,BASS_SAMPLE_FLOAT,NULL,0);
			if (floatable) { // woohoo!
				BASS_StreamFree(floatable);
				floatable=BASS_SAMPLE_FLOAT;
			}
			return 1;

		case WM_DESTROY:
			BASS_Free();
			break;
	}
	return 0;
}
Exemplo n.º 14
0
BOOL Crecord_playerApp::InitInstance() {

    AfxEnableControlContainer();

#ifdef _AFXDLL
    Enable3dControls();         // Call this when using MFC in a shared DLL
#else
    Enable3dControlsStatic();   // Call this when linking to MFC statically
#endif

    g_main_dlg = new Crecord_playerDlg;
  m_pMainWnd = g_main_dlg;

  g_main_dlg->Create(IDD_record_player_DIALOG,NULL);
    
    // create a new world
  world = new cWorld();

  // set background color
  world->setBackgroundColor(0.0f,0.0f,0.0f);

  // Create a camera
  camera = new cCamera(world);
  world->addChild(camera);

  // Create a light source and attach it to camera
  light = new cLight(world);
  light->setEnabled(true);
  light->setPos(cVector3d(2,1,1));

  // define camera position
  flagCameraInMotion = false;

  camera->set(cVector3d(2,0,1), cVector3d(0,0,0), cVector3d(0,0,1));

  // create a display for graphic rendering
  viewport = new cViewport(g_main_dlg->m_gl_area_hwnd, camera, true);
  viewport->setStereoOn(false);

  // init var
  m_rotPos = 0;
  m_rotVel = 0;
  m_inertia = 0.04;
  m_clock.initialize();
  m_lastGoodPosition = 0.0;

  m_reduction = 5.4*10;
  m_cpt = 120*4;          
  m_desiredPos = 0.0;
  m_P = 0.4;
  m_I = 0.0014;
  m_integratorVal = 0.0;
  m_D = 0.02;

  m_lastAngle = 0.0;

  m_velocity = 0;
  m_velocityOld = 0;

  m_RFDInitialAngle = 0.0;
  m_inContact = false;

  LoadModel(TURNTABLE_MODEL);

  object->translate(0,0,-0.3);

  // set stiffness
  double stiffness = (double)35;
  object->setStiffness(stiffness, true);

  // Initialize sound device and create audio stream
  if (!BASS_Init(1,44100,0,0,NULL))
      _cprintf("Init error %d\n", BASS_ErrorGetCode());
    
  // Load a record onto the record player
  load_record(0);
  
  object->computeGlobalPositions(false);
  world->computeGlobalPositions(false);

  return TRUE;
}
Exemplo n.º 15
0
INT_PTR CALLBACK dialogproc(HWND h,UINT m,WPARAM w,LPARAM l)
{
	switch (m) {
		case WM_COMMAND:
			switch (LOWORD(w)) {
				case IDCANCEL:
					DestroyWindow(h);
					break;
				case 10:
					{
						char file[MAX_PATH]="";
						ofn.lpstrFilter="playable files\0*.mo3;*.xm;*.mod;*.s3m;*.it;*.mtm;*.umx;*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aif\0All files\0*.*\0\0";
						ofn.lpstrFile=file;
						if (GetOpenFileName(&ofn)) {
							// free both MOD and stream, it must be one of them! :)
							BASS_MusicFree(chan);
							BASS_StreamFree(chan);
#if 1 // with FX flag
							if (!(chan=BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_LOOP|BASS_SAMPLE_FX))
								&& !(chan=BASS_MusicLoad(FALSE,file,0,0,BASS_SAMPLE_LOOP|BASS_MUSIC_RAMP|BASS_SAMPLE_FX,1))) {
#else // without FX flag
							if (!(chan=BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_LOOP))
								&& !(chan=BASS_MusicLoad(FALSE,file,0,0,BASS_SAMPLE_LOOP|BASS_MUSIC_RAMP,1))) {
#endif
								// whatever it is, it ain't playable
								MESS(10,WM_SETTEXT,0,"click here to open a file...");
								Error("Can't play the file");
								break;
							}
							MESS(10,WM_SETTEXT,0,file);
							{ // setup the effects
								BASS_DX8_PARAMEQ p;
								fx[0]=BASS_ChannelSetFX(chan,BASS_FX_DX8_PARAMEQ,0);
								fx[1]=BASS_ChannelSetFX(chan,BASS_FX_DX8_PARAMEQ,0);
								fx[2]=BASS_ChannelSetFX(chan,BASS_FX_DX8_PARAMEQ,0);
								fx[3]=BASS_ChannelSetFX(chan,BASS_FX_DX8_REVERB,0);
								p.fGain=0;
								p.fBandwidth=18;
								p.fCenter=125;
								BASS_FXSetParameters(fx[0],&p);
								p.fCenter=1000;
								BASS_FXSetParameters(fx[1],&p);
								p.fCenter=8000;
								BASS_FXSetParameters(fx[2],&p);
								UpdateFX(0);
								UpdateFX(1);
								UpdateFX(2);
								UpdateFX(3);
							}
							BASS_ChannelPlay(chan,FALSE);
						}
					}
					break;
			}
			break;

		case WM_VSCROLL:
			if (l) {
				UpdateFX(GetDlgCtrlID((HWND)l)-20);
			}
			break;

		case WM_INITDIALOG:
			win=h;
			memset(&ofn,0,sizeof(ofn));
			ofn.lStructSize=sizeof(ofn);
			ofn.hwndOwner=h;
			ofn.nMaxFile=MAX_PATH;
			ofn.Flags=OFN_HIDEREADONLY|OFN_EXPLORER;
			// setup output - default device
			if (!BASS_Init(-1,44100,0,win,NULL)) {
				Error("Can't initialize device");
				DestroyWindow(win);
				break;
			}
			{
				// check that DX8 features are available
				BASS_INFO bi={sizeof(bi)};
				BASS_GetInfo(&bi);
				if (bi.dsver<8) {
					BASS_Free();
					Error("DirectX 8 is not installed");
					DestroyWindow(win);
				}
			}
			// initialize eq/reverb sliders
			MESS(20,TBM_SETRANGE,FALSE,MAKELONG(0,20));
			MESS(20,TBM_SETPOS,TRUE,10);
			MESS(21,TBM_SETRANGE,FALSE,MAKELONG(0,20));
			MESS(21,TBM_SETPOS,TRUE,10);
			MESS(22,TBM_SETRANGE,FALSE,MAKELONG(0,20));
			MESS(22,TBM_SETPOS,TRUE,10);
			MESS(23,TBM_SETRANGE,FALSE,MAKELONG(0,20));
			MESS(23,TBM_SETPOS,TRUE,20);
			return 1;

		case WM_DESTROY:
			BASS_Free();
			break;
	}
	return 0;
}

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
	// check the correct BASS was loaded
	if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
		MessageBox(0,"An incorrect version of BASS.DLL was loaded",0,MB_ICONERROR);
		return 0;
	}

	{ // enable trackbar support
		INITCOMMONCONTROLSEX cc={sizeof(cc),ICC_BAR_CLASSES};
		InitCommonControlsEx(&cc);
	}

	DialogBox(hInstance,(char*)1000,0,&dialogproc);

	return 0;
}
Exemplo n.º 16
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    setupUi(this);

    Finished_Init = false;
    AllowInit = false;
    PreBuf_timer = new QTimer;
    Update_timer= new QTimer;
    Ping_timer= new QTimer;
    Spectrum_timer = new QTimer;
    BufferStatusUpdate_timer= new QTimer;
    singleClickTimer=new QTimer;
    m_msgbox = NULL;
    isPlaying=false;
    syncLost=false;
    currentRadio=NULL;
    currentTrack="";
    dConnectionProgress=NULL;
    dDelConfirm=NULL;
    dShowHistory=NULL;
    netManager=NULL;
    currentRadioURL=-1;
    streamsErrLoop=false;
    pSpec=NULL;
    mMoving=false;
    savedVolume=0.5;
    isMuted=false;
    treeSelectionChanged=false;
    isRecording=false;
    newVersionAnimation=NULL;
    recButtonAnimation=NULL;
    isRootOperation=false;
#ifdef VISUALS
    isVisResized=false;
    isVisRendering=false;
    visWin=new VisWinCL(this);
    bigVis=false;
    bigVisRunning=false;
#endif

    initBitRate();
    initOggQualityMap();

    qDebug()<<"Cheking BASS version";
    if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
        qDebug()<<"An incorrect version of BASS.DLL was loaded";
        QMessageBox::warning(this,QString("warning"),QString("An incorrect version of BASS.DLL was loaded"));
    }

    BASS_SetConfigPtr(BASS_CONFIG_NET_AGENT, (void*) _T(PLAYER_HTTPAGENT));


#ifdef Q_OS_WIN
    if (BASS_PluginLoad("bass_aac.dll",0)==0) {
        qDebug()<<"Unable to load bass_aac.ddl  BassError="<<BASS_ErrorGetCode();
    }
#elif Q_OS_LINUX
    if (BASS_PluginLoad("bass_aac.so",0)==0) {
        qDebug()<<"Unable to load bass_aac.ddl  BassError="<<BASS_ErrorGetCode();
    }
#endif


    QSettings tSettings(AppPath+CONFIG_FILENAME,QSettings::IniFormat);
    tSettings.setIniCodec("ISO 8859-1");
    Proxy=tSettings.value("proxy","").toString();
    ProxyPort=tSettings.value("proxyport","").toString();
    ProxyUser=tSettings.value("proxyuser","").toString();
    ProxyPass=tSettings.value("proxypass","").toString();
    visualPlugin=tSettings.value("visual",VIS_WIN_PLUG).toString();
    qDebug()<<"visualPlugin="<<visualPlugin;
    recPath=tSettings.value("recpath","").toString();
    recPath=recPath.replace("\\","\\\\");
#ifdef Q_OS_WIN
    if (recPath!="" && recPath.at(recPath.length()-1)!='\\')
        recPath=recPath+"\\";
#else
    if (recPath!="" && recPath.at(recPath.length()-1)!='/')
        recPath=recPath+"/";
#endif

    if (recPath=="") {
#ifdef Q_OS_WIN
        recPath=QDir::toNativeSeparators(QStandardPaths::standardLocations(QStandardPaths::MusicLocation).at(0)+"/");
#endif

#ifdef Q_OS_MAC
        recPath=AppPath.fromLatin1(argv[0]);
        recPath+="/";
#endif
    }

    qDebug()<<"Recording path ="<<recPath;

    if (Proxy!="") {
        qDebug()<<"Proxy="<<Proxy;
        QString tBassProxyStr=ProxyUser;
        if (ProxyPass!="")
            tBassProxyStr+=":"+ProxyPass;
        if (ProxyUser!="")
            tBassProxyStr+="@";
        tBassProxyStr+=Proxy+":"+ProxyPort;
        qDebug()<<"BASSProxy="<<tBassProxyStr;
        qDebug()<<"BASSProxy="<<tBassProxyStr.toLatin1().data();
        //strcpy(proxyStrChar,Proxy.toLatin1().data());
        BASS_SetConfigPtr(BASS_CONFIG_NET_PROXY,tBassProxyStr.toLatin1().data());
        //BASS_SetConfigPtr(BASS_CONFIG_NET_PROXY,&proxyStrChar);
    }
    else {
        BASS_SetConfigPtr(BASS_CONFIG_NET_PROXY, NULL);
    }

    //if( !InitVersion() ) ErrorMsgBox(_T("\n Error Setting up Version strings \n"));
    if( !InitBassErrorMap() ) ErrorMsgBox(_T("\n Error setting up Error Msgs \n"));
    if (!BASS_Init(-1,44100,0,NULL,NULL)) {
        ErrorMsgBox(_T("\nUnable to initialize BASS library\n"), 86, false);
        exit(86);
    }

    savedVolume=BASS_GetVolume();
    slVolume->setValue(savedVolume*slVolume->maximum());


#ifdef Q_OS_WIN
    // allocate ACM format buffer, using suggested buffer size
    acmformlen = BASS_Encode_GetACMFormat(0,NULL,0,NULL,0);
    acmform = (WAVEFORMATEX*)malloc(acmformlen);
    memset(acmform,0,acmformlen);
    acmduncil = (WAVEFORMATEX*)malloc(acmformlen);
    memset(acmduncil, 0, acmformlen);
    //
#endif

    connect(radioTree,SIGNAL(AddStationSig(QModelIndex,RadioCL*)),this,SLOT(AddStation(QModelIndex,RadioCL*)));
    connect(radioTree, SIGNAL(treeSelectionChanged(const QModelIndex &, const QModelIndex &)), this,
            SLOT(radioTreeSelectionChanges(const QModelIndex &, const QModelIndex &)));

    qDebug()<<"Connecting timers signals ";
    connect(PreBuf_timer, SIGNAL(timeout()), this, SLOT(prebufTimeout()));
    connect(Update_timer, SIGNAL(timeout()), this, SLOT(updateTimeout()));
    connect(Ping_timer, SIGNAL(timeout()),this, SLOT(pingRadio()));
    connect(Spectrum_timer, SIGNAL(timeout()), this, SLOT(specTimeout()));
    connect(BufferStatusUpdate_timer, SIGNAL(timeout()),this, SLOT(updateBufferStatus()));
    connect(singleClickTimer, SIGNAL(timeout()),this, SLOT(singleClickTimeout()));

    qDebug()<<"Connecting mgh signals";
    connect( &mgh, SIGNAL(SendUpdTrackInfo(QString)), this, SLOT(on_UpdTrackInfo(QString)) );
    connect( &mgh, SIGNAL(SendUpdRadioInfo(QString,QString,QString,QString)), this, SLOT(on_UpdRadioInfo(QString,QString,QString,QString)));
    connect( &mgh, SIGNAL(SendSyncLost()), this, SLOT(on_SyncLost()) );
    connect( &mgh, SIGNAL(SendPlaybackStarts()), this, SLOT(on_PlaybackStarts()) );
    connect( &mgh, SIGNAL(SendClickRecord()), this, SLOT(on_ClickRecord()) );

    qDebug()<<"Creating actions";
    createActions();
    qDebug()<<"Creating tray icon";
    createTrayIcon();

    qDebug()<<"Setting tray icon";
    setIcon(PLAYER_STATUS_INACTIVE);
    trayIcon->setVisible(true);
    trayIcon->show();
    setWindowTitle(QString(PLAYER_NAME)+" v"+RADIOLA_VERSION);

    qDebug()<<"Initializing spectrum image";
    specbuf = NULL;
    specmode = DEFAULT_SPEC_MODE; // spectrum mode
    specpos = 0; // spectrum mode (and marker pos for 2nd mode)
    pSpec = new QImage(SPECWIDTH, SPECHEIGHT, QImage::Format_Indexed8);
    // setup palette
    pSpec->setColor(0, qRgb(0,0,0));
    for(int a=1; a < 128; a++) {
        pSpec->setColor(a, qRgb(2*a, 256-2*a, 0));
    }
    for(int a=0; a < 32; a++) {
        pSpec->setColor(128+a, qRgb(0, 0, 8*a));
        pSpec->setColor(128+32+a, qRgb(8*a, 0, 255));
        pSpec->setColor(128+64+a, qRgb(255, 8*a, 8*(31-a)));
        //pSpec->setColor(128+64+a, qRgb(8*(31-a), 8*a, 8*a));
        pSpec->setColor(128+96+a, qRgb(255, 255, 8*a));
        //pSpec->setColor(128+96+a, qRgb(255, 255, 8*a));
    }
    pSpec->setColor(254, qRgb(112, 112, 255));
    pSpec->setColor(253, qRgb(255, 128, 128));
    pSpec->setColor(255, qRgb(212,208,200));    // background color
    // create the bitmap
    specbuf = (BYTE*)pSpec->bits();
    pSpec->fill(255);
    specButton->setSpec(pSpec);

    readSettings();

    qDebug()<<"Connecting tray signals ";
    connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
            this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));

    setupRadioTree();

    historyFile.setFileName(GetHistoryDir());

    if (!historyFile.open(QIODevice::ReadWrite | QIODevice::Append)) {
        qDebug()<<"Unable to open history file for write"<<historyFile.fileName();
        return;
    }

    StopPlayback();

    QIcon icon = QIcon(MAINWIN_ICON);
    setWindowIcon(icon);

    new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_S), this, SLOT(showSettings()));
    new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_E), this, SLOT(showRecPath()));
    new QShortcut(QKeySequence(Qt::Key_F1), this, SLOT(showHelp()));
    new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_H), this, SLOT(showHistory()));
#ifdef Q_OS_WIN
    new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_V), this, SLOT(showVisualization()));
#endif
    new QShortcut(QKeySequence(Qt::Key_Space), this, SLOT(on_pbPlay_clicked()));
    new QShortcut(QKeySequence(Qt::Key_MediaPlay), this, SLOT(on_pbPlay_clicked()));
    new QShortcut(QKeySequence(Qt::Key_Delete), this, SLOT(removeRow()));
    new QShortcut(QKeySequence(Qt::Key_Insert), this, SLOT(insertStation()));
    new QShortcut(QKeySequence(Qt::Key_Plus), this, SLOT(insertSubfolder()));

    QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect();
    effect->setBlurRadius(1); //Adjust accordingly
    effect->setOffset(3,3); //Adjust accordingly
    setShadow(bnShowHistory);
    setShadow(pbPlay);
    setShadow(pbRecord);
    setShadow(pbQuit);

    recButtonAnimation=new QMovie(":/images/rec_animation.gif");
    connect(recButtonAnimation,SIGNAL(frameChanged(int)),this,SLOT(setRecButtonIcon(int)));

    singleClickTimer->setInterval(QApplication::doubleClickInterval());
    singleClickTimer->setSingleShot(true);

    CheckNewVersion();

    netManager = new QNetworkAccessManager(this);
    if (Proxy!="") {
        netManager->setProxy(QNetworkProxy(QNetworkProxy::HttpProxy,Proxy,ProxyPort.toInt(),ProxyUser,ProxyPass));
    }
    connect(netManager, SIGNAL(finished(QNetworkReply*)),this, SLOT(pingReply(QNetworkReply*)));
}
Exemplo n.º 17
0
int main(){
	BOOL done = FALSE;
	MSG msg;
	IDirect3DDevice9 *device = NULL;
	IDirect3DSurface9 *main_rendertarget = NULL;
	D3DFORMAT format;
	
	float old_time = 0;

	/* render-to-texture-stuff */
	IDirect3DTexture9 *rtt_texture;
	IDirect3DSurface9 *rtt_surface;
	IDirect3DTexture9 *rtt_32_texture;
	IDirect3DSurface9 *rtt_32_surface;

	/* textures used from mainloop */
	int white, black;
	int odd_is_back_again[4];
	int at_the_gathering_2003[4];
	int o_d_d_in_your_face[4];
	int world_domination[4];
	int back_once_again[3];
	int were_back;
	int cred[4];
	int mad_props[4];
	int not_eph[4];
	int piss_the_fuck_off[11];
	int hardcore;

	int refmap, refmap2;
	int eatyrcode;
	int code_0, code_1;
	int overlaytest;
	int circle_particle;

	/* special-textures */
	int rtt_texture_id;
	int rtt_32_texture_id;
	int video_texture_id;
	int dilldall,dilldall2;
	int metaball_text;

	/* videos */
	video *vid;

	/* 3d-scenes */
	scene *fysikkfjall;
	scene *startblob;
	scene *inni_abstrakt;
	scene *korridor;
	scene *skjerm_rom;
	scene *bare_paa_lissom;

	format = D3DFMT_X8R8G8B8;
	device = d3dwin_open(TITLE, WIDTH, HEIGHT, format, FULLSCREEN);
	if(!device){
		format = D3DFMT_A8R8G8B8;
		device = d3dwin_open(TITLE, WIDTH, HEIGHT, format, FULLSCREEN);
		if(!device){
			format = D3DFMT_X1R5G5B5;
			device = d3dwin_open(TITLE, WIDTH, HEIGHT, format, FULLSCREEN);
			if(!device){
				format = D3DFMT_R5G6B5;
				device = d3dwin_open(TITLE, WIDTH, HEIGHT, format, FULLSCREEN);
				if(!device) error("failed to initialize Direct3D9");
			}
		}
	}

#ifdef BIGSCREEN
	set_gamma(device,1.05f);
#endif

	if (!BASS_Init(1, 44100, BASS_DEVICE_LATENCY, win, NULL)) error("failed to initialize BASS");
	fp = file_open("worlddomination.ogg");
	if (!fp) error("music-file not found");
	music_file = BASS_StreamCreateFile(1, fp->data, 0, fp->size, 0);

	/*** music ***/
//	if(!pest_open(win)) error("failed to initialize DirectSond");
//	if(!pest_load("worlddomination.ogg",0)) error("failed to load music-file");


	/*** subsystems ***/
	init_tunnel();
	video_init();
	if(!init_particles(device)) error("failed to initialize");
	if(!init_overlays(device)) error("f**k a duck");
	if(!init_marching_cubes(device)) error("screw a kangaroo");

	make_random_particles(particles, PARTICLES, vector_make(0,-180,0), 500);
	make_random_particles(particles2, PARTICLES2, vector_make(0,-180,0), 500);
	make_random_particles(particles3, PARTICLES3, vector_make(0,0,0), 800);

	/*** rendertextures ***/
	if (IDirect3DDevice9_CreateTexture(device, 512, 256, 0,D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &rtt_texture, NULL)!=D3D_OK) error("failed to create rendertarget-texture");
	if (IDirect3DTexture9_GetSurfaceLevel(rtt_texture,0,&rtt_surface)!=D3D_OK) error("could not get kvasi-backbuffer-surface");
	if ((rtt_texture_id=texture_insert(device, "rendertexture.jpg", rtt_texture))==-1) error("fakk off!");

	if(IDirect3DDevice9_CreateTexture(device,16,16,0,D3DUSAGE_RENDERTARGET|D3DUSAGE_AUTOGENMIPMAP,D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT, &rtt_32_texture, NULL)!=D3D_OK) error("failed to create rendertarget-texture");
	if(IDirect3DTexture9_GetSurfaceLevel(rtt_32_texture,0,&rtt_32_surface)!=D3D_OK) error("could not get kvasi-backbuffer-surface");
	if((rtt_32_texture_id=texture_insert(device, "rendertexture2.jpg", rtt_32_texture))==-1) error("fakk off!");


	/*** textures ***/
	/* solid colors for fades etc */
	if((white=texture_load(device,"white.png",FALSE))==-1) error("shjit!");
	if((black=texture_load(device,"black.png",FALSE))==-1) error("shjit!");

	/* textoverlays */
	if((odd_is_back_again[0]=texture_load(device,"odd_is_back_again_0.png",FALSE))==-1) error("failed to load image");
	if((odd_is_back_again[1]=texture_load(device,"odd_is_back_again_1.png",FALSE))==-1) error("failed to load image");
	if((odd_is_back_again[2]=texture_load(device,"odd_is_back_again_2.png",FALSE))==-1) error("failed to load image");
	if((odd_is_back_again[3]=texture_load(device,"odd_is_back_again_3.png",FALSE))==-1) error("failed to load image");
	if((at_the_gathering_2003[0]=texture_load(device,"at_the_gathering_2003_0.png",FALSE))==-1) error("failed to load image");
	if((at_the_gathering_2003[1]=texture_load(device,"at_the_gathering_2003_1.png",FALSE))==-1) error("failed to load image");
	if((at_the_gathering_2003[2]=texture_load(device,"at_the_gathering_2003_2.png",FALSE))==-1) error("failed to load image");
	if((at_the_gathering_2003[3]=texture_load(device,"at_the_gathering_2003_3.png",FALSE))==-1) error("failed to load image");
	if((back_once_again[0]=texture_load(device,"back_once_again_0.png",TRUE))==-1) error("failed to load image");
	if((back_once_again[1]=texture_load(device,"back_once_again_1.png",TRUE))==-1) error("failed to load image");
	if((back_once_again[2]=texture_load(device,"back_once_again_2.png",TRUE))==-1) error("failed to load image");
	if((o_d_d_in_your_face[0]=texture_load(device,"o_d_d_in_your_face_0.png",TRUE))==-1) error("failed to load image");
	if((o_d_d_in_your_face[1]=texture_load(device,"o_d_d_in_your_face_1.png",TRUE))==-1) error("failed to load image");
	if((o_d_d_in_your_face[2]=texture_load(device,"o_d_d_in_your_face_2.png",TRUE))==-1) error("failed to load image");
	if((o_d_d_in_your_face[3]=texture_load(device,"o_d_d_in_your_face_3.png",TRUE))==-1) error("failed to load image");
	if((world_domination[0]=texture_load(device,"world_domination_0.png",TRUE))==-1) error("failed to load image");
	if((world_domination[1]=texture_load(device,"world_domination_1.png",TRUE))==-1) error("failed to load image");
	if((world_domination[2]=texture_load(device,"world_domination_2.png",TRUE))==-1) error("failed to load image");
	if((world_domination[3]=texture_load(device,"world_domination_3.png",TRUE))==-1) error("failed to load image");
	if((were_back=texture_load(device,"were_back.png",TRUE))==-1) error("failed to load image");

	if((cred[0]=texture_load(device,"cred_0.png",TRUE))==-1) error("failed to load image");
	if((cred[1]=texture_load(device,"cred_1.png",TRUE))==-1) error("failed to load image");
	if((cred[2]=texture_load(device,"cred_2.png",TRUE))==-1) error("failed to load image");
	if((cred[3]=texture_load(device,"cred_3.png",TRUE))==-1) error("failed to load image");
	if((mad_props[0]=texture_load(device,"mad_props_0.png",TRUE))==-1) error("failed to load image");
	if((mad_props[1]=texture_load(device,"mad_props_1.png",TRUE))==-1) error("failed to load image");
	if((mad_props[2]=texture_load(device,"mad_props_2.png",TRUE))==-1) error("failed to load image");
	if((mad_props[3]=texture_load(device,"mad_props_3.png",TRUE))==-1) error("failed to load image");
	if((not_eph[0]=texture_load(device,"not_eph_0.png",TRUE))==-1) error("failed to load image");
	if((not_eph[1]=texture_load(device,"not_eph_1.png",TRUE))==-1) error("failed to load image");
	if((not_eph[2]=texture_load(device,"not_eph_2.png",TRUE))==-1) error("failed to load image");
	if((not_eph[3]=texture_load(device,"not_eph_3.png",TRUE))==-1) error("failed to load image");

	if((piss_the_fuck_off[0]=texture_load(device,"piss_the_fuck_off_0.png",TRUE))==-1) error("failed to load image");
	if((piss_the_fuck_off[1]=texture_load(device,"piss_the_fuck_off_1.png",TRUE))==-1) error("failed to load image");
	if((piss_the_fuck_off[2]=texture_load(device,"piss_the_fuck_off_2.png",TRUE))==-1) error("failed to load image");
	if((piss_the_fuck_off[3]=texture_load(device,"piss_the_fuck_off_3.png",TRUE))==-1) error("failed to load image");
	if((piss_the_fuck_off[4]=texture_load(device,"piss_the_fuck_off_4.png",TRUE))==-1) error("failed to load image");
	if((piss_the_fuck_off[5]=texture_load(device,"piss_the_fuck_off_5.png",TRUE))==-1) error("failed to load image");
	if((piss_the_fuck_off[6]=texture_load(device,"piss_the_fuck_off_6.png",TRUE))==-1) error("failed to load image");
	if((piss_the_fuck_off[7]=texture_load(device,"piss_the_fuck_off_7.png",TRUE))==-1) error("failed to load image");
	if((piss_the_fuck_off[8]=texture_load(device,"piss_the_fuck_off_8.png",TRUE))==-1) error("failed to load image");
	if((piss_the_fuck_off[9]=texture_load(device,"piss_the_fuck_off_9.png",TRUE))==-1) error("failed to load image");
	if((piss_the_fuck_off[10]=texture_load(device,"piss_the_fuck_off_10.png",TRUE))==-1) error("failed to load image");
	if((hardcore=texture_load(device,"hardcore.png",TRUE))==-1) error("failed to load image");

	/* other textures */
	if((circle_particle=texture_load(device,"circle_particle.jpg",FALSE))==-1) error("shjit!");
	if((refmap=texture_load(device,"fysikkfjall/refmap.jpg",FALSE))==-1) error("shjit!");
	if((refmap2=texture_load(device,"refmap2.jpg",FALSE))==-1) error("shjit!");
	if((eatyrcode=texture_load(device,"eatyrcode.jpg",FULLSCREEN_HACK))==-1) error("shjit!");
	if((code_0=texture_load(device,"code-0.jpg",FALSE))==-1) error("shjit!");
	if((code_1=texture_load(device,"code-1.jpg",FALSE))==-1) error("shjit!");
	if((overlaytest=texture_load(device,"overlaytest.jpg",FALSE))==-1) error("shjit!");

	if((dilldall=texture_load(device,"dilldall.png",FALSE))==-1) error("shjit!");
	if((dilldall2=texture_load(device,"dilldall2.png",FALSE))==-1) error("shjit!");

	if((metaball_text=texture_load(device,"metaballs.png",TRUE))==-1) error("shjit!");

	/*** video ***/
	if(!(vid=video_load(device,"test.kpg"))) error("fæck!");
	video_texture_id = texture_insert(device, "skjerm_rom/skjerm_tom.tga", vid->texture);


	/*** misc stuff ***/
	/* main rendertarget */
	IDirect3DDevice9_GetRenderTarget(device,0,&main_rendertarget);

	/* default state */
	IDirect3DDevice9_CreateStateBlock(device, D3DSBT_ALL, &default_state);
	init_defaultstate(device);
	IDirect3DStateBlock9_Capture(default_state);


	/*** 3d scenes ***/
	if(!(fysikkfjall=load_scene(device,"fysikkfjall/fysikkfjall.krs"))) error("failed to load 3d scene");
	if(!(startblob=load_scene(device,"startblob/startblob.krs"))) error("failed to load 3d scene");
	if(!(inni_abstrakt=load_scene(device,"inni_abstrakt/inni_abstrakt.krs"))) error("failed to load 3d scene");
	if(!(korridor=load_scene(device,"korridor/korridor.krs"))) error("failed to load 3d scene");
	if(!(skjerm_rom=load_scene(device,"skjerm_rom/skjerm_rom.krs"))) error("failed to load 3d scene");
	if(!(bare_paa_lissom=load_scene(device,"bare_paa_lissom/bare_paa_lissom.krs"))) error("failed to load 3d scene");

//	pest_play();
	BASS_Start();
	BASS_StreamPlay(music_file, 1, 0);
	do{
		grid g;
		int i;
		matrix m, temp, temp_matrix;
		matrix marching_cubes_matrix;

		long long bytes_played = BASS_ChannelGetPosition(music_file);
		float time =  bytes_played * (1.0 / (44100 * 2 * 2));
//		float time = pest_get_pos()+0.05f;
		float delta_time = time-old_time;

		int beat = (int)(time*((float)BPM/60.f));

		if(time_index<(sizeof(timetable)/4)){
			while(timetable[time_index]<time) time_index++;
		}

#ifdef _DEBUG
		printf("time: %2.2f, delta_time: %2.2f, time_index: %i, beat: %i                    \r",time,delta_time,time_index,beat);
#endif

		IDirect3DDevice9_SetRenderTarget(device,0,main_rendertarget);
		IDirect3DStateBlock9_Apply(default_state);
		IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0, 1.0f, 0);
//		IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 1.0f, 0);
		IDirect3DDevice9_BeginScene(device);
#if 1
		if(time_index<40){
			if(time_index>0&&time_index<5){
				draw_overlay(device,odd_is_back_again[time_index-1],0,0,1,FALSE);
			}else if(time_index>4&&time_index<19){
				float itime = time*10;
				grid_flat(g,0,0);
				for(i=0;i<7;i++){
					int scale = (time_index&1);
					grid_wave(g,(float)sin(itime-i+sin(i-itime))*0.3f*scale,(float)cos(itime*0.69f+i*0.733f)*0.3f*scale,7,(float)sin(itime+i*0.1f)*0.5f*scale);
				}
				draw_grid(device, g, odd_is_back_again[3], FALSE);
			}else if(time_index>=19){
				float itime = (time-timetable[18])*0.5f;
				grid_flat(g,0,0);
				for(i=0;i<7;i++){
					grid_wave(g,(float)sin(time-i+sin(i-time))*0.3f,(float)cos(time*0.69f+i*0.733f)*0.3f,7, itime*itime);
				}
				draw_grid(device, g, odd_is_back_again[3], FALSE);
			}
			if(time_index>20&&time_index<25){
				draw_overlay(device,at_the_gathering_2003[(time_index-21)%4],0,0,1,TRUE);
			}else if(time_index>=25&&time_index<38){
				float itime = time*10;
				grid_flat(g,0,0);
				for(i=0;i<10;i++){
					int scale = (time_index&1);
					grid_wave(g,(float)sin(itime-i+sin(i-itime))*0.3f*scale,(float)cos(itime*0.69f+i*0.733f)*0.3f*scale,7,(float)sin(itime+i*0.1f)*0.5f*scale);
				}
				draw_grid(device,g,at_the_gathering_2003[3],TRUE);
			}else if(time_index>=38){
				float itime = (time-timetable[37])*0.5f;
				grid_flat(g,0,0);
				for(i=0;i<10;i++){
					grid_wave(g,(float)sin(time-i+sin(i-time))*0.3f,(float)cos(time*0.69f+i*0.733f)*0.3f,7, itime*itime);
				}
				draw_grid(device,g,at_the_gathering_2003[3],TRUE);
			}
		}else if(time_index<52){
			animate_scene(inni_abstrakt,(time-timetable[39]));
			draw_scene(device,inni_abstrakt,0,TRUE);

			flash(device,white,time,timetable[39],1);

			if(time_index<43){
				draw_overlay(device, back_once_again[(time_index-40)%3],0,0,1,FALSE);
			}else if(time_index<47){
				draw_overlay(device, o_d_d_in_your_face[(time_index-43)%4],0,0,1,FALSE);
			}else if(time_index<51){
				draw_overlay(device, world_domination[(time_index-47)%4],0,0,1,FALSE);
			}else{
				draw_overlay(device, were_back,0,0,(time-timetable[51]),FALSE);
			}

			draw_overlay(device,dilldall,sin(sin(time)*0.07f+(((beat+1)/2)*0.8f)),sin(time*0.03337f+(((beat+1)/2)*0.14f)),0.5f,TRUE);
			draw_overlay(device,dilldall2,sin(sin(time*0.1f)*0.07f+time*0.1f+(((beat+1)/2)*0.8f)),sin(time*0.01337f+(((beat+1)/2)*0.14f)),0.5f,TRUE);

		}else if(time_index<69){

			animate_scene(startblob,(time-timetable[39]-0.27f+((beat+1)&2))*0.74948f);

			startblob->cameras[0].fog = TRUE;
			startblob->cameras[0].fog_start = 100.f;
			startblob->cameras[0].fog_end = 700.f;

			if(time_index>=53 && time_index<66 && time_index&1 ){
				float f = fade(timetable[time_index-1],1.7f,time,0.5f,0);
				f *= f;
				f *= 2;

				if(f>0.f)
				IDirect3DDevice9_SetRenderTarget(device,0,rtt_surface);

				draw_scene(device,startblob,0,TRUE);
				draw_particles(device, particles3, PARTICLES3, code_0);

				if(f>0.f){
					IDirect3DDevice9_SetRenderTarget(device,0,main_rendertarget);
					draw_radialblur(device,0,0,f,0,rtt_texture_id, FALSE);
				}
				if(time_index<61) draw_overlay(device,cred[((time_index/2)-2)%4],0,0,f*3,FALSE);
			}else{
				draw_scene(device,startblob,0,TRUE);
				draw_particles(device, particles3, PARTICLES3, circle_particle);			
			}
			if(time_index>=54&& !(time_index&1)){

				float f = fade(timetable[time_index-1],1.8f,time,1.f,0)*0.8f;
				IDirect3DDevice9_SetRenderTarget(device,0,rtt_32_surface);
				draw_scene(device,startblob,0,TRUE);
				draw_particles(device, particles3, PARTICLES3, code_0);

				IDirect3DDevice9_SetRenderTarget(device,0,main_rendertarget);
				IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
				draw_overlay(device,rtt_32_texture_id,0,0,f,TRUE);
				draw_overlay(device,rtt_32_texture_id,0,0,f,TRUE);
				IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
			}

			flash(device,were_back,time,timetable[51],2);
			flash(device,white,time,timetable[51],1);
		}else if(time_index<79){

			for(i=0;i<BALLS;i++){
				balls[i].pos.x = (float)sin(time+i-sin((float)i*0.1212111f))*0.35f;
				balls[i].pos.y = (float)cos(time-(float)i*0.29342111f)*0.35f;
				balls[i].pos.z = (float)sin(time*0.31121f+sin(i-time))*0.35f;
				balls[i].r = 0.15f + (float)sin(time+i)*0.01f;
				balls[i].pos = vector_normalize(balls[i].pos);
				balls[i].pos = vector_scale(balls[i].pos, (float)(cos(i*0.11131f-time*0.55311f)+sin(time+(float)sin(time-i+time*0.3f)))*0.2f );
			}

			animate_scene(korridor,(time-timetable[68])*0.65f );
			draw_scene(device,korridor,(beat/4)&1,TRUE);

			memcpy(temp,korridor->objects[korridor->object_count-1]->mat,sizeof(matrix));
			matrix_scale(marching_cubes_matrix,vector_make(120,120,120));
			matrix_multiply(marching_cubes_matrix,temp,marching_cubes_matrix);
	
			matrix_rotate(temp,vector_make(time,-time,time*0.5f+sin(time)));
			matrix_multiply(marching_cubes_matrix,marching_cubes_matrix,temp);

			IDirect3DDevice9_SetTransform( device, D3DTS_WORLD, (D3DMATRIX*)&marching_cubes_matrix );

			fill_metafield_blur(balls, BALLS,0.98f);
			march_my_cubes_opt(balls, BALLS, 0.9f);

			IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);

			set_texture(device,0,refmap2);
			IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR );
			IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_ADD);
			IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
			IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_CURRENT);

			draw_marched_cubes(device);

			flash(device,white,time,timetable[68],1);

			if(time_index>69&&time_index<74){
				draw_overlay(device,mad_props[(time_index+2)%4],0,0,1,FALSE);
			}else if(time_index>73&&time_index<77){
				draw_overlay(device,not_eph[(time_index+2)%4],0,0,1,FALSE);
			}else if(time_index==77){
				float f = fade(timetable[76],2.5f,time,1,0);
				draw_overlay(device,not_eph[3],0,0,f,FALSE);
			}
		}
		if(time_index>77&&time_index<92){
			float f = fade(timetable[77],timetable[78]-timetable[77],time,0,1);
			draw_overlay(device,eatyrcode,0,0,f,FALSE);

			if(time>109.5f){
				IDirect3DStateBlock9_Apply(default_state);
				animate_particles(particles, PARTICLES, delta_time*30);
				animate_particles(particles2, PARTICLES2, delta_time*28);

				draw_particles(device, particles, PARTICLES, code_0);
				draw_particles(device, particles2, PARTICLES2, code_1);
			}
			if(time_index>79&&time_index<90){
				draw_overlay(device,piss_the_fuck_off[(time_index-80)%11],0,0,1,FALSE);
			}else if(time_index==90){
				float f = fade(timetable[89],2,time,1,0);
				draw_overlay(device,piss_the_fuck_off[10],0,0,f,FALSE);
			}
			if(time_index==91){
				float f = fade(timetable[90],2,time,1,0);
				draw_overlay(device,hardcore,0,0,f,FALSE);
			}
		}else if(time_index>91 && time_index<97){
			animate_scene(skjerm_rom,time);
			video_update(vid, time);
			draw_scene(device,skjerm_rom,((beat/4)&1),TRUE);

			draw_overlay(device,dilldall,sin(sin(time)*0.07f+(((beat+1)/2)*0.8f)),sin(time*0.03337f+(((beat+1)/2)*0.14f)),0.5f,TRUE);
			draw_overlay(device,dilldall2,sin(sin(time*0.1f)*0.07f+time*0.1f+(((beat+1)/2)*0.8f)),sin(time*0.01337f+(((beat+1)/2)*0.14f)),0.5f,TRUE);
			if(time_index>92)
				draw_overlay(device, world_domination[(time_index-93)%4],0,0,1,FALSE);

		}else if(time_index>96&&time_index<104){
			grid_zero(g);

			matrix_translate(m, vector_make(cos(time)*1.5f, sin(time)*1.5f,time*10));
			matrix_rotate(temp_matrix, vector_make(sin(time*0.8111f)*0.2f,sin(time*1.2f)*0.2f,time));
			matrix_multiply(m,m,temp_matrix);

			render_tunnel(g,m);

			matrix_rotate(temp_matrix, vector_make(0,M_PI,0));
			matrix_multiply(m,m,temp_matrix);
			render_tunnel(g,m);
			matrix_rotate(temp_matrix, vector_make(M_PI,0,0));
			matrix_multiply(m,m,temp_matrix);
			render_tunnel(g,m);

			grid_add_noice(g,sin(time)*0.1f);

			draw_grid(device, g, circle_particle, FALSE);

			if(time_index>97&&time_index<102){
				float f = 1;
				if(time_index==101) f = fade(timetable[100],3,time,1,0);
				draw_overlay(device, o_d_d_in_your_face[(time_index-42)%4],0,0,f,FALSE);
			}
		}
		if(time_index>101 && time_index<104){
			float f = fade(timetable[101],8,time,0,1);
			float f2 = fade(timetable[101],4,time,0,1);

			draw_overlay(device,black,0,0,f2,FALSE);

			IDirect3DDevice9_SetRenderTarget(device,0,rtt_surface);
			IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0, 1.0f, 0);

			IDirect3DStateBlock9_Apply(default_state);

			animate_scene(bare_paa_lissom,time-timetable[101]);
			draw_scene(device,bare_paa_lissom,0,TRUE);

			time *=0.5f;

			for(i=0;i<BALLS2;i++){
				balls2[i].pos.x = (float)sin(time+i-sin((float)i*0.1212111f))*0.35f;
				balls2[i].pos.y = (float)cos(time-(float)i*0.29342111f)*0.35f;
				balls2[i].pos.z = (float)sin(time*0.31121f+sin(i-time))*0.35f;
				balls2[i].r = 0.15f + (float)sin(time+i)*0.01f;
				balls2[i].pos = vector_normalize(balls2[i].pos);
				balls2[i].pos = vector_scale(balls2[i].pos, (float)(cos(i*0.11131f-time*0.55311f)+sin(time+(float)sin(time-i+time*0.3f)))*0.2f );
			}

			memcpy(temp,bare_paa_lissom->objects[bare_paa_lissom->object_count-1]->mat,sizeof(matrix));
			matrix_scale(marching_cubes_matrix,vector_make(120,120,120));
			matrix_multiply(marching_cubes_matrix,temp,marching_cubes_matrix);

			IDirect3DDevice9_SetTransform( device, D3DTS_WORLD, (D3DMATRIX*)&marching_cubes_matrix );
			fill_metafield(balls2, BALLS2);
			march_my_cubes_opt(balls2, BALLS2, 0.9f);

			IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);

			set_texture(device,0,refmap);
			IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR );
			IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_ADD);
			IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
			IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_CURRENT);

			draw_marched_cubes(device);

			IDirect3DDevice9_SetRenderTarget(device,0,main_rendertarget);
			draw_overlay(device,rtt_texture_id,0,0,f,TRUE);

			if(time_index==103){
				float f;
				time *= 2;
				f = fade(timetable[time_index-1],3,time,1,0);
				draw_overlay(device,metaball_text,0,0,f,FALSE);

				flash(device,white,time,timetable[time_index-1],1);
			}
		}
		if(time_index==104){
			float f = fade(timetable[103],timetable[104]-timetable[103],time,0,1);

			animate_scene(korridor,180-(time-timetable[time_index-1])*0.8f );
			draw_scene(device,korridor,(beat/4)&1,TRUE);
			draw_overlay(device,black,0,0,f,FALSE);
		}
		if(time_index==105){
			float f = fade(timetable[104],timetable[105]-timetable[104],time,0,1);
			float t = (time-timetable[time_index-1])*0.6f+2.2f;
			animate_scene(fysikkfjall,t);
			draw_scene(device,fysikkfjall,0,TRUE);
			draw_overlay(device,black,0,0,f,FALSE);
		}
#endif
/*
*/
/*
		draw_overlay(device, were_back, (1+sin(time))*0.5f, TRUE);
*/
//		animate_scene(risterom,time);
//		draw_scene(device,risterom,0,TRUE);

#if 0 //helvete_har_frosset
		draw_overlay(device, eatyrcode, 1,FALSE);

		IDirect3DStateBlock9_Apply(default_state);

		animate_particles(particles, PARTICLES, delta_time*30);
		animate_particles(particles2, PARTICLES2, delta_time*28);

		draw_particles(device, particles, PARTICLES, code_0);
		draw_particles(device, particles2, PARTICLES2, code_1);
#endif

#ifdef pikk

//				IDirect3DDevice9_SetRenderTarget(device,0,rtt_surface);
				IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0, 1.0f, 0);

				draw_overlay(device, eatyrcode, TRUE);

				animate_scene(startblob,(time-timetable[39]-0.27f)*0.7453f);
				draw_scene(device,startblob,0,FALSE);
				draw_particles(device, particles, PARTICLES, code_0);
				draw_particles(device, particles2, PARTICLES2, code_1);
//				IDirect3DDevice9_SetRenderTarget(device,0,main_rendertarget);
/*
				draw_radialblur(device,
					(float)sin(time)*0.2f,
					(float)sin(-time*0.331f)*0.13f,
					(float)(2+(float)sin(time*0.5f))*0.2f,
					0,//sin(time)*0.25f,
					rtt_texture_id, TRUE);

				animate_scene(fysikkfjall,time);
				draw_scene(device,fysikkfjall,0,FALSE);
*/
//				draw_overlay(device, rtt_texture_id, TRUE);
#endif

//		draw_overlay(device, eatyrcode, FALSE);

//		video_update(vid, time);
#if 0
//		IDirect3DDevice9_SetRenderTarget(device,0,rtt_surface);

		animate_scene(testscene,time);

//		morph_object(testscene->objects[0], time );
		draw_scene(device,testscene,0,TRUE);
//		draw_particles(device, particles, PARTICLES, particle);

//		IDirect3DDevice9_SetRenderTarget(device,0,main_rendertarget);
#endif
#if 0
		time *=0.5f;

		for(i=0;i<BALLS2;i++){
			balls2[i].pos.x = (float)sin(time+i-sin((float)i*0.1212111f))*0.35f;
			balls2[i].pos.y = (float)cos(time-(float)i*0.29342111f)*0.35f;
			balls2[i].pos.z = (float)sin(time*0.31121f+sin(i-time))*0.35f;
			balls2[i].r = 0.15f + (float)sin(time+i)*0.01f;
			balls2[i].pos = vector_normalize(balls2[i].pos);
			balls2[i].pos = vector_scale(balls2[i].pos, (float)(cos(i*0.11131f-time*0.55311f)+sin(time+(float)sin(time-i+time*0.3f)))*0.2f );
//			balls2[i].pos.x *= 2.8f;
		}

		matrix_translate(temp,vector_make(0,0,87));
		matrix_scale(marching_cubes_matrix,vector_make(50,50,50));
		matrix_multiply(marching_cubes_matrix,temp,marching_cubes_matrix);

		IDirect3DDevice9_SetTransform( device, D3DTS_WORLD, (D3DMATRIX*)&marching_cubes_matrix );
		fill_metafield(balls2, BALLS2);
//		fill_metafield_blur(balls, BALLS,0.98f);
		march_my_cubes_opt(balls2, BALLS2, 0.9f);
//		march_my_cubes(0.9f);

		IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_CW);

		set_texture(device,0,refmap);
		IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR );
		IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_ADD);
		IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
		IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_CURRENT);

		draw_marched_cubes(device);
#endif

#if 0
//		time *= 0.5f;
		grid_zero(g);
//		for(i=0;i<10;i++)
//			grid_wave(g,sin(time-i+sin(i-time))*0.3f,cos(time*0.69f+i*0.733f)*0.3f,7,sin(time+i*0.1f)*0.5f);

		matrix_translate(m, vector_make(cos(time)*1.5f, sin(time)*1.5f,time*10));
		matrix_rotate(temp_matrix, vector_make(sin(time*0.8111f)*0.2f,sin(time*1.2f)*0.2f,time));
		matrix_multiply(m,m,temp_matrix);

//		empty_grid( grid );
		render_tunnel(g,m);

		matrix_rotate(temp_matrix, vector_make(0,M_PI,0));
		matrix_multiply(m,m,temp_matrix);
		render_tunnel(g,m);
		matrix_rotate(temp_matrix, vector_make(M_PI,0,0));
		matrix_multiply(m,m,temp_matrix);
		render_tunnel(g,m);
//		tyfuus_expand_grid( screen, grid, texture );

		grid_add_noice(g,sin(time)*0.1f);

		draw_grid(device, g, circle_particle, FALSE);
#endif
//		IDirect3DDevice9_SetRenderTarget(device,0,main_rendertarget);

//		video_update(vid,time);
/*
		draw_radialblur(device,
			(float)sin(time)*0.2f,
			(float)sin(-time*0.331f)*0.13f,
			(float)(1+(float)sin(time*0.5f))*0.2f,
			0,//sin(time)*0.25f,
			rtt_texture_id, FALSE);
*/
//		IDirect3DStateBlock9_Apply(default_state);

//		draw_overlay(device,rtt_texture_id,FALSE);
//		draw_overlay(device,fullscreen,FALSE);

//		draw_radialblur(device,0,sin(time*0.2f)*2.f, rtt_texture_id);

//		IDirect3DDevice9_StretchRect(device,main_rendertarget,NULL,rtt_surface,NULL,D3DTEXF_NONE);
//		IDirect3DBaseTexture9_GenerateMipSubLevels(rtt_texture);

		IDirect3DDevice9_EndScene(device);
		if(IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL)==D3DERR_DEVICELOST)
			error("fakkin lost device. keep your hands off alt-tab, looser.");

		old_time = time;

		while (PeekMessage(&msg,NULL,0,0,PM_REMOVE)){ 
			TranslateMessage(&msg);
			DispatchMessage(&msg);
			if (msg.message == WM_QUIT ||
			    msg.message == WM_KEYDOWN && LOWORD(msg.wParam) == VK_ESCAPE)
				done = TRUE;
		}
	}while(!done);

	deinit_marching_cubes();
	deinit_overlays();
	deinit_particles();

	free_scene(fysikkfjall);
	free_scene(startblob);
	free_scene(inni_abstrakt);
	free_scene(korridor);
	free_scene(skjerm_rom);
	free_scene(bare_paa_lissom);

	free_materials();
	free_textures();
	free_video(vid);

	rtt_surface->lpVtbl->Release(rtt_surface);
	rtt_32_surface->lpVtbl->Release(rtt_32_surface);

	main_rendertarget->lpVtbl->Release(main_rendertarget);
	IDirect3DStateBlock9_Release(default_state);


	d3dwin_close();

	if (music_file) BASS_StreamFree( music_file );
	if (fp) file_close( fp );
	BASS_Free();

//	pest_close();

	return 0;
}
Exemplo n.º 18
0
int WINAPI WinMain( HINSTANCE instance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
//void entrypoint(void)
{
    MSG         msg;
    int         done=0;
    WININFO     *info = &wininfo;

	window_init(info);

	long st = GetTickCount();
	
	CLogger* myLogger;
	myLogger = new CLogger();

	GraphicsClass* m_Graphics;
	m_Graphics = new GraphicsClass();

	m_Graphics->Initialize(XRES,YRES,info->hWnd);

	// BASS
	BASS_Init(-1,44100,0,0,NULL);
	//char filename[400]="C:\\My_Projects\\frmwrk\\Debug\\lemonade-merry_xmas_nectas.xm";
	char filename[400]="C:\\My_Projects\\frmwrk\\Debug\\bass_system-questa_sera.xm";
	//char * filename= "dark_rat-xmas.xm";
	DWORD chan;
	float time;
	//chan=BASS_MusicLoad(FALSE,"dark_rat-xmas.xm",0,0,BASS_SAMPLE_LOOP|BASS_MUSIC_RAMPS|BASS_MUSIC_PRESCAN,0);
	if (!(chan=BASS_MusicLoad(FALSE,filename,0,0,BASS_MUSIC_RAMPS|BASS_MUSIC_PRESCAN,0)))
	{
		int k=5;
	}

	float dummy;
	int a;
	for (a=0;BASS_ChannelGetAttribute(chan,BASS_ATTRIB_MUSIC_VOL_CHAN+a,&dummy);a++);
	QWORD pos;
	pos=BASS_ChannelGetLength(chan,BASS_POS_BYTE);

	BASS_ChannelPlay(chan,FALSE);

	// programm loop
	long to=0;
	while( !done )
    {
		pos=BASS_ChannelGetPosition(chan,BASS_POS_BYTE);
		time=BASS_ChannelBytes2Seconds(chan,pos);
	
		myLogger->LogThis("pos");
		myLogger->LogThisFloat((float)pos);
		myLogger->LogThis("time");
		myLogger->LogThisFloat((float)time);

		if (time!=0)
		{
			int k=6;
		}
		long t = GetTickCount();
        if( !to ) to=t; 
        t-=to;

		while( PeekMessage(&msg,0,0,0,PM_REMOVE) )
        {
            if( msg.message==WM_QUIT ) done=1;
		    TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
        DrawTime( info, .001f*t );
		m_Graphics->Frame();
		m_Graphics->Render();
	}

	window_end(info);
	
    ExitProcess( 0 );
}
Exemplo n.º 19
0
int main(int argc, char* argv[])
{
	gtk_init(&argc,&argv);

	// check the correct BASS was loaded
	if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
		Error("An incorrect version of BASS was loaded");
		return 0;
	}

	// initialize BASS
	if (!BASS_Init(-1,44100,0,NULL,NULL)) {
		Error("Can't initialize device");
		return 0;
	}

	if (!PlayFile()) { // start a file playing
		BASS_Free();
		return 0;
	}

	// create the window
	win=gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_position(GTK_WINDOW(win),GTK_WIN_POS_CENTER);
	gtk_window_set_resizable(GTK_WINDOW(win),FALSE);
	gtk_window_set_title(GTK_WINDOW(win),"BASS spectrum example (click to toggle mode)");
	g_signal_connect(win,"destroy",GTK_SIGNAL_FUNC(WindowDestroy),NULL);

	GtkWidget *ebox=gtk_event_box_new();
	gtk_container_add(GTK_CONTAINER(win),ebox);
	g_signal_connect(ebox,"button-release-event",GTK_SIGNAL_FUNC(WindowButtonRelease),NULL);

	// create the bitmap
	specpb=gdk_pixbuf_new(GDK_COLORSPACE_RGB,FALSE,8,SPECWIDTH,SPECHEIGHT);
	speci=gtk_image_new_from_pixbuf(specpb);
	gtk_container_add(GTK_CONTAINER(ebox),speci);

	{ // setup palette
		RGB *pal=palette;
		int a;
		memset(palette,0,sizeof(palette));
		for (a=1;a<128;a++) {
			pal[a].rgbGreen=256-2*a;
			pal[a].rgbRed=2*a;
		}
		for (a=0;a<32;a++) {
			pal[128+a].rgbBlue=8*a;
			pal[128+32+a].rgbBlue=255;
			pal[128+32+a].rgbRed=8*a;
			pal[128+64+a].rgbRed=255;
			pal[128+64+a].rgbBlue=8*(31-a);
			pal[128+64+a].rgbGreen=8*a;
			pal[128+96+a].rgbRed=255;
			pal[128+96+a].rgbGreen=255;
			pal[128+96+a].rgbBlue=8*a;
		}
	}

	// setup update timer (40hz)
	g_timeout_add(25,UpdateSpectrum,NULL);

	gtk_widget_show_all(win);
	gtk_main();

	gdk_pixbuf_unref(specpb);

	BASS_Free();

	return 0;
}
Exemplo n.º 20
0
void main(int argc, char **argv)
{
	const char *fxname[9]={"CHORUS","COMPRESSOR","DISTORTION","ECHO",
		"FLANGER","GARGLE","I3DL2REVERB","PARAMEQ","REVERB"};
	HFX fx[9]={0}; // effect handles
	INPUT_RECORD keyin;
	DWORD r,buflen;

	printf("BASS Simple Sinewave Synth\n"
			"--------------------------\n");

	// check the correct BASS was loaded
	if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
		printf("An incorrect version of BASS.DLL was loaded");
		return;
	}

	// 10ms update period
	BASS_SetConfig(BASS_CONFIG_UPDATEPERIOD,10);

	// setup output - get latency
	if (!BASS_Init(-1,44100,BASS_DEVICE_LATENCY,0,NULL))
		Error("Can't initialize device");

	BASS_GetInfo(&info);
	// default buffer size = update period + 'minbuf' + 1ms extra margin
	BASS_SetConfig(BASS_CONFIG_BUFFER,10+info.minbuf+1);
	buflen=BASS_GetConfig(BASS_CONFIG_BUFFER);
	// if the device's output rate is unknown default to 44100 Hz
	if (!info.freq) info.freq=44100;
	// create a stream, stereo so that effects sound nice
	stream=BASS_StreamCreate(info.freq,2,0,(STREAMPROC*)WriteStream,0);

	printf("device latency: %dms\n",info.latency);
	printf("device minbuf: %dms\n",info.minbuf);
	printf("ds version: %d (effects %s)\n",info.dsver,info.dsver<8?"disabled":"enabled");
	printf("press these keys to play:\n\n"
		"  2 3  5 6 7  9 0  =\n"
		" Q W ER T Y UI O P[ ]\n\n"
		"press -/+ to de/increase the buffer\n"
		"press spacebar to quit\n\n");
	if (info.dsver>=8) // DX8 effects available
		printf("press F1-F9 to toggle effects\n\n");
	printf("using a %dms buffer\r",buflen);

	BASS_ChannelPlay(stream,FALSE);

	while (ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE),&keyin,1,&r)) {
		int key;
		if (keyin.EventType!=KEY_EVENT) continue;
		if (keyin.Event.KeyEvent.wVirtualKeyCode==VK_SPACE) break;
		if (keyin.Event.KeyEvent.bKeyDown) {
			if (keyin.Event.KeyEvent.wVirtualKeyCode==VK_SUBTRACT
				|| keyin.Event.KeyEvent.wVirtualKeyCode==VK_ADD) {
				// recreate stream with smaller/larger buffer
				BASS_StreamFree(stream);
				if (keyin.Event.KeyEvent.wVirtualKeyCode==VK_SUBTRACT)
					BASS_SetConfig(BASS_CONFIG_BUFFER,buflen-1); // smaller buffer
				else 
					BASS_SetConfig(BASS_CONFIG_BUFFER,buflen+1); // larger buffer
				buflen=BASS_GetConfig(BASS_CONFIG_BUFFER);
				printf("using a %dms buffer\t\t\r",buflen);
				stream=BASS_StreamCreate(info.freq,2,0,(STREAMPROC*)WriteStream,0);
				// set effects on the new stream
				for (r=0;r<9;r++) if (fx[r]) fx[r]=BASS_ChannelSetFX(stream,BASS_FX_DX8_CHORUS+r,0);
				BASS_ChannelPlay(stream,FALSE);
			}
			if (keyin.Event.KeyEvent.wVirtualKeyCode>=VK_F1
				&& keyin.Event.KeyEvent.wVirtualKeyCode<=VK_F9) {
				r=keyin.Event.KeyEvent.wVirtualKeyCode-VK_F1;
				if (fx[r]) {
					BASS_ChannelRemoveFX(stream,fx[r]);
					fx[r]=0;
					printf("effect %s = OFF\t\t\r",fxname[r]);
				} else {
					// set the effect, not bothering with parameters (use defaults)
					if (fx[r]=BASS_ChannelSetFX(stream,BASS_FX_DX8_CHORUS+r,0))
						printf("effect %s = ON\t\t\r",fxname[r]);
				}
			}
		}
		for (key=0;key<KEYS;key++)
			if (keyin.Event.KeyEvent.wVirtualKeyCode==keys[key]) {
				if (keyin.Event.KeyEvent.bKeyDown && vol[key]<MAXVOL) {
					pos[key]=0;
					vol[key]=MAXVOL+DECAY/2; // start key (setting "vol" slightly higher than MAXVOL to cover any rounding-down)
				} else if (!keyin.Event.KeyEvent.bKeyDown && vol[key])
					vol[key]-=DECAY; // trigger key fadeout
				break;
			}
	}

	BASS_Free();
}
Exemplo n.º 21
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
  int i = 0;
  DWORD chan = 0;
  DWORD act = 0;
  DWORD volume = 100;
  wchar_t file[320] = L"";
  int argc = 0;
  LPWSTR *argv;
  int status = 0;

  /* Check the correct BASS was loaded */
  if(HIWORD(BASS_GetVersion()) != BASSVERSION)
  {
    usage(1, "Error: An incorrect version of BASS was loaded!");
  }

  argv = CommandLineToArgvW(GetCommandLineW(), &argc);

  if(NULL == argv)
  {
    printf("Error: Could not determine arguments!\n");
    exit(1);
  }

  if(argc > 4)
  {
    usage(1, "Error: Too many arguments!\n");
  }
  else
  {
    for (i = 1; i < argc; i++)
    {
      if (wcscmp(argv[i], L"-ver") == 0)
      {
        usage(0, "bassplayer-win version 2.3 by Christopher Brochtrup.\n");
      }
      else if(wcscmp(argv[i], L"-vol") == 0)
      {
        i++;
        volume = _wtoi(argv[i]);
      }
      else
      {
        wcsncpy(file, argv[i], 255);
      }
    }
  }

  LocalFree(argv);

  if(wcslen(file) == 0)
  {
    usage(1, "Error: No file provided!\n");
  }

  status = BASS_Init(-1, 44100, 0, 0, NULL);

  if(!status)
  {
    print_bass_error("BASS_Init()");
  }

  chan = BASS_StreamCreateFile(FALSE, file, 0, 0, BASS_UNICODE);

  if(!chan)
  {
    print_bass_error("BASS_StreamCreateFile()");
  }

  BASS_SetConfig(BASS_CONFIG_GVOL_STREAM, volume*100); /* Global stream volume (0-10000) */

  status = BASS_ChannelPlay(chan, FALSE);

  if(!status)
  {
    print_bass_error("BASS_ErrorGetCode()");
  }

  /* Wait for file to finish playing */
  while(act = BASS_ChannelIsActive(chan))
  {
    Sleep(50);
  }

  BASS_Free();

  exit(0);

} /* WinMain */
Exemplo n.º 22
0
int main(int argc, char* argv[])
{
	IBNibRef nibRef;
	OSStatus err;
	glob_t g;
    
	// check the correct BASS was loaded
	if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
		Error("An incorrect version of BASS was loaded");
		return 0;
	}

	// initialize default output device
	if (!BASS_Init(-1,44100,0,NULL,NULL)) {
		Error("Can't initialize device");
		return 0;
	}

	// Create Window and stuff
	err = CreateNibReference(CFSTR("plugins"), &nibRef);
	if (err) return err;
	err = CreateWindowFromNib(nibRef, CFSTR("Window"), &win);
	if (err) return err;
	DisposeNibReference(nibRef);

	DataBrowserCallbacks dbc;
	dbc.version=kDataBrowserLatestCallbacks;
	InitDataBrowserCallbacks(&dbc);
	dbc.u.v1.itemDataCallback=MyDataBrowserItemDataCallback;
	ControlRef list=GetControl(20);
	SetDataBrowserCallbacks(list,&dbc);

	{ // look for plugins (in the executable directory)
		char path[300];
		DWORD l=sizeof(path);
		_NSGetExecutablePath(path,&l);
		strcpy(strrchr(path,'/')+1,"libbass*.dylib");
		if (!glob(path,0,0,&g)) {
			int a;
			for (a=0;a<g.gl_pathc;a++) {
				if (BASS_PluginLoad(g.gl_pathv[a],0)) { // plugin loaded,  add it to the list...
					char *p=strrchr(g.gl_pathv[a],'/')+1;
					AddDataBrowserItems(list,kDataBrowserNoItem,1,(DataBrowserItemID*)&p,kDataBrowserItemNoProperty);
				}
			}
		}
		DWORD c;
		GetDataBrowserItemCount(list,kDataBrowserNoItem,FALSE,kDataBrowserItemNoState,(DataBrowserItemState*)&c);
		if (!c) { // no plugins...
			static const char *noplugins="no plugins - visit the BASS webpage to get some";
			AddDataBrowserItems(list,kDataBrowserNoItem,1,(DataBrowserItemID*)&noplugins,kDataBrowserItemNoProperty);
		}
	}

	SetupControlHandler(10,kEventControlHit,OpenEventHandler);
	SetControlAction(GetControl(12),NewControlActionUPP(PosEventHandler));

	EventLoopTimerRef timer;
	InstallEventLoopTimer(GetCurrentEventLoop(),kEventDurationNoWait,kEventDurationSecond/2,NewEventLoopTimerUPP(TimerProc),0,&timer);

	ShowWindow(win);
	RunApplicationEventLoop();

	globfree(&g);

	// "free" the output device and all plugins
	BASS_Free();
	BASS_PluginFree(0);

    return 0; 
}
Exemplo n.º 23
0
BOOL CALLBACK dialogproc(HWND h,UINT m,WPARAM w,LPARAM l)
{
	DWORD a=0;
	float freq;
	char c[30];

	BASS_BFX_PEAKEQ eq;		// dsp peaking equalizer
	BASS_BFX_PHASER phs;	// dsp phaser

	switch (m) {
		case WM_COMMAND:
			switch (LOWORD(w)) {
				case ID_OPEN:
					{
						char file[MAX_PATH]="";
						ofn.lpstrFilter="playable files\0*.mo3;*.xm;*.mod;*.s3m;*.it;*.mtm;*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aif\0All files\0*.*\0\0";
						ofn.lpstrFile=file;
						if (GetOpenFileName(&ofn)) {
							memcpy(path,file,ofn.nFileOffset);
							path[ofn.nFileOffset-1]=0;

							// free previous dsp effects & handles
							BASS_StreamFree(chan);	// free stream
							BASS_MusicFree(chan);	// free music

							if(!(chan=BASS_StreamCreateFile(FALSE, file, 0, 0, BASS_SAMPLE_LOOP|floatable))&&
								!(chan=BASS_MusicLoad(FALSE, file, 0, 0, BASS_MUSIC_LOOP|BASS_MUSIC_RAMP|floatable,0))){
								// not a WAV/MP3 or MOD
								MESS(ID_OPEN,WM_SETTEXT,0,"click here to open a file && play it...");
								Error("Selected file couldnt be loaded!");
								break;
							}

							// update the Button to show the loaded file name
							MESS(ID_OPEN,WM_SETTEXT,0,GetFileName(file));

							// set dsp effects
							SendMessage(win,WM_COMMAND,IDC_CHKEQ,l);
							SendMessage(win,WM_COMMAND,IDC_CHKPHS,l);

							// get current sample rate
							BASS_ChannelGetAttribute(chan, BASS_ATTRIB_FREQ, &freq);
							oldfreq = freq;

							// set the dx sample rate & view
							MESS(IDC_DXRATE,TBM_SETRANGEMAX,0,(long)(freq * 1.3f));
							MESS(IDC_DXRATE,TBM_SETRANGEMIN,0,(long)(freq * 0.7f));
							MESS(IDC_DXRATE,TBM_SETPOS,TRUE,(long)freq);
							MESS(IDC_DXRATE,TBM_SETPAGESIZE,0,(long)(freq * 0.01f));	// by 1%

							sprintf(c,"DirectX Samplerate = %dHz", (long)freq);
							MESS(IDC_SDXRATE,WM_SETTEXT,0,c);

							// play it!
							BASS_ChannelPlay(chan, FALSE);
						}
					}
					return 1;

				case IDC_CHKEQ:
					if (MESS(IDC_CHKEQ,BM_GETCHECK,0,0))
						SetDSP_EQ(0.0f, 2.5f, 0.0f, 125.0f, 1000.0f, 8000.0f);
					else
						BASS_ChannelRemoveFX(chan, fxEQ);
				return 1;

				case IDC_CHKPHS:
					if(MESS(IDC_CHKPHS,BM_GETCHECK,0,0)){
						fxPhaser=BASS_ChannelSetFX(chan, BASS_FX_BFX_PHASER,0);

						BASS_FXGetParameters(fxPhaser, &phs);
							phs.fWetMix = (float)MESS(IDC_WETMIX,TBM_GETPOS,0,0) / 1000.0f;
							phs.fDryMix = (float)MESS(IDC_DRYMIX,TBM_GETPOS,0,0) / 1000.0f;
							phs.fFeedback = (float)MESS(IDC_FEEDBACK,TBM_GETPOS,0,0) / 1000.0f;
							phs.fRate = (float)MESS(IDC_RATE,TBM_GETPOS,0,0) / 10.0f;
							phs.fRange = (float)MESS(IDC_RANGE,TBM_GETPOS,0,0) / 10.0f;
							phs.fFreq = (float)MESS(IDC_FREQ,TBM_GETPOS,0,0) / 10.0f;
						BASS_FXSetParameters(fxPhaser, &phs);
					}else
						BASS_ChannelRemoveFX(chan, fxPhaser);
				return 1;

			}
			return 1;

		case WM_VSCROLL:
			if(l){
				UpdateFX(GetDlgCtrlID((HWND)l)-IDC_SLDEQ1);
			}
		return 1;

		case WM_HSCROLL:
			if(!BASS_ChannelIsActive(chan)) break;

			switch (GetDlgCtrlID((HWND)l)) {
				case IDC_DXRATE:
					BASS_ChannelSetAttribute(chan, BASS_ATTRIB_FREQ, (float)MESS(IDC_DXRATE, TBM_GETPOS, 0, 0));

					sprintf(c,"DirectX Samplerate = %dHz", MESS(IDC_DXRATE, TBM_GETPOS, 0, 0));
					MESS(IDC_SDXRATE,WM_SETTEXT,0,c);

					// update all bands fCenters after changing samplerate
					{
						int i;
						for(i=0;i<3;i++){
							eq.lBand = i;
							BASS_FXGetParameters(fxEQ, &eq);
								eq.fCenter = eq.fCenter * (float)MESS(IDC_DXRATE, TBM_GETPOS, 0, 0) / oldfreq;
							BASS_FXSetParameters(fxEQ, &eq);
						}
						oldfreq = (float)MESS(IDC_DXRATE, TBM_GETPOS, 0, 0);
					}
				break;

				case IDC_DRYMIX:
				case IDC_WETMIX:
				case IDC_FEEDBACK:
				case IDC_RATE:
				case IDC_RANGE:
				case IDC_FREQ:
					BASS_FXGetParameters(fxPhaser, &phs);
						phs.fWetMix = (float)MESS(IDC_WETMIX,TBM_GETPOS,0,0) / 1000.0f;
						phs.fDryMix = (float)MESS(IDC_DRYMIX,TBM_GETPOS,0,0) / 1000.0f;
						phs.fFeedback = (float)MESS(IDC_FEEDBACK,TBM_GETPOS,0,0) / 1000.0f;
						phs.fRate = (float)MESS(IDC_RATE,TBM_GETPOS,0,0) / 10.0f;
						phs.fRange = (float)MESS(IDC_RANGE,TBM_GETPOS,0,0) / 10.0f;
						phs.fFreq = (float)MESS(IDC_FREQ,TBM_GETPOS,0,0) / 10.0f;
					BASS_FXSetParameters(fxPhaser, &phs);
			}
			return 1;

		case WM_INITDIALOG:
			win=h;
			GetCurrentDirectory(MAX_PATH,path);
			memset(&ofn,0,sizeof(ofn));
			ofn.lStructSize=sizeof(ofn);
			ofn.hwndOwner=h;
			ofn.hInstance=inst;
			ofn.nMaxFile=MAX_PATH;
			ofn.Flags=OFN_HIDEREADONLY|OFN_EXPLORER;

			// enable floating-point DSP
			BASS_SetConfig(BASS_CONFIG_FLOATDSP, TRUE);

			// setup output - default device, 44100hz, stereo, 16 bits
			if (!BASS_Init(-1,44100,0,win,NULL)) {
				Error("Can't initialize device");
				DestroyWindow(win);
				return 1;
			}

			// check for floating-point capability
			floatable = BASS_StreamCreate(44100, 2, BASS_SAMPLE_FLOAT, 0, 0);
			if (floatable) {
				BASS_StreamFree(floatable);  //woohoo!
			    floatable = BASS_SAMPLE_FLOAT;
			}

			// initialize dsp eq sliders
			MESS(IDC_SLDEQ1,TBM_SETRANGE,FALSE,MAKELONG(0,20));
			MESS(IDC_SLDEQ1,TBM_SETPOS,TRUE,10);

			MESS(IDC_SLDEQ2,TBM_SETRANGE,FALSE,MAKELONG(0,20));
			MESS(IDC_SLDEQ2,TBM_SETPOS,TRUE,10);

			MESS(IDC_SLDEQ3,TBM_SETRANGE,FALSE,MAKELONG(0,20));
			MESS(IDC_SLDEQ3,TBM_SETPOS,TRUE,10);

			// dx rate
			MESS(IDC_DXRATE,TBM_SETRANGEMAX,0,(long)(44100.0f*1.3f));
			MESS(IDC_DXRATE,TBM_SETRANGEMIN,0,(long)(44100.0f*0.7f));
			MESS(IDC_DXRATE,TBM_SETPOS,TRUE,44100);
			MESS(IDC_DXRATE,TBM_SETPAGESIZE,0,(long)(44100.0f*0.01f));	// by 1%

			// DryMix
			MESS(IDC_DRYMIX,TBM_SETRANGE,0,MAKELONG(-2000,2000));
			MESS(IDC_DRYMIX,TBM_SETPOS,TRUE,-999);

			// WetMix
			MESS(IDC_WETMIX,TBM_SETRANGE,0,MAKELONG(-2000,2000));
			MESS(IDC_WETMIX,TBM_SETPOS,TRUE,999);

			// Feedback
			MESS(IDC_FEEDBACK,TBM_SETRANGE,0,MAKELONG(-1000,1000));
			MESS(IDC_FEEDBACK,TBM_SETPOS,TRUE,-60);

			// Rate
			MESS(IDC_RATE,TBM_SETRANGE,0,MAKELONG(0,100));
			MESS(IDC_RATE,TBM_SETPOS,TRUE,2);

			// Range
			MESS(IDC_RANGE,TBM_SETRANGE,0,MAKELONG(0,100));
			MESS(IDC_RANGE,TBM_SETPOS,TRUE,60);

			// Freq
			MESS(IDC_FREQ,TBM_SETRANGE,0,MAKELONG(0,10000));
			MESS(IDC_FREQ,TBM_SETPOS,TRUE,1000);

			Font=CreateFont(-12,0,0,0,FW_BOLD,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_STRING_PRECIS,
				            CLIP_STROKE_PRECIS,DRAFT_QUALITY,DEFAULT_PITCH | FF_DONTCARE,
							"MS Sans Serif");
			// set the font for check boxes
			MESS(IDC_CHKEQ, WM_SETFONT, Font, TRUE);
			MESS(IDC_CHKPHS,WM_SETFONT, Font, TRUE);
		return 1;

		case WM_CLOSE:
			EndDialog(h,0);
			return 0;
		break;
	}
	return 0;
}
int WINAPI WinMain( HINSTANCE instance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
    MSG         msg;
    int         done=0;
    WININFO     *info = &wininfo;

    info->hInstance = GetModuleHandle( 0 );

    //if( MessageBox( 0, "fullscreen?", info->wndclass, MB_YESNO|MB_ICONQUESTION)==IDYES ) info->full++;

    if (!window_init(info))
    {
        window_end(info);
        MessageBox(0, "window_init()!", "error", MB_OK|MB_ICONEXCLAMATION);
        return 0;
    }

	if (initGL(info))
	{
		return 0;
	}

    //intro_init();

	// start music playback
#ifdef MUSIC
	BASS_Init(-1,44100,0,info->hWnd,NULL);
	HSTREAM mp3Str=BASS_StreamCreateFile(FALSE,"Musik/set1.mp3",0,0,0);
	BASS_ChannelPlay(mp3Str, TRUE);
	BASS_Start();
#endif

	// Initialize COM
	HRESULT hr = CoInitialize(NULL);
	if (FAILED(hr)) exit(-1);

	// Example editor usage
	char errorText[MAX_ERROR_LENGTH+1];
	char filename[SM_MAX_FILENAME_LENGTH+1];
	sprintf_s(filename, SM_MAX_FILENAME_LENGTH, "shaders/%s", usedShader[usedIndex]);
	if (editor.loadText(filename, errorText))
	{
		MessageBox(info->hWnd, errorText, "Editor init", MB_OK);
		return -1;
	}

    long to=timeGetTime();
    while( !done )
        {
		long t = timeGetTime() - to;

        while( PeekMessage(&msg,0,0,0,PM_REMOVE) )
        {
            if( msg.message==WM_QUIT ) done=1;
		    TranslateMessage( &msg );
            DispatchMessage( &msg );
        }

		glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT);

        intro_do(t);
		editor.render(t);

		SwapBuffers( info->hDC );
	}

    window_end( info );

#ifdef MUSIC
	// music uninit
	BASS_ChannelStop(mp3Str);
	BASS_StreamFree(mp3Str);
	BASS_Free();
#endif

	// Un-initialize COM
	CoUninitialize();

    return( 0 );
}
Exemplo n.º 25
0
void NLS::Init() {
	Time::Reset();
	Config::Load();
	locale::global(locale(""));
#ifndef _DEBUG
	// Log output to logfile
	freopen("nolifestory.log", "a", stdout);
	freopen("nolifestory.log", "a", stderr);
#endif
	cout << endl << "Initializing NoLifeStory" << endl;
	cout << "아무 라이프 스토리 없음" << endl;
	cout << "유니 코드는 사용" << endl;
	cout << "Using locale: " << locale().name() << endl;

	srand(time(0));

	auto initDone = [](const string &msg) { cout << "[Loading] Init " << msg << " done." << endl; };

	Crypto::Init();
	initDone("Cryptography");

	InitWZ();
	initDone("WZ data");

	Network::Init();
	initDone("Network");

	Graphics::Init();
	initDone("Graphics");

#ifdef NLS_WINDOWS
	BASS_Init(-1, 44100, 0, window->GetSystemHandle(), 0);
#else
	BASS_Init(-1, 44100, 0, (void*)window->GetSystemHandle(), 0);
#endif
	initDone("BASS Sound System");

	if (Mindfuck) {
		HSTREAM s = BASS_StreamCreateFile(false, "bgm.mp3", 0, 0, BASS_SAMPLE_FLOAT|BASS_SAMPLE_LOOP);
		BASS_ChannelPlay(s, true);
	}

	Text::Init();
	initDone("Text");

	Player::Init();
	ThisPlayer = new _ThisPlayer;
	initDone("Player Data");

	View::Init();
	initDone("View");

	Mouse::Init();
	initDone("Mouse");

	UI::Init();
	initDone("User Interface");

	Physics::Init();
	initDone("Physics System");

	Key::Init();
	initDone("AES Keys");

	Time::Step();
	cout << "Initialization complete" << endl;

	MainChat << Text::Color(255, 255, 0, 255) << "[NoLifeStory] Welcome to NoLifeStory!" << cendl;
	if (NLS::Network::Online) {
		string v1 = NLS::Network::Version/100?tostring(NLS::Network::Version/100):string();
		string v2 = tostring(NLS::Network::Version%100);
		MainChat << Text::Color(255, 20, 50) << "[INFO] Connected with MapleStory v" + v1 + "." + v2 + "!" << cendl;
	} else {
		MainChat << Text::Color(255, 20, 50) << "[INFO] Not connected with any MapleStory server!" << cendl;
	}
	if (Profiling) {
		cout << "Running in profiling mode. Have fun!" << cendl;
		Node n = WZ["Map"]["Map"];
		for (int i = 0; i < 10; i++) {
			Node nn = n["Map"+tostring(i)];
			if (nn)
			for_each(nn.begin(), nn.end(), [](pair<string, Node> p){
				ProfileMaps.push_back(p.first);
			});
		}
	}

	Map::Load(Network::Online?"MapLogin":"******", "");
	Map::Load();
}
Exemplo n.º 26
0
Arquivo: 3dtest.c Projeto: adius/FeetJ
int main(int argc, char* argv[])
{
	regex_t fregex[2];

	gtk_init(&argc,&argv);

	// check the correct BASS was loaded
	if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
		Error("An incorrect version of BASS was loaded");
		return 0;
	}

	// Initialize the output device with 3D support
	if (!BASS_Init(-1,44100,BASS_DEVICE_3D,NULL,NULL)) {
		Error("Can't initialize device");
		return 0;
	}

	{
		BASS_INFO i;
		BASS_GetInfo(&i);
		if (i.speakers>2) {
			GtkWidget *dialog=gtk_message_dialog_new(NULL,0,
				GTK_MESSAGE_QUESTION,GTK_BUTTONS_YES_NO,"Multiple speakers were detected. Would you like to use them?");
			if (gtk_dialog_run(GTK_DIALOG(dialog))==GTK_RESPONSE_NO)
				BASS_SetConfig(BASS_CONFIG_3DALGORITHM,BASS_3DALG_OFF);
			gtk_widget_destroy(dialog);
		}
	}

	// Use meters as distance unit, real world rolloff, real doppler effect
	BASS_Set3DFactors(1,1,1);

	// initialize GUI
	glade=glade_xml_new(GLADE_PATH"3dtest.glade",NULL,NULL);
	if (!glade) return 0;
	win=GetWidget("window1");
	if (!win) return 0;
	glade_xml_signal_autoconnect(glade);
	g_signal_connect(gtk_tree_view_get_selection(GTK_TREE_VIEW(GetWidget("channels"))),"changed",G_CALLBACK(ListSelectionChange),NULL);

	{ // setup list
		GtkTreeView *list=GTK_TREE_VIEW(GetWidget("channels"));
		GtkTreeViewColumn *col=gtk_tree_view_column_new();
		gtk_tree_view_append_column(list,col);
		GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
		gtk_tree_view_column_pack_start(col,renderer,TRUE);
		gtk_tree_view_column_add_attribute(col, renderer, "text", 0);
		GtkListStore *liststore=gtk_list_store_new(1,G_TYPE_STRING);
		gtk_tree_view_set_model(list,GTK_TREE_MODEL(liststore));
		g_object_unref(liststore);
	}

	{ // initialize file selector
		GtkFileFilter *filter;
		filesel=gtk_file_chooser_dialog_new("Open File",GTK_WINDOW(win),GTK_FILE_CHOOSER_ACTION_OPEN,
			GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,GTK_STOCK_OPEN,GTK_RESPONSE_ACCEPT,NULL);
		filter=gtk_file_filter_new();
		gtk_file_filter_set_name(filter,"Streamable files (wav/aif/mp3/mp2/mp1/ogg)");
		regcomp(&fregex[0],"\\.(mp[1-3]|ogg|wav|aif)$",REG_ICASE|REG_NOSUB|REG_EXTENDED);
		gtk_file_filter_add_custom(filter,GTK_FILE_FILTER_FILENAME,FileExtensionFilter,&fregex[0],NULL);
		gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(filesel),filter);
		filter=gtk_file_filter_new();
		gtk_file_filter_set_name(filter,"MOD music files (mo3/xm/mod/s3m/it/mtm/umx)");
		regcomp(&fregex[1],"\\.(mo3|xm|mod|s3m|it|umx)$",REG_ICASE|REG_NOSUB|REG_EXTENDED);
		gtk_file_filter_add_custom(filter,GTK_FILE_FILTER_FILENAME,FileExtensionFilter,&fregex[1],NULL);
		gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(filesel),filter);
		filter=gtk_file_filter_new();
		gtk_file_filter_set_name(filter,"All files");
		gtk_file_filter_add_pattern(filter,"*");
		gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(filesel),filter);
	}

	g_timeout_add(TIMERPERIOD,Update,NULL);

	UpdateButtons();

	gtk_main();

	gtk_widget_destroy(filesel);
	regfree(&fregex[0]);
	regfree(&fregex[1]);

	BASS_Free(); // close output

    return 0;
}
Exemplo n.º 27
0
inline bool KNMusicBackendBass::initialBass(DWORD &channelFlags)
{
    //Detect operating system version and enable option for using WASAPI.
#ifdef Q_OS_WIN64
    m_wasapiEnabled=m_systemConfigure->data("WASAPI", false).toBool();
#endif
    //Get the buffer length.
    int bufferLength=m_systemConfigure->data("BufferLength", 500).toInt();
    //Check buffer length is valid.
    if(bufferLength<10)
    {
        //For minimum, buffer should be 10ms.
        bufferLength=10;
    }
    else if(bufferLength>5000)
    {
        //For maximum, buffer should be 5000ms.
        bufferLength=5000;
    }
    //Get the output device index.
    QString outputDeviceId="-1";
    {
        //Check whether the configure has output device.
        if(m_systemConfigure->contains("OutputDevice"))
        {
            //Get the json object.
            QJsonObject deviceInfo=
                    m_systemConfigure->data("OutputDevice").toJsonObject();
            //Get the device info Id.
            outputDeviceId=deviceInfo.value("Id").toString();
        }
    }
    //Check the bass library version first.
    if(HIWORD(BASS_GetVersion()) > BASSVERSION)
    {
        //Failed to load a higher version bass library.
        return false;
    }
    //Enabled float digital signal processing.
    //DON'T MOVE THIS, this should config before bass init.
    if(m_systemConfigure->data("Float", false).toBool())
    {
        //Enable 32-bit floating-point sample data converting.
        BASS_SetConfig(BASS_CONFIG_FLOATDSP, TRUE);
    }
    //Set the buffer length.
    BASS_SetConfig(BASS_CONFIG_BUFFER, static_cast<DWORD>(bufferLength));
    //Get the setting sample rate.
    QString userSampleRate=
            m_systemConfigure->data("SampleRate", "None").toString();
    //Set a default initial sample rate.
    int initialSampleRate=44100;
#ifdef Q_OS_WIN64
    if(m_wasapiEnabled)
    {
        //Prepare the user output device info.
        int userOutputDevice=-1;
        //Check the user output device selection.
        if(outputDeviceId.startsWith("w"))
        {
            //Get the possible output device.
            userOutputDevice=outputDeviceId.mid(1).toInt();
        }
        //For 64-bit Windows, we will enable WASAPI as the playing API instead
        //of using DirectX.
        //Find the output device.
        BASS_WASAPI_DEVICEINFO deviceInfo;
        int deviceCount=0;
        QList<int> validDeviceIndex;
        for(deviceCount=0;
            BASS_WASAPI_GetDeviceInfo(deviceCount, &deviceInfo);
            ++deviceCount)
        {
            //Check the device flag.
            if((deviceInfo.flags & (BASS_DEVICE_LOOPBACK |
                                    BASS_DEVICE_INPUT))==0)
            {
                //Check the valid device list.
                if((deviceInfo.flags & BASS_DEVICE_DEFAULT)
                        ==BASS_DEVICE_DEFAULT)
                {
                    //Save the default device index.
                    m_wasapiOutputDevice=deviceCount;
                }
                //Add the device to the list.
                validDeviceIndex.append(deviceCount);
            }
        }
        // Check the device index.
        if(validDeviceIndex.isEmpty())
        {
            //Failed to find the output device.
            return false;
        }
        //Check the user selection is still valid.
        if(validDeviceIndex.contains(userOutputDevice))
        {
            //Set the user selected device as the output device.
            m_wasapiOutputDevice=userOutputDevice;
        }
        //Because we won't playing anything via BASS, so don't need an update
        //thread.
        BASS_SetConfig(BASS_CONFIG_UPDATETHREADS, 0);
        //Setup BASS - "no sound" device with the "mix" sample rate (default for
        //MOD music)
        BASS_Init(0, deviceInfo.mixfreq, 0, 0, NULL);
    }
    else
    {
#endif
        //Check the start data.
        DWORD outputDevice=-1;
        if(!outputDeviceId.startsWith("w"))
        {
            //Get the raw output device
            int rawOutputDevice=outputDeviceId.toInt();
            //Check whether the output device is valid.
            QJsonArray allDevices=deviceList();
            //Check whether the output device is existed.
            if(rawOutputDevice>=-1 && (rawOutputDevice<allDevices.size()-1))
            {
                //Set the device back to default.
                outputDevice=rawOutputDevice;
            }
        }
        //Normal bass initialize.
        //Prepare the bass initial flag.
        DWORD initFlag=0;
        //Check the user sample rate.
        if(QString::number(userSampleRate.toInt())==userSampleRate)
        {
            //Update the initial sample rate.
            initialSampleRate=userSampleRate.toInt();
            //Add the initial flag.
            initFlag |= BASS_DEVICE_FREQ;
        }
        //Check the preference setting.
        if(m_systemConfigure->data("Stereo", false).toBool())
        {
            //Add stereo flag.
            initFlag |= BASS_DEVICE_STEREO;
        }
        //Initial bass library.
        if(!BASS_Init(outputDevice, initialSampleRate, initFlag, NULL, NULL))
        {
            //Failed to initial the library bass.
            return false;
        }
#ifdef Q_OS_WIN64
    }
#endif
    //Clear the channel flags.
    channelFlags=0;
    //When enabling 32-bit floating converting, check the float support.
    if(m_systemConfigure->data("Float", false).toBool())
    {
        //Check float dsp supporting.
        DWORD fdpsCheck=BASS_StreamCreate(initialSampleRate,
                                          2, BASS_SAMPLE_FLOAT, NULL, 0);
        //If support the float dsp,
        if(fdpsCheck)
        {
            //Free the check channel, recover the memory.
            BASS_StreamFree(fdpsCheck);
            //Set fdps support flag.
            channelFlags |= BASS_SAMPLE_FLOAT;
        }
    }
    //Load complete.
    return true;
}
Exemplo n.º 28
0
INT_PTR CALLBACK dialogproc(HWND h,UINT m,WPARAM w,LPARAM l)
{
	switch (m) {
		case WM_COMMAND:
			switch (LOWORD(w)) {
				case IDCANCEL:
					DestroyWindow(h);
					break;
				case 10:
					{
						char file[MAX_PATH]="";
						ofn.lpstrFile=file;
						ofn.nMaxFile=MAX_PATH;
						if (GetOpenFileName(&ofn)) {
							BASS_StreamFree(chan); // free the old stream
							if (!(chan=BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_LOOP))) {
								// it ain't playable
								MESS(10,WM_SETTEXT,0,"click here to open a file...");
								MESS(11,WM_SETTEXT,0,"");
								Error("Can't play the file");
								break;
							}
							MESS(10,WM_SETTEXT,0,file);
							{ // display the file type and length
								QWORD bytes=BASS_ChannelGetLength(chan,BASS_POS_BYTE);
								DWORD time=BASS_ChannelBytes2Seconds(chan,bytes);
								BASS_CHANNELINFO info;
								BASS_ChannelGetInfo(chan,&info);
								sprintf(file,"channel type = %x (%s)\nlength = %I64u (%u:%02u)",
									info.ctype,GetCTypeString(info.ctype,info.plugin),bytes,time/60,time%60);
								MESS(11,WM_SETTEXT,0,file);
								MESS(12,TBM_SETRANGE,1,MAKELONG(0,time)); // update scroller range
							}
							BASS_ChannelPlay(chan,FALSE);
						}
					}
					break;
			}
			break;

		case WM_HSCROLL:
			if (l && LOWORD(w)!=SB_THUMBPOSITION && LOWORD(w)!=SB_ENDSCROLL) { // set the position
				int pos=SendMessage((HWND)l,TBM_GETPOS,0,0);
				BASS_ChannelSetPosition(chan,BASS_ChannelSeconds2Bytes(chan,pos),BASS_POS_BYTE);
			}
			break;

		case WM_TIMER:
			MESS(12,TBM_SETPOS,1,(DWORD)BASS_ChannelBytes2Seconds(chan,BASS_ChannelGetPosition(chan,BASS_POS_BYTE))); // update position
			break;

		case WM_INITDIALOG:
			win=h;
			// initialize default output device
			if (!BASS_Init(-1,44100,0,win,NULL)) {
				Error("Can't initialize device");
				DestroyWindow(win);
				break;
			}
			// initialize file selector
			memset(&ofn,0,sizeof(ofn));
			ofn.lStructSize=sizeof(ofn);
			ofn.hwndOwner=h;
			ofn.Flags=OFN_HIDEREADONLY|OFN_EXPLORER;
			ofn.lpstrFilter=filter;
			memcpy(filter,"BASS built-in (*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aif)\0*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aif\0",88);
			{ // look for plugins (in the executable's directory)
				WIN32_FIND_DATA fd;
				HANDLE fh;
				char path[MAX_PATH],*fp=filter+88;
				GetModuleFileName(0,path,sizeof(path));
				strcpy(strrchr(path,'\\')+1,"bass*.dll");
				fh=FindFirstFile(path,&fd);
				if (fh!=INVALID_HANDLE_VALUE) {
					do {
						HPLUGIN plug;
						if (plug=BASS_PluginLoad(fd.cFileName,0)) { // plugin loaded...
							const BASS_PLUGININFO *pinfo=BASS_PluginGetInfo(plug); // get plugin info to add to the file selector filter...
							int a;
							for (a=0;a<pinfo->formatc;a++) {
								fp+=sprintf(fp,"%s (%s) - %s",pinfo->formats[a].name,pinfo->formats[a].exts,fd.cFileName)+1; // format description
								fp+=sprintf(fp,"%s",pinfo->formats[a].exts)+1; // extension filter
							}
							// add plugin to the list
							MESS(20,LB_ADDSTRING,0,fd.cFileName);
						}
					} while (FindNextFile(fh,&fd));
					FindClose(fh);
				}
				if (!MESS(20,LB_GETCOUNT,0,0)) // no plugins...
					MESS(20,LB_ADDSTRING,0,"no plugins - visit the BASS webpage to get some");
				memcpy(fp,"All files\0*.*\0\0",15);
			}
			SetTimer(h,0,500,0); // timer to update the position
			return 1;

		case WM_DESTROY:
			// "free" the output device and all plugins
			BASS_Free();
			BASS_PluginFree(0);
			break;
	}
	return 0;
}
Exemplo n.º 29
0
BOOL CALLBACK dialogproc(HWND h,UINT m,WPARAM w,LPARAM l)
{
	DWORD p;
	float freq;
	char c[30];

	switch (m) {
		case WM_COMMAND:
			switch (LOWORD(w)) {
				case ID_OPEN:
					{
						char file[MAX_PATH]="";
						ofn.lpstrFilter="playable files\0*.mo3;*.xm;*.mod;*.s3m;*.it;*.mtm;*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aif\0All files\0*.*\0\0";
						ofn.lpstrFile=file;
						if (GetOpenFileName(&ofn)) {
							memcpy(path,file,ofn.nFileOffset);
							path[ofn.nFileOffset-1]=0;

							// free decode bpm & stream
							BASS_FX_BPM_Free(hBPM);

							// free tempo, stream, music & bpm/beat callbacks
							BASS_StreamFree(chan);

							// create decode stream channel
							chan=BASS_StreamCreateFile(FALSE, file, 0, 0, BASS_STREAM_DECODE);

							// create decode music channel
							if (!chan) chan = BASS_MusicLoad(FALSE, file, 0, 0, BASS_MUSIC_RAMP|BASS_MUSIC_PRESCAN|BASS_MUSIC_DECODE, 0);

							if (!chan){
								// not a WAV/MP3 or MOD
								MESS(ID_OPEN,WM_SETTEXT,0,"click here to open a file && play it...");
								Error("Selected file couldn't be loaded!");
								break;
							}

							// get current samplerate
							BASS_ChannelGetAttribute(chan, BASS_ATTRIB_FREQ, &freq);

							// update the position slider
							p = (DWORD)BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetLength(chan, BASS_POS_BYTE));
							MESS(IDC_POS,TBM_SETRANGEMAX,0,p);
							MESS(IDC_POS,TBM_SETPOS,TRUE,0);

							// create a new stream - decoded & resampled :)
							if (!(chan=BASS_FX_TempoCreate(chan, BASS_SAMPLE_LOOP|BASS_FX_FREESOURCE))){
								MESS(ID_OPEN,WM_SETTEXT,0,"click here to open a file && play it...");
								Error("Couldn't create a resampled stream!");
								BASS_StreamFree(chan);
								BASS_MusicFree(chan);
								break;
							}

							// update the button to show the loaded file name
							MESS(ID_OPEN,WM_SETTEXT,0,GetFileName(file));

							// set Volume
							p = MESS(IDC_VOL,TBM_GETPOS,0,0);
							BASS_ChannelSetAttribute(chan, BASS_ATTRIB_VOL, (float)(100 - p)/100.0f);

							// update tempo slider & view
							MESS(IDC_TEMPO,TBM_SETPOS,TRUE,0);
							MESS(IDC_STEMPO,WM_SETTEXT,0,"Tempo = 0%");

							// set rate min/max values according to current frequency
							MESS(IDC_RATE,TBM_SETRANGEMAX,0,(long)(freq * 1.3f));
							MESS(IDC_RATE,TBM_SETRANGEMIN,0,(long)(freq * 0.7f));
							MESS(IDC_RATE,TBM_SETPOS,TRUE,(long)freq);
							MESS(IDC_RATE,TBM_SETPAGESIZE,0,(long)(freq * 0.01f));	// by 1%

							sprintf(c,"Samplerate = %dHz", (long)freq);
							MESS(IDC_SRATE,WM_SETTEXT,0,c);

							// update the approximate time in seconds view
							UpdatePositionLabel();

							// play new created stream
							BASS_ChannelPlay(chan,FALSE);

							// set the callback bpm and beat
							SendMessage(win,WM_COMMAND,IDC_CHKPERIOD,l);
							SendMessage(win,WM_COMMAND,IDC_CHKBEAT,l);

							// get the bpm of 30 seconds from the start
							DecodingBPM(TRUE, 0.0f, 30.0f, file);
						}
					}
				return 1;

				case IDC_CHKPERIOD:
					if(MESS(IDC_CHKPERIOD,BM_GETCHECK,0,0)){
						GetDlgItemText(win, IDC_EPBPM, c, 5);
						BASS_FX_BPM_CallbackSet(chan, (BPMPROC*)GetBPM_Callback, (double)atof(c), 0, BASS_FX_BPM_MULT2, 0);
					}else
						BASS_FX_BPM_Free(chan);
				return 1;

				case IDC_CHKBEAT:
					if(MESS(IDC_CHKBEAT,BM_GETCHECK,0,0)){
						BASS_FX_BPM_BeatCallbackSet(chan, (BPMBEATPROC*)GetBeatPos_Callback, 0);
					}else
						BASS_FX_BPM_BeatFree(chan);
				return 1;
			}
			break;

		case WM_VSCROLL:
			if(GetDlgCtrlID((HWND)l) == IDC_VOL)
				BASS_ChannelSetAttribute(chan, BASS_ATTRIB_VOL, (float)(100 - MESS(IDC_VOL,TBM_GETPOS,0,0))/100.0f);
		break;

		case WM_HSCROLL:
			{
				if(!BASS_ChannelIsActive(chan)) break;

				switch (GetDlgCtrlID((HWND)l)) {
					case IDC_TEMPO:
							// set new tempo
							BASS_ChannelSetAttribute(chan, BASS_ATTRIB_TEMPO, (float)MESS(IDC_TEMPO, TBM_GETPOS, 0, 0));

							// update tempo static text
							sprintf(c,"Tempo = %d%%", MESS(IDC_TEMPO, TBM_GETPOS, 0, 0));
							MESS(IDC_STEMPO,WM_SETTEXT,0,c);
					case IDC_RATE:
						{
							// set new samplerate
							BASS_ChannelSetAttribute(chan, BASS_ATTRIB_TEMPO_FREQ, (float)MESS(IDC_RATE, TBM_GETPOS, 0, 0));

							sprintf(c,"Samplerate = %dHz", MESS(IDC_RATE, TBM_GETPOS, 0, 0));
							MESS(IDC_SRATE,WM_SETTEXT,0,c);

							// update the bpm view
							if (MESS(IDC_CHKPERIOD,BM_GETCHECK,0,0))
								sprintf(c,"BPM: %0.2f", GetNewBPM(chan));
							else
								sprintf(c,"BPM: %0.2f", GetNewBPM(hBPM));

							MESS(IDC_SBPM,WM_SETTEXT,0,c);

							// update the approximate time in seconds view
							UpdatePositionLabel();
						}
					break;
					case IDC_POS:
						// change the position
						if (LOWORD(w) == SB_ENDSCROLL) { // seek to new pos
							BASS_ChannelSetPosition(chan, (QWORD)BASS_ChannelSeconds2Bytes(chan, (double)MESS(IDC_POS,TBM_GETPOS,0,0)), BASS_POS_BYTE);

							// get the bpm of last IDC_EPBPM seconds
							GetDlgItemText(win, IDC_EPBPM, c, 5);
							DecodingBPM(FALSE, (double)MESS(IDC_POS,TBM_GETPOS,0,0) - (double)atof(c), (double)MESS(IDC_POS,TBM_GETPOS,0,0),"");
						}
						// update the approximate time in seconds view
						UpdatePositionLabel();
					break;
				}
			}
			return 1;
			break;

		case WM_CLOSE:
			EndDialog(h, 0);
			return 1;
		break;

		case WM_INITDIALOG:
			win=h;
			GetCurrentDirectory(MAX_PATH,path);
			memset(&ofn,0,sizeof(ofn));
			ofn.lStructSize=sizeof(ofn);
			ofn.hwndOwner=h;
			ofn.hInstance=inst;
			ofn.nMaxFile=MAX_PATH;
			ofn.Flags=OFN_HIDEREADONLY|OFN_EXPLORER;

			// setup output - default device, 44100hz, stereo, 16 bits
			if (!BASS_Init(-1,44100,0,win,NULL)) {
				Error("Can't initialize device");
				DestroyWindow(win);
				return 1;
			}
    
			// volume
			MESS(IDC_VOL,TBM_SETRANGEMAX,0,100);
			MESS(IDC_VOL,TBM_SETPOS,TRUE,50);
			MESS(IDC_VOL,TBM_SETPAGESIZE,0,5);

			// tempo
			MESS(IDC_TEMPO,TBM_SETRANGEMAX,TRUE,30);
			MESS(IDC_TEMPO,TBM_SETRANGEMIN,TRUE,-30);
			MESS(IDC_TEMPO,TBM_SETPOS,TRUE,0);
			MESS(IDC_TEMPO,TBM_SETPAGESIZE,0,1);

			// rate
			MESS(IDC_RATE,TBM_SETRANGEMAX,0,(long)(44100.0f * 1.3f));
			MESS(IDC_RATE,TBM_SETRANGEMIN,0,(long)(44100.0f * 0.7f));
			MESS(IDC_RATE,TBM_SETPOS,TRUE,44100);
			MESS(IDC_RATE,TBM_SETPAGESIZE,0,(long)(44100.0f * 0.01f));	// by 1%

			// bpm detection process
			MESS(IDC_PRGRSBPM,PBM_SETRANGE32,0,100);

			// set the bpm period edit box, as a default of 10 seconds :)
			MESS(IDC_EPBPM,WM_SETTEXT,0,"10");

			// set the bpm static text font
			Font = CreateFont(-12,0,0,0,FW_BOLD,FALSE,FALSE,FALSE,ANSI_CHARSET,
			                    OUT_STROKE_PRECIS,CLIP_STROKE_PRECIS,DRAFT_QUALITY,
								DEFAULT_PITCH | FF_DONTCARE,"Tahoma");
			MESS(IDC_SBPM, WM_SETFONT, Font, TRUE);
			MESS(IDC_SBEAT, WM_SETFONT, Font, TRUE);
			return 1;
	}
	return 0;
}
Exemplo n.º 30
0
void __cdecl main(int argc, char **argv)
{
	HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	int running = 1;

#ifdef WIN32
	if (IsDebuggerPresent())
	{
		// turn on floating-point exceptions
		unsigned int prev;
		_clearfp();
		_controlfp_s(&prev, 0, _EM_ZERODIVIDE|_EM_INVALID);
	}
#endif

	// check the correct BASS was loaded
	if (HIWORD(BASS_GetVersion()) != BASSVERSION)
	{
		fprintf(stderr, "An incorrect version of BASS.DLL was loaded");
		return;
	}

	// set the window title
	SetConsoleTitle(TEXT(title_text));

	// set the console buffer size
	static const COORD bufferSize = { 80, 50 };
	SetConsoleScreenBufferSize(hOut, bufferSize);

	// set the console window size
	static const SMALL_RECT windowSize = { 0, 0, 79, 49 };
	SetConsoleWindowInfo(hOut, TRUE, &windowSize);

	// clear the window
	Clear(hOut);

	// hide the cursor
	static const CONSOLE_CURSOR_INFO cursorInfo = { 100, FALSE };
	SetConsoleCursorInfo(hOut, &cursorInfo);

	// set input mode
	SetConsoleMode(hIn, 0);

	// 10ms update period
	const DWORD STREAM_UPDATE_PERIOD = 10;
	BASS_SetConfig(BASS_CONFIG_UPDATEPERIOD, STREAM_UPDATE_PERIOD);

	// initialize BASS sound library
	const DWORD STREAM_FREQUENCY = 48000;
	if (!BASS_Init(-1, STREAM_FREQUENCY, BASS_DEVICE_LATENCY, 0, NULL))
		Error("Can't initialize device");

	// get device info
	BASS_GetInfo(&info);

	// if the device's output rate is unknown default to stream frequency
	if (!info.freq) info.freq = STREAM_FREQUENCY;

	// debug print info
	DebugPrint("frequency: %d (min %d, max %d)\n", info.freq, info.minrate, info.maxrate);
	DebugPrint("device latency: %dms\n", info.latency);
	DebugPrint("device minbuf: %dms\n", info.minbuf);
	DebugPrint("ds version: %d (effects %s)\n", info.dsver, info.dsver < 8 ? "disabled" : "enabled");

	// default buffer size = update period + 'minbuf' + 1ms extra margin
	BASS_SetConfig(BASS_CONFIG_BUFFER, STREAM_UPDATE_PERIOD + info.minbuf + 1);
	DebugPrint("using a %dms buffer\r", BASS_GetConfig(BASS_CONFIG_BUFFER));

	// create a stream, stereo so that effects sound nice
	stream = BASS_StreamCreate(info.freq, 2, BASS_SAMPLE_FLOAT, (STREAMPROC*)WriteStream, 0);

	// set channel to apply effects
	fx_channel = stream;

#ifdef BANDLIMITED_SAWTOOTH
	// initialize bandlimited sawtooth tables
	InitSawtooth();
#endif

	// initialize waves
	InitWave();

	// enable the first oscillator
	osc_config[0].enable = true;

	// reset all controllers
	Control::ResetAll();

	// start playing the audio stream
	BASS_ChannelPlay(stream, FALSE);

	// get the number of midi devices
	UINT midiInDevs = Midi::Input::GetNumDevices();
	DebugPrint("MIDI input devices: %d\n", midiInDevs);

	// print device names
	for (UINT i = 0; i < midiInDevs; ++i)
	{
		MIDIINCAPS midiInCaps;
		if (Midi::Input::GetDeviceCaps(i, midiInCaps) == 0)
		{
			DebugPrint("%d: %s\n", i, midiInCaps.szPname);
		}
	}

	// if there are any devices available...
	if (midiInDevs > 0)
	{
		// open and start midi input
		// TO DO: select device number via a configuration setting
		Midi::Input::Open(0);
		Midi::Input::Start();
	}

	// initialize to middle c
	note_most_recent = 60;
	voice_note[voice_most_recent] = unsigned char(note_most_recent);

	DisplaySpectrumAnalyzer displaySpectrumAnalyzer;
	DisplayKeyVolumeEnvelope displayKeyVolumeEnvelope;
	DisplayOscillatorWaveform displayOscillatorWaveform;
	DisplayOscillatorFrequency displayOscillatorFrequency;
	DisplayLowFrequencyOscillator displayLowFrequencyOscillator;
	DisplayFilterFrequency displayFilterFrequency;

	// initialize spectrum analyzer
	displaySpectrumAnalyzer.Init(stream, info);

	// initialize key display
	displayKeyVolumeEnvelope.Init(hOut);

	// show output scale and key octave
	PrintOutputScale(hOut);
	PrintKeyOctave(hOut);
	PrintGoToEffects(hOut);
	PrintAntialias(hOut);

	// show main page
	Menu::SetActivePage(hOut, Menu::PAGE_MAIN);

	while (running)
	{
		// if there are any pending input events...
		DWORD numEvents = 0;
		while (GetNumberOfConsoleInputEvents(hIn, &numEvents) && numEvents > 0)
		{
			// get the next input event
			INPUT_RECORD keyin;
			ReadConsoleInput(hIn, &keyin, 1, &numEvents);
			if (keyin.EventType == KEY_EVENT)
			{
				// handle interface keys
				if (keyin.Event.KeyEvent.bKeyDown)
				{
					WORD code = keyin.Event.KeyEvent.wVirtualKeyCode;
					DWORD modifiers = keyin.Event.KeyEvent.dwControlKeyState;
					if (code == VK_ESCAPE)
					{
						running = 0;
						break;
					}
					else if (code == VK_OEM_MINUS || code == VK_SUBTRACT)
					{
						Menu::UpdatePercentageProperty(output_scale, -1, modifiers, 0, 4);
						PrintOutputScale(hOut);
					}
					else if (code == VK_OEM_PLUS || code == VK_ADD)
					{
						Menu::UpdatePercentageProperty(output_scale, +1, modifiers, 0, 4);
						PrintOutputScale(hOut);
					}
					else if (code == VK_OEM_4)	// '['
					{
						if (keyboard_octave > 1)
						{
							for (int k = 0; k < KEYS; ++k)
							{
								if (key_down[k])
									NoteOff(k + keyboard_octave * 12);
							}
							--keyboard_octave;
							for (int k = 0; k < KEYS; ++k)
							{
								if (key_down[k])
									NoteOn(k + keyboard_octave * 12);
							}
							PrintKeyOctave(hOut);
						}
					}
					else if (code == VK_OEM_6)	// ']'
					{
						if (keyboard_octave < 9)
						{
							for (int k = 0; k < KEYS; ++k)
							{
								if (key_down[k])
									NoteOff(k + keyboard_octave * 12);
							}
							++keyboard_octave;
							for (int k = 0; k < KEYS; ++k)
							{
								if (key_down[k])
									NoteOn(k + keyboard_octave * 12);
							}
							PrintKeyOctave(hOut);
						}
					}
					else if (code == VK_F12)
					{
						use_antialias = !use_antialias;
						PrintAntialias(hOut);
					}
					else if (code >= VK_F1 && code < VK_F10)
					{
						Menu::SetActiveMenu(hOut, code - VK_F1);
					}
					else if (code == VK_F10)
					{
						PrintGoToEffects(hOut);
						Menu::SetActivePage(hOut, Menu::PAGE_MAIN);
					}
					else if (code == VK_F11)
					{
						PrintGoToMain(hOut);
						Menu::SetActivePage(hOut, Menu::PAGE_FX);
					}
					else if (code == VK_TAB)
					{
						if (modifiers & SHIFT_PRESSED)
							Menu::PrevMenu(hOut);
						else
							Menu::NextMenu(hOut);
					}
					else if (code == VK_UP || code == VK_DOWN || code == VK_RIGHT || code == VK_LEFT)
					{
						Menu::Handler(hOut, code, modifiers);
					}
				}

				// handle note keys
				for (int k = 0; k < KEYS; k++)
				{
					if (keyin.Event.KeyEvent.wVirtualKeyCode == keys[k])
					{
						// key down
						bool down = (keyin.Event.KeyEvent.bKeyDown != 0);

						// if key down state changed...
						if (key_down[k] != down)
						{
							// update state
							key_down[k] = down;

							// if pressing the key
							if (down)
							{
								// note on
								NoteOn(k + keyboard_octave * 12);
							}
							else
							{
								// note off
								NoteOff(k + keyboard_octave * 12);
							}
						}
						break;
					}
				}
			}
		}

		// center frequency of the zeroth semitone band
		// (one octave down from the lowest key)
		float const freq_min = powf(2, float(keyboard_octave - 6)) * middle_c_frequency;

		// update the spectrum analyzer display
		displaySpectrumAnalyzer.Update(hOut, stream, info, freq_min);

		// update note key volume envelope display
		displayKeyVolumeEnvelope.Update(hOut);

		if (Menu::active_page == Menu::PAGE_MAIN)
		{
			// update the oscillator waveform display
			displayOscillatorWaveform.Update(hOut, info, voice_most_recent);

			// update the oscillator frequency displays
			for (int o = 0; o < NUM_OSCILLATORS; ++o)
			{
				if (osc_config[o].enable)
					displayOscillatorFrequency.Update(hOut, voice_most_recent, o);
			}

			// update the low-frequency oscillator display
			displayLowFrequencyOscillator.Update(hOut);

			// update the filter frequency display
			if (flt_config.enable)
				displayFilterFrequency.Update(hOut, voice_most_recent);
		}

		// show CPU usage
		PrintConsole(hOut, { 73, 49 }, "%6.2f%%", BASS_GetCPU());

		// sleep for 1/60th of second
		Sleep(16);
	}

	if (midiInDevs)
	{
		// stop and close midi input
		Midi::Input::Stop();
		Midi::Input::Close();
	}

	// clean up spectrum analyzer
	displaySpectrumAnalyzer.Cleanup(stream);

	// clear the window
	Clear(hOut);

	BASS_Free();
}