From 6a6ef888e1132505da264e395d2c1ca08fffecc5 Mon Sep 17 00:00:00 2001 From: tobigun Date: Wed, 5 Dec 2007 22:51:01 +0000 Subject: - music-visualization support added. - hardcoded to projectm at the moment. - needs a plugin-structure makeover git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@677 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UVisualizer.pas | 201 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 Game/Code/Classes/UVisualizer.pas (limited to 'Game/Code/Classes/UVisualizer.pas') diff --git a/Game/Code/Classes/UVisualizer.pas b/Game/Code/Classes/UVisualizer.pas new file mode 100644 index 00000000..3bea8f54 --- /dev/null +++ b/Game/Code/Classes/UVisualizer.pas @@ -0,0 +1,201 @@ +{############################################################################ +# Visualizer support for UltraStar deluxe # +# # +# Created by hennymcc # +# based on UVideo.pas # +#############################################################################} + +unit UVisualizer; + +interface + +{$IFDEF FPC} + {$MODE DELPHI} +{$ENDIF} + +uses SDL, + UGraphicClasses, + textgl, + math, + OpenGL12, + SysUtils, + UIni, + {$ifdef DebugDisplay} + dialogs, + {$ENDIF} + projectM, + windows; + +procedure Init; +procedure VisualizerStart; +procedure VisualizerStop; +procedure VisualizerGetFrame(Time: Extended); +procedure VisualizerDrawGL(Screen: integer); +procedure VisualizerTogglePause; + +const + VisualWidth = 640; + VisualHeight = 480; + gx = 32; + gy = 24; + fps = 30; + texsize = 512; + +var + pm: PProjectM; + VisualizerStarted, VisualizerPaused: Boolean; + VisualTex: glUint; + pcm_data: TPCM16; + hRC: Integer; + hDC: Integer; + +implementation + +procedure Init; +begin + VisualizerStarted := False; + VisualizerPaused := False; + glGenTextures(1, PglUint(@VisualTex)); + glBindTexture(GL_TEXTURE_2D, VisualTex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +end; + +procedure VisualizerStart; +begin +exit; + VisualizerStarted := True; + + New(pm); + projectM_reset(pm); + + pm^.fullscreen := 0; + pm^.renderTarget^.texsize := texsize; + pm^.gx := gx; + pm^.gy := gy; + pm^.fps := fps; + pm^.renderTarget^.usePbuffers := 0; + + pm^.fontURL := PChar('Visuals\fonts'); + pm^.presetURL := PChar('Visuals\presets'); + + glPushAttrib(GL_ALL_ATTRIB_BITS); + projectM_init(pm); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + projectM_resetGL(pm, VisualWidth, VisualHeight); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glMatrixMode(GL_TEXTURE); + glPopMatrix(); + glPopAttrib(); +end; + +procedure VisualizerStop; +begin + if VisualizerStarted then begin + VisualizerStarted := False; + Dispose(pm); + end; +end; + +procedure VisualizerTogglePause; +begin + if VisualizerPaused then VisualizerPaused:=False + else VisualizerPaused:=True; +end; + +procedure VisualizerGetFrame(Time: Extended); +var + i: integer; +begin + exit; + + if not VisualizerStarted then Exit; + if VisualizerPaused then Exit; + + Randomize(); + + for i := 0 to 511 do + begin + pcm_data[0][i] := RandomRange(High(Smallint), Low(Smallint)); + pcm_data[1][i] := pcm_data[0][i]; + end; + addPCM16(pcm_data); + + glPushAttrib(GL_ALL_ATTRIB_BITS); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + renderFrame(pm); + glFlush(); + { + glBindTexture(GL_TEXTURE_2D, VisualTex); + glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, VisualWidth, VisualHeight, 0); + } + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glMatrixMode(GL_TEXTURE); + glPopMatrix(); + glPopAttrib(); + + glClear(GL_DEPTH_BUFFER_BIT); + + { + glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); + + glEnable(GL_TEXTURE_2D); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glBindTexture(GL_TEXTURE_2D, VisualTex); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2f(-1, -1); + glTexCoord2f(1, 0); glVertex2f( 1, -1); + glTexCoord2f(1, 1); glVertex2f( 1, 1); + glTexCoord2f(0, 1); glVertex2f(-1, 1); + glEnd(); + glDisable(GL_TEXTURE_2D); + } +end; + +procedure VisualizerDrawGL(Screen: integer); +begin +{ + // have a nice black background to draw on (even if there were errors opening the vid) + if Screen=1 then begin + glClearColor(0,0,0,0); + glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); + end; + // exit if there's nothing to draw + if not VisualizerStarted then Exit; + + glEnable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + glColor4f(1, 1, 1, 1); + glBindTexture(GL_TEXTURE_2D, VisualTex); + glbegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2f(400-VisualWidth/2, 300-VisualHeight/2); + glTexCoord2f(0, 1); + glVertex2f(400-VisualWidth/2, 300+VisualHeight/2); + glTexCoord2f(1, 1); + glVertex2f(400+VisualWidth/2, 300+VisualHeight/2); + glTexCoord2f(1, 0); + glVertex2f(400+VisualWidth/2, 300-VisualHeight/2); + glEnd; + glDisable(GL_TEXTURE_2D); + glDisable(GL_BLEND); +} +end; + +end. -- cgit v1.2.3 From 486ad8796acc5883ef83f3a78cd615f6711d77f0 Mon Sep 17 00:00:00 2001 From: jaybinks Date: Thu, 6 Dec 2007 09:39:49 +0000 Subject: conformed projectM to IVideoPlayback still needs a little work. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@678 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UVisualizer.pas | 157 ++++++++++++++++++++++++++++++-------- 1 file changed, 124 insertions(+), 33 deletions(-) (limited to 'Game/Code/Classes/UVisualizer.pas') diff --git a/Game/Code/Classes/UVisualizer.pas b/Game/Code/Classes/UVisualizer.pas index 3bea8f54..1905358f 100644 --- a/Game/Code/Classes/UVisualizer.pas +++ b/Game/Code/Classes/UVisualizer.pas @@ -2,6 +2,7 @@ # Visualizer support for UltraStar deluxe # # # # Created by hennymcc # +# Slight modifications by Jay Binks # # based on UVideo.pas # #############################################################################} @@ -24,46 +25,122 @@ uses SDL, dialogs, {$ENDIF} projectM, + UMusic, windows; -procedure Init; -procedure VisualizerStart; -procedure VisualizerStop; -procedure VisualizerGetFrame(Time: Extended); -procedure VisualizerDrawGL(Screen: integer); -procedure VisualizerTogglePause; +implementation + +var + singleton_VideoProjectM : IVideoPlayback; const - VisualWidth = 640; - VisualHeight = 480; - gx = 32; - gy = 24; - fps = 30; - texsize = 512; + VisualWidth = 800; // 640 + VisualHeight = 600; // 480 + gx = 32; + gy = 24; + fps = 30; + texsize = 512; -var - pm: PProjectM; - VisualizerStarted, VisualizerPaused: Boolean; - VisualTex: glUint; - pcm_data: TPCM16; - hRC: Integer; - hDC: Integer; +type + TVideoPlayback_ProjectM = class( TInterfacedObject, IVideoPlayback ) + + pm : PProjectM; -implementation + VisualizerStarted , + VisualizerPaused : Boolean; -procedure Init; -begin + VisualTex : glUint; + pcm_data : TPCM16; + hRC : Integer; + hDC : Integer; + + procedure VisualizerStart; + procedure VisualizerStop; + + procedure VisualizerTogglePause; + public + constructor create(); + function GetName: String; + + procedure init(); + + function Open( aFileName : string): boolean; // true if succeed + procedure Close; + + procedure Play; + procedure Pause; + procedure Stop; + + procedure MoveTo(Time: real); + function getPosition: real; + + procedure GetFrame(Time: Extended); // WANT TO RENAME THESE TO BE MORE GENERIC + procedure DrawGL(Screen: integer); // WANT TO RENAME THESE TO BE MORE GENERIC + end; + + +constructor TVideoPlayback_ProjectM.create(); +begin +end; + + +procedure TVideoPlayback_ProjectM.init(); +begin + writeln( 'TVideoPlayback_ProjectM - INITIALIZE !!!!!!!!' ); + VisualizerStarted := False; - VisualizerPaused := False; + VisualizerPaused := False; + glGenTextures(1, PglUint(@VisualTex)); glBindTexture(GL_TEXTURE_2D, VisualTex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); end; -procedure VisualizerStart; +function TVideoPlayback_ProjectM.GetName: String; +begin + result := 'ProjectM'; +end; + + +function TVideoPlayback_ProjectM.Open( aFileName : string): boolean; // true if succeed begin -exit; + VisualizerStart(); + result := true; +end; + +procedure TVideoPlayback_ProjectM.Close; +begin +end; + +procedure TVideoPlayback_ProjectM.Play; +begin + VisualizerStart(); +end; + +procedure TVideoPlayback_ProjectM.Pause; +begin + VisualizerTogglePause(); +end; + +procedure TVideoPlayback_ProjectM.Stop; +begin + VisualizerStop(); +end; + +procedure TVideoPlayback_ProjectM.MoveTo(Time: real); +begin +end; + +function TVideoPlayback_ProjectM.getPosition: real; +begin + result := 0; +end; + +procedure TVideoPlayback_ProjectM.VisualizerStart; +begin +//exit; VisualizerStarted := True; New(pm); @@ -76,7 +153,7 @@ exit; pm^.fps := fps; pm^.renderTarget^.usePbuffers := 0; - pm^.fontURL := PChar('Visuals\fonts'); + pm^.fontURL := PChar('Visuals\fonts'); pm^.presetURL := PChar('Visuals\presets'); glPushAttrib(GL_ALL_ATTRIB_BITS); @@ -97,7 +174,7 @@ exit; glPopAttrib(); end; -procedure VisualizerStop; +procedure TVideoPlayback_ProjectM.VisualizerStop; begin if VisualizerStarted then begin VisualizerStarted := False; @@ -105,17 +182,17 @@ begin end; end; -procedure VisualizerTogglePause; +procedure TVideoPlayback_ProjectM.VisualizerTogglePause; begin if VisualizerPaused then VisualizerPaused:=False else VisualizerPaused:=True; end; -procedure VisualizerGetFrame(Time: Extended); +procedure TVideoPlayback_ProjectM.GetFrame(Time: Extended); var i: integer; begin - exit; +// exit; if not VisualizerStarted then Exit; if VisualizerPaused then Exit; @@ -168,9 +245,11 @@ begin } end; -procedure VisualizerDrawGL(Screen: integer); +procedure TVideoPlayback_ProjectM.DrawGL(Screen: integer); begin -{ + + exit; + // have a nice black background to draw on (even if there were errors opening the vid) if Screen=1 then begin glClearColor(0,0,0,0); @@ -195,7 +274,19 @@ begin glEnd; glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); -} + end; + +initialization + singleton_VideoProjectM := TVideoPlayback_ProjectM.create(); + + writeln( 'UVideoProjectM - Register Playback' ); + AudioManager.add( singleton_VideoProjectM ); + +finalization + AudioManager.Remove( singleton_VideoProjectM ); + + + end. -- cgit v1.2.3 From 27ca028ea19879bb3b109c58bae86b61e60b3370 Mon Sep 17 00:00:00 2001 From: tobigun Date: Thu, 6 Dec 2007 10:40:15 +0000 Subject: Visualizer changes (audio connection, some opengl fixes) git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@679 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UVisualizer.pas | 96 +++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 40 deletions(-) (limited to 'Game/Code/Classes/UVisualizer.pas') diff --git a/Game/Code/Classes/UVisualizer.pas b/Game/Code/Classes/UVisualizer.pas index 1905358f..0f2334ba 100644 --- a/Game/Code/Classes/UVisualizer.pas +++ b/Game/Code/Classes/UVisualizer.pas @@ -30,16 +30,19 @@ uses SDL, implementation +uses + UGraphic; + var singleton_VideoProjectM : IVideoPlayback; const - VisualWidth = 800; // 640 - VisualHeight = 600; // 480 gx = 32; gy = 24; fps = 30; texsize = 512; + visuals_Dir = 'Visuals'; // TODO: move this to a place common for all visualizers + projectM_Dir = visuals_Dir+'/projectM'; type TVideoPlayback_ProjectM = class( TInterfacedObject, IVideoPlayback ) @@ -50,7 +53,7 @@ type VisualizerPaused : Boolean; VisualTex : glUint; - pcm_data : TPCM16; + PCMData : TPCMData; hRC : Integer; hDC : Integer; @@ -140,7 +143,6 @@ end; procedure TVideoPlayback_ProjectM.VisualizerStart; begin -//exit; VisualizerStarted := True; New(pm); @@ -153,8 +155,8 @@ begin pm^.fps := fps; pm^.renderTarget^.usePbuffers := 0; - pm^.fontURL := PChar('Visuals\fonts'); - pm^.presetURL := PChar('Visuals\presets'); + pm^.fontURL := PChar(projectM_Dir+'/fonts'); + pm^.presetURL := PChar(projectM_Dir+'/presets'); glPushAttrib(GL_ALL_ATTRIB_BITS); projectM_init(pm); @@ -164,7 +166,9 @@ begin glPushMatrix(); glMatrixMode(GL_TEXTURE); glPushMatrix(); - projectM_resetGL(pm, VisualWidth, VisualHeight); + + projectM_resetGL(pm, ScreenW, ScreenH); + glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); @@ -191,21 +195,16 @@ end; procedure TVideoPlayback_ProjectM.GetFrame(Time: Extended); var i: integer; + nSamples: cardinal; begin -// exit; - if not VisualizerStarted then Exit; if VisualizerPaused then Exit; - Randomize(); - - for i := 0 to 511 do - begin - pcm_data[0][i] := RandomRange(High(Smallint), Low(Smallint)); - pcm_data[1][i] := pcm_data[0][i]; - end; - addPCM16(pcm_data); + // get audio data + nSamples := AudioPlayback.GetPCMData(PcmData); + addPCM16Data(PSmallInt(@PcmData), nSamples); + // store OpenGL state (might be messed up otherwise) glPushAttrib(GL_ALL_ATTRIB_BITS); glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -213,12 +212,17 @@ begin glPushMatrix(); glMatrixMode(GL_TEXTURE); glPushMatrix(); + + // let projectM render a frame renderFrame(pm); glFlush(); - { + + {$IFDEF UseTexture} glBindTexture(GL_TEXTURE_2D, VisualTex); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, VisualWidth, VisualHeight, 0); - } + {$ENDIF} + + // restore USDX OpenGL state glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); @@ -227,41 +231,45 @@ begin glPopMatrix(); glPopAttrib(); + // discard projectM's depth buffer information (avoid overlay) glClear(GL_DEPTH_BUFFER_BIT); - - { - glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); - - glEnable(GL_TEXTURE_2D); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - glBindTexture(GL_TEXTURE_2D, VisualTex); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); glVertex2f(-1, -1); - glTexCoord2f(1, 0); glVertex2f( 1, -1); - glTexCoord2f(1, 1); glVertex2f( 1, 1); - glTexCoord2f(0, 1); glVertex2f(-1, 1); - glEnd(); - glDisable(GL_TEXTURE_2D); - } end; procedure TVideoPlayback_ProjectM.DrawGL(Screen: integer); begin - - exit; - + {$IFDEF UseTexture} // have a nice black background to draw on (even if there were errors opening the vid) if Screen=1 then begin - glClearColor(0,0,0,0); + glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); end; // exit if there's nothing to draw if not VisualizerStarted then Exit; - glEnable(GL_TEXTURE_2D); + // setup display + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluOrtho2D(0, 1, 0, 1); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glEnable(GL_BLEND); - glColor4f(1, 1, 1, 1); + glEnable(GL_TEXTURE_2D); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBindTexture(GL_TEXTURE_2D, VisualTex); + glColor4f(1, 1, 1, 1); + + // draw projectM frame + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2f(0, 0); + glTexCoord2f(1, 0); glVertex2f(1, 0); + glTexCoord2f(1, 1); glVertex2f(1, 1); + glTexCoord2f(0, 1); glVertex2f(0, 1); + glEnd(); + + { glbegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(400-VisualWidth/2, 300-VisualHeight/2); @@ -272,9 +280,17 @@ begin glTexCoord2f(1, 0); glVertex2f(400+VisualWidth/2, 300-VisualHeight/2); glEnd; + } + glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); + // restore state + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + {$ENDIF} end; -- cgit v1.2.3 From 553ee1ad981964a3689e6510d5813dbff0f2119c Mon Sep 17 00:00:00 2001 From: jaybinks Date: Thu, 6 Dec 2007 10:46:53 +0000 Subject: added "V" key to sing screen to start Visualization... git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@681 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UVisualizer.pas | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'Game/Code/Classes/UVisualizer.pas') diff --git a/Game/Code/Classes/UVisualizer.pas b/Game/Code/Classes/UVisualizer.pas index 0f2334ba..6fb5b7a7 100644 --- a/Game/Code/Classes/UVisualizer.pas +++ b/Game/Code/Classes/UVisualizer.pas @@ -63,22 +63,21 @@ type procedure VisualizerTogglePause; public constructor create(); - function GetName: String; + procedure init(); + function GetName: String; - procedure init(); + function Open( aFileName : string): boolean; // true if succeed + procedure Close; - function Open( aFileName : string): boolean; // true if succeed - procedure Close; + procedure Play; + procedure Pause; + procedure Stop; - procedure Play; - procedure Pause; - procedure Stop; + procedure MoveTo(Time: real); + function getPosition: real; - procedure MoveTo(Time: real); - function getPosition: real; - - procedure GetFrame(Time: Extended); // WANT TO RENAME THESE TO BE MORE GENERIC - procedure DrawGL(Screen: integer); // WANT TO RENAME THESE TO BE MORE GENERIC + procedure GetFrame(Time: Extended); + procedure DrawGL(Screen: integer); end; @@ -188,8 +187,7 @@ end; procedure TVideoPlayback_ProjectM.VisualizerTogglePause; begin - if VisualizerPaused then VisualizerPaused:=False - else VisualizerPaused:=True; + VisualizerPaused := not VisualizerPaused; end; procedure TVideoPlayback_ProjectM.GetFrame(Time: Extended); -- cgit v1.2.3 From 886b7205df1355054eda3cb72b65c77ec8a40d73 Mon Sep 17 00:00:00 2001 From: jaybinks Date: Thu, 6 Dec 2007 11:19:36 +0000 Subject: added [tab] to change visualization preset git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@682 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UVisualizer.pas | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'Game/Code/Classes/UVisualizer.pas') diff --git a/Game/Code/Classes/UVisualizer.pas b/Game/Code/Classes/UVisualizer.pas index 6fb5b7a7..08e4b594 100644 --- a/Game/Code/Classes/UVisualizer.pas +++ b/Game/Code/Classes/UVisualizer.pas @@ -133,6 +133,39 @@ end; procedure TVideoPlayback_ProjectM.MoveTo(Time: real); begin + // this code MAY be able to be cut down... but Im not 100% sure.. + // in here, we cant realy move to a specific time, since its all random generated + // but a call to this function will change the preset, which changes the pattern + projectM_reset(pm); + + pm^.fullscreen := 0; + pm^.renderTarget^.texsize := texsize; + pm^.gx := gx; + pm^.gy := gy; + pm^.fps := fps; + pm^.renderTarget^.usePbuffers := 0; + + pm^.fontURL := PChar(projectM_Dir+'/fonts'); + pm^.presetURL := PChar(projectM_Dir+'/presets'); + + glPushAttrib(GL_ALL_ATTRIB_BITS); + projectM_init(pm); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + + projectM_resetGL(pm, ScreenW, ScreenH); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glMatrixMode(GL_TEXTURE); + glPopMatrix(); + glPopAttrib(); + end; function TVideoPlayback_ProjectM.getPosition: real; -- cgit v1.2.3 From be68ff31e2d10d5f29894c6ec4ed877c70c142a3 Mon Sep 17 00:00:00 2001 From: jaybinks Date: Thu, 6 Dec 2007 12:26:05 +0000 Subject: gave priority to videos over Visualization... so now video plays back... and "V" will switch between Video ( or jpg ) background and visualization. this needs to be pressed on every song, as the state should be forgotten. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@687 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UVisualizer.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Game/Code/Classes/UVisualizer.pas') diff --git a/Game/Code/Classes/UVisualizer.pas b/Game/Code/Classes/UVisualizer.pas index 08e4b594..b6b3a1cc 100644 --- a/Game/Code/Classes/UVisualizer.pas +++ b/Game/Code/Classes/UVisualizer.pas @@ -45,7 +45,7 @@ const projectM_Dir = visuals_Dir+'/projectM'; type - TVideoPlayback_ProjectM = class( TInterfacedObject, IVideoPlayback ) + TVideoPlayback_ProjectM = class( TInterfacedObject, IVideoPlayback, IVideoVisualization ) pm : PProjectM; -- cgit v1.2.3 From 73a9bf99b8993aa69f3ed77b36b0236fb1cde2ed Mon Sep 17 00:00:00 2001 From: jaybinks Date: Thu, 6 Dec 2007 23:53:46 +0000 Subject: trying to get projectM to run in linux git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@692 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UVisualizer.pas | 540 +++++++++++++++++++------------------- 1 file changed, 275 insertions(+), 265 deletions(-) (limited to 'Game/Code/Classes/UVisualizer.pas') diff --git a/Game/Code/Classes/UVisualizer.pas b/Game/Code/Classes/UVisualizer.pas index b6b3a1cc..a49187e7 100644 --- a/Game/Code/Classes/UVisualizer.pas +++ b/Game/Code/Classes/UVisualizer.pas @@ -1,66 +1,65 @@ -{############################################################################ -# Visualizer support for UltraStar deluxe # -# # -# Created by hennymcc # -# Slight modifications by Jay Binks # -# based on UVideo.pas # -#############################################################################} - -unit UVisualizer; - -interface - -{$IFDEF FPC} - {$MODE DELPHI} -{$ENDIF} - -uses SDL, - UGraphicClasses, - textgl, - math, - OpenGL12, - SysUtils, - UIni, - {$ifdef DebugDisplay} - dialogs, - {$ENDIF} - projectM, - UMusic, - windows; - -implementation - -uses - UGraphic; - -var +{############################################################################ +# Visualizer support for UltraStar deluxe # +# # +# Created by hennymcc # +# Slight modifications by Jay Binks # +# based on UVideo.pas # +#############################################################################} + +unit UVisualizer; + +interface + +{$IFDEF FPC} + {$MODE DELPHI} +{$ENDIF} + +uses SDL, + UGraphicClasses, + textgl, + math, + OpenGL12, + SysUtils, + UIni, + {$ifdef DebugDisplay} + dialogs, + {$ENDIF} + projectM, + UMusic; + +implementation + +uses + UGraphic; + +var singleton_VideoProjectM : IVideoPlayback; - -const - gx = 32; - gy = 24; - fps = 30; - texsize = 512; - visuals_Dir = 'Visuals'; // TODO: move this to a place common for all visualizers - projectM_Dir = visuals_Dir+'/projectM'; - -type - TVideoPlayback_ProjectM = class( TInterfacedObject, IVideoPlayback, IVideoVisualization ) + +const + gx = 32; + gy = 24; + fps = 30; + texsize = 512; + visuals_Dir = 'Visuals'; // TODO: move this to a place common for all visualizers + projectM_Dir = visuals_Dir+'/projectM'; + +type + TVideoPlayback_ProjectM = class( TInterfacedObject, IVideoPlayback, IVideoVisualization ) pm : PProjectM; - - VisualizerStarted , - VisualizerPaused : Boolean; - - VisualTex : glUint; - PCMData : TPCMData; - hRC : Integer; - hDC : Integer; + + VisualizerStarted , + VisualizerPaused : Boolean; + + VisualTex : glUint; + PCMData : TPCMData; + hRC : Integer; + hDC : Integer; procedure VisualizerStart; procedure VisualizerStop; - - procedure VisualizerTogglePause; + + procedure VisualizerTogglePause; public constructor create(); procedure init(); @@ -79,40 +78,44 @@ type procedure GetFrame(Time: Extended); procedure DrawGL(Screen: integer); end; - - -constructor TVideoPlayback_ProjectM.create(); + + +constructor TVideoPlayback_ProjectM.create(); begin end; - - -procedure TVideoPlayback_ProjectM.init(); + + +procedure TVideoPlayback_ProjectM.init(); begin writeln( 'TVideoPlayback_ProjectM - INITIALIZE !!!!!!!!' ); - VisualizerStarted := False; - VisualizerPaused := False; - - glGenTextures(1, PglUint(@VisualTex)); - glBindTexture(GL_TEXTURE_2D, VisualTex); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); -end; - -function TVideoPlayback_ProjectM.GetName: String; + VisualizerStarted := False; + VisualizerPaused := False; + + glGenTextures(1, PglUint(@VisualTex)); + glBindTexture(GL_TEXTURE_2D, VisualTex); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + New(pm); + projectM_reset(pm); + +end; + +function TVideoPlayback_ProjectM.GetName: String; begin result := 'ProjectM'; end; - - -function TVideoPlayback_ProjectM.Open( aFileName : string): boolean; // true if succeed -begin - VisualizerStart(); - result := true; -end; - -procedure TVideoPlayback_ProjectM.Close; + + +function TVideoPlayback_ProjectM.Open( aFileName : string): boolean; // true if succeed +begin + VisualizerStart(); + result := true; +end; + +procedure TVideoPlayback_ProjectM.Close; begin end; @@ -137,33 +140,33 @@ begin // in here, we cant realy move to a specific time, since its all random generated // but a call to this function will change the preset, which changes the pattern projectM_reset(pm); - - pm^.fullscreen := 0; - pm^.renderTarget^.texsize := texsize; - pm^.gx := gx; - pm^.gy := gy; - pm^.fps := fps; - pm^.renderTarget^.usePbuffers := 0; - - pm^.fontURL := PChar(projectM_Dir+'/fonts'); - pm^.presetURL := PChar(projectM_Dir+'/presets'); - - glPushAttrib(GL_ALL_ATTRIB_BITS); - projectM_init(pm); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glMatrixMode(GL_TEXTURE); - glPushMatrix(); - - projectM_resetGL(pm, ScreenW, ScreenH); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - glMatrixMode(GL_TEXTURE); - glPopMatrix(); + + pm^.fullscreen := 0; + pm^.renderTarget^.texsize := texsize; + pm^.gx := gx; + pm^.gy := gy; + pm^.fps := fps; + pm^.renderTarget^.usePbuffers := 0; + + pm^.fontURL := PChar(projectM_Dir+'/fonts'); + pm^.presetURL := PChar(projectM_Dir+'/presets'); + + glPushAttrib(GL_ALL_ATTRIB_BITS); + projectM_init(pm); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + + projectM_resetGL(pm, ScreenW, ScreenH); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glMatrixMode(GL_TEXTURE); + glPopMatrix(); glPopAttrib(); end; @@ -173,158 +176,165 @@ begin result := 0; end; -procedure TVideoPlayback_ProjectM.VisualizerStart; -begin - VisualizerStarted := True; - - New(pm); - projectM_reset(pm); - - pm^.fullscreen := 0; - pm^.renderTarget^.texsize := texsize; - pm^.gx := gx; - pm^.gy := gy; - pm^.fps := fps; - pm^.renderTarget^.usePbuffers := 0; - - pm^.fontURL := PChar(projectM_Dir+'/fonts'); - pm^.presetURL := PChar(projectM_Dir+'/presets'); - - glPushAttrib(GL_ALL_ATTRIB_BITS); - projectM_init(pm); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glMatrixMode(GL_TEXTURE); - glPushMatrix(); - - projectM_resetGL(pm, ScreenW, ScreenH); - - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - glMatrixMode(GL_TEXTURE); - glPopMatrix(); - glPopAttrib(); -end; - -procedure TVideoPlayback_ProjectM.VisualizerStop; -begin - if VisualizerStarted then begin - VisualizerStarted := False; - Dispose(pm); - end; -end; - -procedure TVideoPlayback_ProjectM.VisualizerTogglePause; -begin - VisualizerPaused := not VisualizerPaused; -end; - -procedure TVideoPlayback_ProjectM.GetFrame(Time: Extended); -var - i: integer; - nSamples: cardinal; -begin - if not VisualizerStarted then Exit; - if VisualizerPaused then Exit; - - // get audio data - nSamples := AudioPlayback.GetPCMData(PcmData); - addPCM16Data(PSmallInt(@PcmData), nSamples); - - // store OpenGL state (might be messed up otherwise) - glPushAttrib(GL_ALL_ATTRIB_BITS); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glMatrixMode(GL_TEXTURE); - glPushMatrix(); - - // let projectM render a frame - renderFrame(pm); - glFlush(); - - {$IFDEF UseTexture} - glBindTexture(GL_TEXTURE_2D, VisualTex); - glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, VisualWidth, VisualHeight, 0); - {$ENDIF} - - // restore USDX OpenGL state - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - glMatrixMode(GL_TEXTURE); - glPopMatrix(); - glPopAttrib(); - - // discard projectM's depth buffer information (avoid overlay) - glClear(GL_DEPTH_BUFFER_BIT); -end; - -procedure TVideoPlayback_ProjectM.DrawGL(Screen: integer); -begin - {$IFDEF UseTexture} - // have a nice black background to draw on (even if there were errors opening the vid) - if Screen=1 then begin - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); - end; - // exit if there's nothing to draw - if not VisualizerStarted then Exit; - - // setup display - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - gluOrtho2D(0, 1, 0, 1); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - glEnable(GL_BLEND); - glEnable(GL_TEXTURE_2D); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - glBindTexture(GL_TEXTURE_2D, VisualTex); - glColor4f(1, 1, 1, 1); - - // draw projectM frame - glBegin(GL_QUADS); - glTexCoord2f(0, 0); glVertex2f(0, 0); - glTexCoord2f(1, 0); glVertex2f(1, 0); - glTexCoord2f(1, 1); glVertex2f(1, 1); - glTexCoord2f(0, 1); glVertex2f(0, 1); - glEnd(); - - { - glbegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2f(400-VisualWidth/2, 300-VisualHeight/2); - glTexCoord2f(0, 1); - glVertex2f(400-VisualWidth/2, 300+VisualHeight/2); - glTexCoord2f(1, 1); - glVertex2f(400+VisualWidth/2, 300+VisualHeight/2); - glTexCoord2f(1, 0); - glVertex2f(400+VisualWidth/2, 300-VisualHeight/2); - glEnd; - } - - glDisable(GL_TEXTURE_2D); - glDisable(GL_BLEND); - - // restore state - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - {$ENDIF} -end; - - +procedure TVideoPlayback_ProjectM.VisualizerStart; +begin + VisualizerStarted := True; + +// New(pm); +// projectM_reset(pm); + + writeln('Render Target'); + writeln( inttostr( integer( assigned(pm^.renderTarget) ) ) ); + + pm^.fullscreen := 0; + pm^.gx := gx; + pm^.gy := gy; + pm^.fps := fps; + + if assigned(pm^.renderTarget) then + begin + pm^.renderTarget^.texsize := texsize; + pm^.renderTarget^.usePbuffers := 0; + end; + + pm^.fontURL := PChar(projectM_Dir+'/fonts'); + pm^.presetURL := PChar(projectM_Dir+'/presets'); + + glPushAttrib(GL_ALL_ATTRIB_BITS); + projectM_init(pm); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + + projectM_resetGL(pm, ScreenW, ScreenH); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glMatrixMode(GL_TEXTURE); + glPopMatrix(); + glPopAttrib(); +end; + +procedure TVideoPlayback_ProjectM.VisualizerStop; +begin + if VisualizerStarted then begin + VisualizerStarted := False; + Dispose(pm); + end; +end; + +procedure TVideoPlayback_ProjectM.VisualizerTogglePause; +begin + VisualizerPaused := not VisualizerPaused; +end; + +procedure TVideoPlayback_ProjectM.GetFrame(Time: Extended); +var + i: integer; + nSamples: cardinal; +begin + if not VisualizerStarted then Exit; + if VisualizerPaused then Exit; + + // get audio data + nSamples := AudioPlayback.GetPCMData(PcmData); + addPCM16Data(PSmallInt(@PcmData), nSamples); + + // store OpenGL state (might be messed up otherwise) + glPushAttrib(GL_ALL_ATTRIB_BITS); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + + // let projectM render a frame + renderFrame(pm); + glFlush(); + + {$IFDEF UseTexture} + glBindTexture(GL_TEXTURE_2D, VisualTex); + glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, VisualWidth, VisualHeight, 0); + {$ENDIF} + + // restore USDX OpenGL state + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glMatrixMode(GL_TEXTURE); + glPopMatrix(); + glPopAttrib(); + + // discard projectM's depth buffer information (avoid overlay) + glClear(GL_DEPTH_BUFFER_BIT); +end; + +procedure TVideoPlayback_ProjectM.DrawGL(Screen: integer); +begin + {$IFDEF UseTexture} + // have a nice black background to draw on (even if there were errors opening the vid) + if Screen=1 then begin + glClearColor(0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); + end; + // exit if there's nothing to draw + if not VisualizerStarted then Exit; + + // setup display + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluOrtho2D(0, 1, 0, 1); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glEnable(GL_BLEND); + glEnable(GL_TEXTURE_2D); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glBindTexture(GL_TEXTURE_2D, VisualTex); + glColor4f(1, 1, 1, 1); + + // draw projectM frame + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2f(0, 0); + glTexCoord2f(1, 0); glVertex2f(1, 0); + glTexCoord2f(1, 1); glVertex2f(1, 1); + glTexCoord2f(0, 1); glVertex2f(0, 1); + glEnd(); + + { + glbegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2f(400-VisualWidth/2, 300-VisualHeight/2); + glTexCoord2f(0, 1); + glVertex2f(400-VisualWidth/2, 300+VisualHeight/2); + glTexCoord2f(1, 1); + glVertex2f(400+VisualWidth/2, 300+VisualHeight/2); + glTexCoord2f(1, 0); + glVertex2f(400+VisualWidth/2, 300-VisualHeight/2); + glEnd; + } + + glDisable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + + // restore state + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + {$ENDIF} +end; + + initialization singleton_VideoProjectM := TVideoPlayback_ProjectM.create(); @@ -334,6 +344,6 @@ initialization finalization AudioManager.Remove( singleton_VideoProjectM ); - - -end. + + +end. -- cgit v1.2.3 From 842af29c79390c0f78c2f004b463fe555ab01430 Mon Sep 17 00:00:00 2001 From: jaybinks Date: Fri, 7 Dec 2007 00:37:39 +0000 Subject: oops didnt mean to commit that. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@693 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UVisualizer.pas | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'Game/Code/Classes/UVisualizer.pas') diff --git a/Game/Code/Classes/UVisualizer.pas b/Game/Code/Classes/UVisualizer.pas index a49187e7..fc5eacbf 100644 --- a/Game/Code/Classes/UVisualizer.pas +++ b/Game/Code/Classes/UVisualizer.pas @@ -98,9 +98,6 @@ begin glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - New(pm); - projectM_reset(pm); - end; function TVideoPlayback_ProjectM.GetName: String; @@ -180,8 +177,8 @@ procedure TVideoPlayback_ProjectM.VisualizerStart; begin VisualizerStarted := True; -// New(pm); -// projectM_reset(pm); + New(pm); + projectM_reset(pm); writeln('Render Target'); writeln( inttostr( integer( assigned(pm^.renderTarget) ) ) ); -- cgit v1.2.3 From 2e41ddbf9dc84772cdc9c8a9ab80d4861d6e4177 Mon Sep 17 00:00:00 2001 From: tobigun Date: Fri, 7 Dec 2007 02:32:44 +0000 Subject: Fixed some linux visualizer errors git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@694 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UVisualizer.pas | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'Game/Code/Classes/UVisualizer.pas') diff --git a/Game/Code/Classes/UVisualizer.pas b/Game/Code/Classes/UVisualizer.pas index fc5eacbf..fa737d81 100644 --- a/Game/Code/Classes/UVisualizer.pas +++ b/Game/Code/Classes/UVisualizer.pas @@ -97,7 +97,6 @@ begin glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - end; function TVideoPlayback_ProjectM.GetName: String; @@ -180,19 +179,12 @@ begin New(pm); projectM_reset(pm); - writeln('Render Target'); - writeln( inttostr( integer( assigned(pm^.renderTarget) ) ) ); - pm^.fullscreen := 0; - pm^.gx := gx; - pm^.gy := gy; + pm^.renderTarget^.texsize := texsize; + pm^.gx := gx; + pm^.gy := gy; pm^.fps := fps; - - if assigned(pm^.renderTarget) then - begin - pm^.renderTarget^.texsize := texsize; - pm^.renderTarget^.usePbuffers := 0; - end; + pm^.renderTarget^.usePbuffers := 0; pm^.fontURL := PChar(projectM_Dir+'/fonts'); pm^.presetURL := PChar(projectM_Dir+'/presets'); @@ -240,7 +232,7 @@ begin // get audio data nSamples := AudioPlayback.GetPCMData(PcmData); - addPCM16Data(PSmallInt(@PcmData), nSamples); + addPCM16Data(PPCM16Data(@PcmData), nSamples); // store OpenGL state (might be messed up otherwise) glPushAttrib(GL_ALL_ATTRIB_BITS); -- cgit v1.2.3 From 425ff834dbc3933475ee8f783eea6167e92ec174 Mon Sep 17 00:00:00 2001 From: jaybinks Date: Fri, 7 Dec 2007 04:32:38 +0000 Subject: little bit of tidy up.. added command line switch, to see what media interfaces are being used. moved RandomPCM Data generation to Visualizer class. added Visualization preset change, on new line ( may be a little to much... maybe we should do ever 4 or 16 bars or something ?) git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@697 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UVisualizer.pas | 55 +++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 5 deletions(-) (limited to 'Game/Code/Classes/UVisualizer.pas') diff --git a/Game/Code/Classes/UVisualizer.pas b/Game/Code/Classes/UVisualizer.pas index fa737d81..6548e2b7 100644 --- a/Game/Code/Classes/UVisualizer.pas +++ b/Game/Code/Classes/UVisualizer.pas @@ -56,10 +56,14 @@ type hRC : Integer; hDC : Integer; + RndPCMcount : integer; + procedure VisualizerStart; procedure VisualizerStop; procedure VisualizerTogglePause; + + function GetRandomPCMData(var data: TPCMData): Cardinal; public constructor create(); procedure init(); @@ -82,13 +86,12 @@ type constructor TVideoPlayback_ProjectM.create(); begin + RndPCMcount := 0; end; procedure TVideoPlayback_ProjectM.init(); begin - writeln( 'TVideoPlayback_ProjectM - INITIALIZE !!!!!!!!' ); - VisualizerStarted := False; VisualizerPaused := False; @@ -232,6 +235,10 @@ begin // get audio data nSamples := AudioPlayback.GetPCMData(PcmData); + + if nSamples = 0 then + nSamples := GetRandomPCMData(PcmData); + addPCM16Data(PPCM16Data(@PcmData), nSamples); // store OpenGL state (might be messed up otherwise) @@ -244,7 +251,15 @@ begin glPushMatrix(); // let projectM render a frame - renderFrame(pm); + try + renderFrame(pm); + except + // This happens with some presets... ( and only some times also .. moreso on linux ) + // if we have an "Invalid Floating Point Error" while rendering a frame... then change preset. + MoveTo( now ); + + // hmm have to be careful, that we dont get to many here... coz it could keep failing.. and trying again. + end; glFlush(); {$IFDEF UseTexture} @@ -323,11 +338,41 @@ begin {$ENDIF} end; +function TVideoPlayback_ProjectM.GetRandomPCMData(var data: TPCMData): Cardinal; +var + i: integer; +begin + // Produce some fake PCM data + if ( RndPCMcount mod 500 = 0 ) then + begin + for i := 0 to 511 do begin + data[0][i] := 0; + data[1][i] := 0; + end; + end + else begin + for i := 0 to 511 do begin + if ( i mod 2 = 0 ) then begin + data[0][i] := floor(Random * power(2.,14)); + data[1][i] := floor(Random * power(2.,14)); + end + else begin; + data[0][i] := floor(Random * power(2.,14)); + data[1][i] := floor(Random * power(2.,14)); + end; + if ( i mod 2 = 1 ) then begin + data[0][i] := -data[0][i]; + data[1][i] := -data[1][i]; + end; + end; + end; + Inc( RndPCMcount ); + result := 512; +end; + initialization singleton_VideoProjectM := TVideoPlayback_ProjectM.create(); - - writeln( 'UVideoProjectM - Register Playback' ); AudioManager.add( singleton_VideoProjectM ); finalization -- cgit v1.2.3 From 65cd744909a51e2c9adcfbd3bbbeee096b35b111 Mon Sep 17 00:00:00 2001 From: tobigun Date: Mon, 17 Dec 2007 16:40:13 +0000 Subject: - faster preset switching - added projectM 1.0 support git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@715 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UVisualizer.pas | 761 +++++++++++++++++++------------------- 1 file changed, 378 insertions(+), 383 deletions(-) (limited to 'Game/Code/Classes/UVisualizer.pas') diff --git a/Game/Code/Classes/UVisualizer.pas b/Game/Code/Classes/UVisualizer.pas index 6548e2b7..5fc4bb82 100644 --- a/Game/Code/Classes/UVisualizer.pas +++ b/Game/Code/Classes/UVisualizer.pas @@ -1,383 +1,378 @@ -{############################################################################ -# Visualizer support for UltraStar deluxe # -# # -# Created by hennymcc # -# Slight modifications by Jay Binks # -# based on UVideo.pas # -#############################################################################} - -unit UVisualizer; - -interface - -{$IFDEF FPC} - {$MODE DELPHI} -{$ENDIF} - -uses SDL, - UGraphicClasses, - textgl, - math, - OpenGL12, - SysUtils, - UIni, - {$ifdef DebugDisplay} - dialogs, - {$ENDIF} - projectM, - UMusic; - -implementation - -uses - UGraphic; - -var - singleton_VideoProjectM : IVideoPlayback; - -const - gx = 32; - gy = 24; - fps = 30; - texsize = 512; - visuals_Dir = 'Visuals'; // TODO: move this to a place common for all visualizers - projectM_Dir = visuals_Dir+'/projectM'; - -type - TVideoPlayback_ProjectM = class( TInterfacedObject, IVideoPlayback, IVideoVisualization ) - - pm : PProjectM; - - VisualizerStarted , - VisualizerPaused : Boolean; - - VisualTex : glUint; - PCMData : TPCMData; - hRC : Integer; - hDC : Integer; - - RndPCMcount : integer; - - procedure VisualizerStart; - procedure VisualizerStop; - - procedure VisualizerTogglePause; - - function GetRandomPCMData(var data: TPCMData): Cardinal; - public - constructor create(); - procedure init(); - function GetName: String; - - function Open( aFileName : string): boolean; // true if succeed - procedure Close; - - procedure Play; - procedure Pause; - procedure Stop; - - procedure MoveTo(Time: real); - function getPosition: real; - - procedure GetFrame(Time: Extended); - procedure DrawGL(Screen: integer); - end; - - -constructor TVideoPlayback_ProjectM.create(); -begin - RndPCMcount := 0; -end; - - -procedure TVideoPlayback_ProjectM.init(); -begin - VisualizerStarted := False; - VisualizerPaused := False; - - glGenTextures(1, PglUint(@VisualTex)); - glBindTexture(GL_TEXTURE_2D, VisualTex); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); -end; - -function TVideoPlayback_ProjectM.GetName: String; -begin - result := 'ProjectM'; -end; - - -function TVideoPlayback_ProjectM.Open( aFileName : string): boolean; // true if succeed -begin - VisualizerStart(); - result := true; -end; - -procedure TVideoPlayback_ProjectM.Close; -begin -end; - -procedure TVideoPlayback_ProjectM.Play; -begin - VisualizerStart(); -end; - -procedure TVideoPlayback_ProjectM.Pause; -begin - VisualizerTogglePause(); -end; - -procedure TVideoPlayback_ProjectM.Stop; -begin - VisualizerStop(); -end; - -procedure TVideoPlayback_ProjectM.MoveTo(Time: real); -begin - // this code MAY be able to be cut down... but Im not 100% sure.. - // in here, we cant realy move to a specific time, since its all random generated - // but a call to this function will change the preset, which changes the pattern - projectM_reset(pm); - - pm^.fullscreen := 0; - pm^.renderTarget^.texsize := texsize; - pm^.gx := gx; - pm^.gy := gy; - pm^.fps := fps; - pm^.renderTarget^.usePbuffers := 0; - - pm^.fontURL := PChar(projectM_Dir+'/fonts'); - pm^.presetURL := PChar(projectM_Dir+'/presets'); - - glPushAttrib(GL_ALL_ATTRIB_BITS); - projectM_init(pm); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glMatrixMode(GL_TEXTURE); - glPushMatrix(); - - projectM_resetGL(pm, ScreenW, ScreenH); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - glMatrixMode(GL_TEXTURE); - glPopMatrix(); - glPopAttrib(); - -end; - -function TVideoPlayback_ProjectM.getPosition: real; -begin - result := 0; -end; - -procedure TVideoPlayback_ProjectM.VisualizerStart; -begin - VisualizerStarted := True; - - New(pm); - projectM_reset(pm); - - pm^.fullscreen := 0; - pm^.renderTarget^.texsize := texsize; - pm^.gx := gx; - pm^.gy := gy; - pm^.fps := fps; - pm^.renderTarget^.usePbuffers := 0; - - pm^.fontURL := PChar(projectM_Dir+'/fonts'); - pm^.presetURL := PChar(projectM_Dir+'/presets'); - - glPushAttrib(GL_ALL_ATTRIB_BITS); - projectM_init(pm); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glMatrixMode(GL_TEXTURE); - glPushMatrix(); - - projectM_resetGL(pm, ScreenW, ScreenH); - - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - glMatrixMode(GL_TEXTURE); - glPopMatrix(); - glPopAttrib(); -end; - -procedure TVideoPlayback_ProjectM.VisualizerStop; -begin - if VisualizerStarted then begin - VisualizerStarted := False; - Dispose(pm); - end; -end; - -procedure TVideoPlayback_ProjectM.VisualizerTogglePause; -begin - VisualizerPaused := not VisualizerPaused; -end; - -procedure TVideoPlayback_ProjectM.GetFrame(Time: Extended); -var - i: integer; - nSamples: cardinal; -begin - if not VisualizerStarted then Exit; - if VisualizerPaused then Exit; - - // get audio data - nSamples := AudioPlayback.GetPCMData(PcmData); - - if nSamples = 0 then - nSamples := GetRandomPCMData(PcmData); - - addPCM16Data(PPCM16Data(@PcmData), nSamples); - - // store OpenGL state (might be messed up otherwise) - glPushAttrib(GL_ALL_ATTRIB_BITS); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glMatrixMode(GL_TEXTURE); - glPushMatrix(); - - // let projectM render a frame - try - renderFrame(pm); - except - // This happens with some presets... ( and only some times also .. moreso on linux ) - // if we have an "Invalid Floating Point Error" while rendering a frame... then change preset. - MoveTo( now ); - - // hmm have to be careful, that we dont get to many here... coz it could keep failing.. and trying again. - end; - glFlush(); - - {$IFDEF UseTexture} - glBindTexture(GL_TEXTURE_2D, VisualTex); - glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, VisualWidth, VisualHeight, 0); - {$ENDIF} - - // restore USDX OpenGL state - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - glMatrixMode(GL_TEXTURE); - glPopMatrix(); - glPopAttrib(); - - // discard projectM's depth buffer information (avoid overlay) - glClear(GL_DEPTH_BUFFER_BIT); -end; - -procedure TVideoPlayback_ProjectM.DrawGL(Screen: integer); -begin - {$IFDEF UseTexture} - // have a nice black background to draw on (even if there were errors opening the vid) - if Screen=1 then begin - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); - end; - // exit if there's nothing to draw - if not VisualizerStarted then Exit; - - // setup display - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - gluOrtho2D(0, 1, 0, 1); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - glEnable(GL_BLEND); - glEnable(GL_TEXTURE_2D); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - glBindTexture(GL_TEXTURE_2D, VisualTex); - glColor4f(1, 1, 1, 1); - - // draw projectM frame - glBegin(GL_QUADS); - glTexCoord2f(0, 0); glVertex2f(0, 0); - glTexCoord2f(1, 0); glVertex2f(1, 0); - glTexCoord2f(1, 1); glVertex2f(1, 1); - glTexCoord2f(0, 1); glVertex2f(0, 1); - glEnd(); - - { - glbegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2f(400-VisualWidth/2, 300-VisualHeight/2); - glTexCoord2f(0, 1); - glVertex2f(400-VisualWidth/2, 300+VisualHeight/2); - glTexCoord2f(1, 1); - glVertex2f(400+VisualWidth/2, 300+VisualHeight/2); - glTexCoord2f(1, 0); - glVertex2f(400+VisualWidth/2, 300-VisualHeight/2); - glEnd; - } - - glDisable(GL_TEXTURE_2D); - glDisable(GL_BLEND); - - // restore state - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - {$ENDIF} -end; - -function TVideoPlayback_ProjectM.GetRandomPCMData(var data: TPCMData): Cardinal; -var - i: integer; -begin - // Produce some fake PCM data - if ( RndPCMcount mod 500 = 0 ) then - begin - for i := 0 to 511 do begin - data[0][i] := 0; - data[1][i] := 0; - end; - end - else begin - for i := 0 to 511 do begin - if ( i mod 2 = 0 ) then begin - data[0][i] := floor(Random * power(2.,14)); - data[1][i] := floor(Random * power(2.,14)); - end - else begin; - data[0][i] := floor(Random * power(2.,14)); - data[1][i] := floor(Random * power(2.,14)); - end; - if ( i mod 2 = 1 ) then begin - data[0][i] := -data[0][i]; - data[1][i] := -data[1][i]; - end; - end; - end; - Inc( RndPCMcount ); - result := 512; -end; - - -initialization - singleton_VideoProjectM := TVideoPlayback_ProjectM.create(); - AudioManager.add( singleton_VideoProjectM ); - -finalization - AudioManager.Remove( singleton_VideoProjectM ); - - - -end. +{############################################################################ +# Visualizer support for UltraStar deluxe # +# # +# Created by hennymcc # +# Slight modifications by Jay Binks # +# based on UVideo.pas # +#############################################################################} + +unit UVisualizer; + +interface + +{$IFDEF FPC} + {$MODE DELPHI} +{$ENDIF} + +{$I switches.inc} + +uses + SDL, + UGraphicClasses, + textgl, + math, + OpenGL12, + SysUtils, + UIni, + {$ifdef DebugDisplay} + {$ifdef win32} + dialogs, + {$endif} + {$endif} + projectM, + UMusic; + +implementation + +uses + UGraphic, + ULog; + +var + singleton_VideoProjectM : IVideoPlayback; + +const + gx = 32; + gy = 24; + fps = 30; + texsize = 512; + visualsDir = 'Visuals'; // TODO: move this to a place common for all visualizers + projectMDir = visualsDir+'/projectM'; + presetsDir = projectMDir+'/presets'; + fontsDir = projectMDir+'/fonts'; + +type + TVideoPlayback_ProjectM = class( TInterfacedObject, IVideoPlayback, IVideoVisualization ) + private + pm : TProjectM; + + VisualizerStarted , + VisualizerPaused : Boolean; + + VisualTex : glUint; + PCMData : TPCMData; + hRC : Integer; + hDC : Integer; + + RndPCMcount : integer; + + projMatrix: array[0..3, 0..3] of GLdouble; + texMatrix: array[0..3, 0..3] of GLdouble; + + procedure VisualizerStart; + procedure VisualizerStop; + + procedure VisualizerTogglePause; + + function GetRandomPCMData(var data: TPCMData): Cardinal; + + procedure SaveOpenGLState(); + procedure RestoreOpenGLState(); + + public + constructor create(); + procedure init(); + function GetName: String; + + function Open( aFileName : string): boolean; // true if succeed + procedure Close; + + procedure Play; + procedure Pause; + procedure Stop; + + procedure MoveTo(Time: real); + function getPosition: real; + + procedure GetFrame(Time: Extended); + procedure DrawGL(Screen: integer); + end; + + +constructor TVideoPlayback_ProjectM.create(); +begin + RndPCMcount := 0; +end; + + +procedure TVideoPlayback_ProjectM.init(); +begin + VisualizerStarted := False; + VisualizerPaused := False; + + {$IFDEF UseTexture} + glGenTextures(1, PglUint(@VisualTex)); + glBindTexture(GL_TEXTURE_2D, VisualTex); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + {$ENDIF} +end; + +function TVideoPlayback_ProjectM.GetName: String; +begin + result := 'ProjectM'; +end; + + +function TVideoPlayback_ProjectM.Open( aFileName : string): boolean; // true if succeed +begin + VisualizerStart(); + result := true; +end; + +procedure TVideoPlayback_ProjectM.Close; +begin +end; + +procedure TVideoPlayback_ProjectM.Play; +begin + VisualizerStart(); +end; + +procedure TVideoPlayback_ProjectM.Pause; +begin + VisualizerTogglePause(); +end; + +procedure TVideoPlayback_ProjectM.Stop; +begin + VisualizerStop(); +end; + +procedure TVideoPlayback_ProjectM.MoveTo(Time: real); +begin + pm.RandomPreset(); +end; + +function TVideoPlayback_ProjectM.getPosition: real; +begin + result := 0; +end; + +procedure TVideoPlayback_ProjectM.SaveOpenGLState(); +begin + // save all OpenGL state-machine attributes + glPushAttrib(GL_ALL_ATTRIB_BITS); + + // save projection-matrix + glMatrixMode(GL_PROJECTION); + // - WARNING: projection-matrix stack-depth is only 2! + // -> overflow might occur if glPopMatrix() is used for this matrix + // -> use glGet() instead of glPushMatrix() + glPushMatrix(); + //glGetDoublev(GL_PROJECTION_MATRIX, @projMatrix); + + // save texture-matrix + glMatrixMode(GL_TEXTURE); + // - WARNING: texture-matrix stack-depth is only 2! + // -> overflow might occur if glPopMatrix() is used for this matrix + // -> use glGet() instead of glPushMatrix() if problems appear + glPushMatrix(); + //glGetDoublev(GL_TEXTURE_MATRIX, @texMatrix); + + // save modelview-matrix + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); +end; + +procedure TVideoPlayback_ProjectM.RestoreOpenGLState(); +begin + // restore projection-matrix + glMatrixMode(GL_PROJECTION); + // - WARNING: projection-matrix stack-depth is only 2! + // -> overflow _occurs_ if glPopMatrix() is used for this matrix + // -> use glLoadMatrix() instead of glPopMatrix() + glPopMatrix(); + //glLoadMatrixd(@projMatrix); + + // restore texture-matrix + // -> overflow might occur if glPopMatrix() is used for this matrix + glMatrixMode(GL_TEXTURE); + glPopMatrix(); + //glLoadMatrixd(@texMatrix); + + // restore modelview-matrix + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + + // restore all OpenGL state-machine attributes + glPopAttrib(); +end; + +procedure TVideoPlayback_ProjectM.VisualizerStart; +var + initResult: Cardinal; +begin + VisualizerStarted := True; + + pm := TProjectM.Create(gx, gy, fps, texsize, ScreenW, ScreenH, + presetsDir, fontsDir); + //initResult := projectM_initRenderToTexture(pm); + + SaveOpenGLState(); + pm.ResetGL(ScreenW, ScreenH); + RestoreOpenGLState(); +end; + +procedure TVideoPlayback_ProjectM.VisualizerStop; +begin + if VisualizerStarted then begin + VisualizerStarted := False; + pm.Free(); + end; +end; + +procedure TVideoPlayback_ProjectM.VisualizerTogglePause; +begin + VisualizerPaused := not VisualizerPaused; +end; + +procedure TVideoPlayback_ProjectM.GetFrame(Time: Extended); +var + i: integer; + nSamples: cardinal; + stackDepth: Integer; +begin + if not VisualizerStarted then Exit; + if VisualizerPaused then Exit; + + // get audio data + nSamples := AudioPlayback.GetPCMData(PcmData); + + if nSamples = 0 then + nSamples := GetRandomPCMData(PcmData); + + pm.AddPCM16Data(PSmallint(@PcmData), nSamples); + + // store OpenGL state (might be messed up otherwise) + SaveOpenGLState(); + pm.ResetGL(ScreenW, ScreenH); + + //glGetIntegerv(GL_PROJECTION_STACK_DEPTH, @stackDepth); + //writeln('StackDepth0: ' + inttostr(stackDepth)); + + // let projectM render a frame + try + pm.RenderFrame(); + except + // this may happen with some presets ( on linux ) if there is a div by zero + // in projectM's getBeatVals() function (file: beat_detect.cc) + Log.LogStatus('Div by zero!', 'Visualizer'); + MoveTo( now ); + end; + + //glGetIntegerv(GL_PROJECTION_STACK_DEPTH, @stackDepth); + //writeln('StackDepth1: ' + inttostr(stackDepth)); + + {$IFDEF UseTexture} + glBindTexture(GL_TEXTURE_2D, VisualTex); + glFlush(); + glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, VisualWidth, VisualHeight, 0); + {$ENDIF} + + // restore USDX OpenGL state + RestoreOpenGLState(); + + // discard projectM's depth buffer information (avoid overlay) + glClear(GL_DEPTH_BUFFER_BIT); +end; + +procedure TVideoPlayback_ProjectM.DrawGL(Screen: integer); +begin + {$IFDEF UseTexture} + // have a nice black background to draw on (even if there were errors opening the vid) + if Screen=1 then begin + glClearColor(0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); + end; + // exit if there's nothing to draw + if not VisualizerStarted then Exit; + + // setup display + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluOrtho2D(0, 1, 0, 1); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glEnable(GL_BLEND); + glEnable(GL_TEXTURE_2D); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glBindTexture(GL_TEXTURE_2D, VisualTex); + glColor4f(1, 1, 1, 1); + + // draw projectM frame + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2f(0, 0); + glTexCoord2f(1, 0); glVertex2f(1, 0); + glTexCoord2f(1, 1); glVertex2f(1, 1); + glTexCoord2f(0, 1); glVertex2f(0, 1); + glEnd(); + + glDisable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + + // restore state + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + {$ENDIF} +end; + +function TVideoPlayback_ProjectM.GetRandomPCMData(var data: TPCMData): Cardinal; +var + i: integer; +begin + // Produce some fake PCM data + if ( RndPCMcount mod 500 = 0 ) then + begin + for i := 0 to 511 do begin + data[0][i] := 0; + data[1][i] := 0; + end; + end + else begin + for i := 0 to 511 do begin + if ( i mod 2 = 0 ) then begin + data[0][i] := floor(Random * power(2.,14)); + data[1][i] := floor(Random * power(2.,14)); + end + else begin; + data[0][i] := floor(Random * power(2.,14)); + data[1][i] := floor(Random * power(2.,14)); + end; + if ( i mod 2 = 1 ) then begin + data[0][i] := -data[0][i]; + data[1][i] := -data[1][i]; + end; + end; + end; + Inc( RndPCMcount ); + result := 512; +end; + + +initialization + singleton_VideoProjectM := TVideoPlayback_ProjectM.create(); + AudioManager.add( singleton_VideoProjectM ); + +finalization + AudioManager.Remove( singleton_VideoProjectM ); + + + +end. -- cgit v1.2.3 From ff1dc556936cef441e105a19aa9d1d3b9e0cc833 Mon Sep 17 00:00:00 2001 From: tobigun Date: Fri, 11 Jan 2008 13:52:44 +0000 Subject: changed from ffmpeg-free (audio) to ffmpeg-enabled (if turned on in switches.inc) version. BASS is used by default. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@786 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UVisualizer.pas | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'Game/Code/Classes/UVisualizer.pas') diff --git a/Game/Code/Classes/UVisualizer.pas b/Game/Code/Classes/UVisualizer.pas index 5fc4bb82..22c168a2 100644 --- a/Game/Code/Classes/UVisualizer.pas +++ b/Game/Code/Classes/UVisualizer.pas @@ -61,9 +61,7 @@ type VisualTex : glUint; PCMData : TPCMData; - hRC : Integer; - hDC : Integer; - + RndPCMcount : integer; projMatrix: array[0..3, 0..3] of GLdouble; @@ -91,8 +89,8 @@ type procedure Pause; procedure Stop; - procedure MoveTo(Time: real); - function getPosition: real; + procedure SetPosition(Time: real); + function GetPosition: real; procedure GetFrame(Time: Extended); procedure DrawGL(Screen: integer); @@ -150,12 +148,12 @@ begin VisualizerStop(); end; -procedure TVideoPlayback_ProjectM.MoveTo(Time: real); +procedure TVideoPlayback_ProjectM.SetPosition(Time: real); begin pm.RandomPreset(); end; -function TVideoPlayback_ProjectM.getPosition: real; +function TVideoPlayback_ProjectM.GetPosition: real; begin result := 0; end; @@ -240,7 +238,6 @@ end; procedure TVideoPlayback_ProjectM.GetFrame(Time: Extended); var - i: integer; nSamples: cardinal; stackDepth: Integer; begin @@ -269,7 +266,7 @@ begin // this may happen with some presets ( on linux ) if there is a div by zero // in projectM's getBeatVals() function (file: beat_detect.cc) Log.LogStatus('Div by zero!', 'Visualizer'); - MoveTo( now ); + SetPosition( now ); end; //glGetIntegerv(GL_PROJECTION_STACK_DEPTH, @stackDepth); -- cgit v1.2.3 From 9e696510eb04ce60cbfb8fa88629c66a9384c0f2 Mon Sep 17 00:00:00 2001 From: tobigun Date: Tue, 12 Feb 2008 10:30:58 +0000 Subject: UVisualizer uses the system dependant default game-path now git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@843 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UVisualizer.pas | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'Game/Code/Classes/UVisualizer.pas') diff --git a/Game/Code/Classes/UVisualizer.pas b/Game/Code/Classes/UVisualizer.pas index 22c168a2..2f584299 100644 --- a/Game/Code/Classes/UVisualizer.pas +++ b/Game/Code/Classes/UVisualizer.pas @@ -36,6 +36,7 @@ implementation uses UGraphic, + UMain, ULog; var @@ -46,10 +47,15 @@ const gy = 24; fps = 30; texsize = 512; - visualsDir = 'Visuals'; // TODO: move this to a place common for all visualizers - projectMDir = visualsDir+'/projectM'; - presetsDir = projectMDir+'/presets'; - fontsDir = projectMDir+'/fonts'; + +var + ProjectMPath : string; + presetsDir : string; + fontsDir : string; + + // FIXME: dirty fix needed because the init method is not + // called yet. + inited: boolean; type TVideoPlayback_ProjectM = class( TInterfacedObject, IVideoPlayback, IVideoVisualization ) @@ -78,8 +84,8 @@ type procedure RestoreOpenGLState(); public - constructor create(); - procedure init(); + constructor Create(); + procedure Init(); function GetName: String; function Open( aFileName : string): boolean; // true if succeed @@ -97,14 +103,22 @@ type end; -constructor TVideoPlayback_ProjectM.create(); +constructor TVideoPlayback_ProjectM.Create(); begin RndPCMcount := 0; end; -procedure TVideoPlayback_ProjectM.init(); +procedure TVideoPlayback_ProjectM.Init(); begin + // FIXME: dirty fix needed because the init method is not + // called yet. + inited := true; + + ProjectMPath := VisualsPath + 'projectM' + PathDelim; + presetsDir := ProjectMPath + 'presets'; + fontsDir := ProjectMPath + 'fonts'; + VisualizerStarted := False; VisualizerPaused := False; @@ -212,6 +226,11 @@ procedure TVideoPlayback_ProjectM.VisualizerStart; var initResult: Cardinal; begin + // FIXME: dirty fix needed because the init method is not + // called yet. + if (not inited) then + Init(); + VisualizerStarted := True; pm := TProjectM.Create(gx, gy, fps, texsize, ScreenW, ScreenH, -- cgit v1.2.3