diff --git a/src/projectM-iTunes/iprojectM.cpp b/src/projectM-iTunes/iprojectM.cpp index 42edafbbf..1c70b7a0b 100755 --- a/src/projectM-iTunes/iprojectM.cpp +++ b/src/projectM-iTunes/iprojectM.cpp @@ -29,11 +29,11 @@ #include #endif -#include +#include #include -#include -#include -#include +#include +#include +#include //#include #ifdef WIN32 diff --git a/src/projectM-libvisual/actor_projectM.cpp b/src/projectM-libvisual/actor_projectM.cpp index f69a8a328..bd83a4f91 100644 --- a/src/projectM-libvisual/actor_projectM.cpp +++ b/src/projectM-libvisual/actor_projectM.cpp @@ -1,390 +1,390 @@ -#include -using namespace std; - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include "lvtoprojectM.h" - -#if HAVE_CONFIG_H -#include -#endif -#define CONFIG_FILE "/config" -#define PRESETS_DIR "/presets" -#define FONTS_DIR "/fonts" - -void read_config(); - -int texsize=512; -int gx=32,gy=24; -int wvw=512,wvh=512; -int fvw=1024,fvh=768; -int fps=30, fullscreen=0; - -/* Private context sensitive data goes here, */ -typedef struct { - projectM *PM; -} ProjectmPrivate; - -extern "C" int lv_projectm_init (VisPluginData *plugin); -extern "C" int lv_projectm_cleanup (VisPluginData *plugin); -extern "C" int lv_projectm_requisition (VisPluginData *plugin, int *width, int *height); -extern "C" int lv_projectm_dimension (VisPluginData *plugin, VisVideo *video, int width, int height); -extern "C" int lv_projectm_events (VisPluginData *plugin, VisEventQueue *events); -extern "C" VisPalette *lv_projectm_palette (VisPluginData *plugin); -extern "C" int lv_projectm_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio); - -VISUAL_PLUGIN_API_VERSION_VALIDATOR - -/* Main plugin stuff */ -/* The get_plugin_info function provides the libvisual plugin registry, and plugin loader - * with the very basic plugin information */ -extern "C" const VisPluginInfo *get_plugin_info (int *count) -{ - /* Initialize the plugin specific data structure - * with pointers to the functions that represent - * the plugin interface it's implementation, more info: - * http://libvisual.sourceforge.net/newdocs/docs/html/struct__VisActorPlugin.html */ - static VisActorPlugin actor[1]; - static VisPluginInfo info[1]; - - actor[0].requisition = lv_projectm_requisition; - actor[0].palette = lv_projectm_palette; - actor[0].render = lv_projectm_render; - actor[0].vidoptions.depth = VISUAL_VIDEO_DEPTH_GL; /* We want GL clearly */ - - - info[0].type = VISUAL_PLUGIN_TYPE_ACTOR; - - info[0].plugname = "projectM"; - info[0].name = "libvisual projectM"; - info[0].author = "Peter Sperl"; - info[0].version = "1.00"; - info[0].about = "projectM"; - info[0].help = ""; - - info[0].init = lv_projectm_init; - info[0].cleanup = lv_projectm_cleanup; - info[0].events = lv_projectm_events; - - info[0].plugin = VISUAL_OBJECT (&actor[0]); - *count = sizeof (info) / sizeof (*info); - - VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_ALPHA_SIZE, 8); - VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_DEPTH_SIZE, 16); - VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_DOUBLEBUFFER, 1); - - VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_RED_SIZE, 8); - VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_GREEN_SIZE, 8); - VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_BLUE_SIZE, 8); - return info; -} - - -/* This function is called before we really start rendering, it's the init function */ -extern "C" int lv_projectm_init (VisPluginData *plugin) -{ - char projectM_data[1024]; - ProjectmPrivate *priv; - - read_config(); - /* Allocate the projectm private data structure, and register it as a private */ - - priv = new ProjectmPrivate; - visual_mem_set (priv, 0, sizeof (ProjectmPrivate)); - - - //priv = visual_mem_new0 (ProjectmPrivate, 1); - visual_object_set_private (VISUAL_OBJECT (plugin), priv); - - //FIXME - priv->PM = visual_mem_new0 (projectM, 1); - //globalPM = (projectM *)wipemalloc( sizeof( projectM ) ); - priv->PM->projectM_reset(); - - - //projectM_reset( globalPM ); - - priv->PM->fullscreen = 0; //fullscreen; - priv->PM->renderTarget->texsize = texsize; - priv->PM->renderTarget->usePbuffers = 1; - priv->PM->gx=gx; - priv->PM->gy=gy; - priv->PM->fps=fps; - - - strcpy(projectM_data, PROJECTM_DATADIR); - strcpy(projectM_data+strlen(PROJECTM_DATADIR), FONTS_DIR); - projectM_data[strlen(PROJECTM_DATADIR)+strlen(FONTS_DIR)]='\0'; - - priv->PM->fontURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( priv->PM->fontURL, projectM_data ); - - strcpy(projectM_data+strlen(PROJECTM_DATADIR), PRESETS_DIR); - projectM_data[strlen(PROJECTM_DATADIR)+strlen(PRESETS_DIR)]='\0'; - - priv->PM->presetURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( priv->PM->presetURL, projectM_data ); - - priv->PM->projectM_init(); - - priv->PM->projectM_resetGL( wvw, wvh ); - - return 0; -} - -extern "C" int lv_projectm_cleanup (VisPluginData *plugin) -{ - ProjectmPrivate *priv = (ProjectmPrivate*)visual_object_get_private (VISUAL_OBJECT (plugin)); - - /* Cleanup, and thus also free our private */ - visual_mem_free (priv->PM); - visual_mem_free (priv); - return 0; -} - -/* This is used to ask a plugin if it can handle a certain size, and if not, to - * set the size it wants by putting a value in width, height that represents the - * required size */ -extern "C" int lv_projectm_requisition (VisPluginData *plugin, int *width, int *height) -{ - int reqw, reqh; - - /* Size negotiate with the window */ - reqw = *width; - reqh = *height; - - if (reqw < 64) - reqw = 64; - - if (reqh < 64) - reqh = 64; - - *width = reqw; - *height = reqh; - - return 0; -} - -extern "C" int lv_projectm_dimension (VisPluginData *plugin, VisVideo *video, int width, int height) -{ - ProjectmPrivate *priv = (ProjectmPrivate*)visual_object_get_private (VISUAL_OBJECT (plugin)); - - visual_video_set_dimension (video, width, height); - - priv->PM->projectM_resetGL( width, height ); - - return 0; -} - -/* This is the main event loop, where all kind of events can be handled, more information - * regarding these can be found at: - * http://libvisual.sourceforge.net/newdocs/docs/html/union__VisEvent.html - */ -extern "C" int lv_projectm_events (VisPluginData *plugin, VisEventQueue *events) -{ - ProjectmPrivate *priv = (ProjectmPrivate*)visual_object_get_private (VISUAL_OBJECT (plugin)); - VisEvent ev; - VisParamEntry *param; - - projectMEvent evt; - projectMKeycode key; - projectMModifier mod; - - while (visual_event_queue_poll (events, &ev)) - { - switch (ev.type) - { - case VISUAL_EVENT_KEYUP: - - evt = lv2pmEvent( ev.type ); - key = lv2pmKeycode( ev.event.keyboard.keysym.sym ); - mod = lv2pmModifier( ev.event.keyboard.keysym.mod ); - priv->PM->key_handler(PROJECTM_KEYDOWN, key,mod); - - break; - case VISUAL_EVENT_RESIZE: - lv_projectm_dimension (plugin, ev.event.resize.video, - ev.event.resize.width, ev.event.resize.height); - break; - - default: /* to avoid warnings */ - break; - } - } - - return 0; -} - -/* Using this function we can update the palette when we're in 8bits mode, which - * we aren't with projectm, so just ignore :) */ -extern "C" VisPalette *lv_projectm_palette (VisPluginData *plugin) -{ - return NULL; -} - -/* This is where the real rendering happens! This function is what we call, many times - * a second to get our graphical frames. */ -extern "C" int lv_projectm_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio) -{ - ProjectmPrivate *priv = (ProjectmPrivate*)visual_object_get_private (VISUAL_OBJECT (plugin)); - VisBuffer pcmb; - float pcm[2][512]; - //short pcms[2][512]; - int i; - - visual_buffer_set_data_pair (&pcmb, pcm[0], sizeof (pcm[0])); - visual_audio_get_sample (audio, &pcmb, VISUAL_AUDIO_CHANNEL_LEFT); - - visual_buffer_set_data_pair (&pcmb, pcm[1], sizeof (pcm[1])); - visual_audio_get_sample (audio, &pcmb, VISUAL_AUDIO_CHANNEL_RIGHT); - - /* - for (i = 0; i < 512; i++) { - pcms[0][i] = pcm[0][i] * 32768.0; - pcms[1][i] = pcm[1][i] * 32768.0; - } - - addPCM16Data(pcms,512); - */ - - priv->PM->beatDetect->pcm->addPCMfloat(*pcm,512); - - priv->PM->renderFrame(); - - return 0; -} - - - -void read_config() -{ - - int n; - - char num[80]; - FILE *in; - FILE *out; - - char* home; - char projectM_home[1024]; - char projectM_config[1024]; - - strcpy(projectM_config, PROJECTM_DATADIR); - strcpy(projectM_config+strlen(PROJECTM_DATADIR), CONFIG_FILE); - projectM_config[strlen(PROJECTM_DATADIR)+strlen(CONFIG_FILE)]='\0'; - - home=getenv("HOME"); - strcpy(projectM_home, home); - strcpy(projectM_home+strlen(home), "/.projectM/config"); - projectM_home[strlen(home)+strlen("/.projectM/config")]='\0'; - - - if ((in = fopen(projectM_home, "r")) != 0) - { - printf("reading ~/.projectM/config \n"); - } - else - { - printf("trying to create ~/.projectM/config \n"); - - strcpy(projectM_home, home); - strcpy(projectM_home+strlen(home), "/.projectM"); - projectM_home[strlen(home)+strlen("/.projectM")]='\0'; - mkdir(projectM_home,0755); - - strcpy(projectM_home, home); - strcpy(projectM_home+strlen(home), "/.projectM/config"); - projectM_home[strlen(home)+strlen("/.projectM/config")]='\0'; - - if((out = fopen(projectM_home,"w"))!=0) - { - - if ((in = fopen(projectM_config, "r")) != 0) - { - - while(fgets(num,80,in)!=NULL) - { - fputs(num,out); - } - fclose(in); - fclose(out); - - - if ((in = fopen(projectM_home, "r")) != 0) - { printf("created ~/.projectM/config successfully\n"); } - else{printf("This shouldn't happen, using implementation defualts\n");return;} - } - else{printf("Cannot find projectM default config, using implementation defaults\n");return;} - } - else - { - printf("Cannot create ~/.projectM/config, using default config file\n"); - if ((in = fopen(projectM_config, "r")) != 0) - { printf("Successfully opened default config file\n");} - else{ printf("Using implementation defaults, your system is really messed up, I'm suprised we even got this far\n"); return;} - - } - - } - - - - fgets(num, 80, in); fgets(num, 80, in); fgets(num, 80, in); - if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &texsize); - - fgets(num, 80, in); - if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &gx); - - fgets(num, 80, in); - if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &gy); - - fgets(num, 80, in); - if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &wvw); - - fgets(num, 80, in); - if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &wvh); - - fgets(num, 80, in); - if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fvw); - - fgets(num, 80, in); - if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fvh); - - fgets(num, 80, in); - if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fps); - - fgets(num, 80, in); - if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fullscreen); - /* - fgets(num, 80, in); - fgets(num, 80, in); - - n=0; - while (num[n]!=' ' && num[n]!='\n' && n < 80 && num[n]!=EOF) - { - disp[n]=num[n]; - n++; - } - disp[n]=0; - - - // sprintf(disp,"%s",num ); - setenv("DISPLAY",disp,1); - printf("%s %d\n", disp,strlen(disp)); - setenv("LD_PRELOAD", "/usr/lib/tls/libGL.so.1.0.4496", 1); - */ - fclose(in); - -} +#include +using namespace std; + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include "lvtoprojectM.hpp" + +#if HAVE_CONFIG_H +#include +#endif +#define CONFIG_FILE "/config" +#define PRESETS_DIR "/presets" +#define FONTS_DIR "/fonts" + +void read_config(); + +int texsize=512; +int gx=32,gy=24; +int wvw=512,wvh=512; +int fvw=1024,fvh=768; +int fps=30, fullscreen=0; + +/* Private context sensitive data goes here, */ +typedef struct { + projectM *PM; +} ProjectmPrivate; + +extern "C" int lv_projectm_init (VisPluginData *plugin); +extern "C" int lv_projectm_cleanup (VisPluginData *plugin); +extern "C" int lv_projectm_requisition (VisPluginData *plugin, int *width, int *height); +extern "C" int lv_projectm_dimension (VisPluginData *plugin, VisVideo *video, int width, int height); +extern "C" int lv_projectm_events (VisPluginData *plugin, VisEventQueue *events); +extern "C" VisPalette *lv_projectm_palette (VisPluginData *plugin); +extern "C" int lv_projectm_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio); + +VISUAL_PLUGIN_API_VERSION_VALIDATOR + +/* Main plugin stuff */ +/* The get_plugin_info function provides the libvisual plugin registry, and plugin loader + * with the very basic plugin information */ +extern "C" const VisPluginInfo *get_plugin_info (int *count) +{ + /* Initialize the plugin specific data structure + * with pointers to the functions that represent + * the plugin interface it's implementation, more info: + * http://libvisual.sourceforge.net/newdocs/docs/html/struct__VisActorPlugin.html */ + static VisActorPlugin actor[1]; + static VisPluginInfo info[1]; + + actor[0].requisition = lv_projectm_requisition; + actor[0].palette = lv_projectm_palette; + actor[0].render = lv_projectm_render; + actor[0].vidoptions.depth = VISUAL_VIDEO_DEPTH_GL; /* We want GL clearly */ + + + info[0].type = VISUAL_PLUGIN_TYPE_ACTOR; + + info[0].plugname = "projectM"; + info[0].name = "libvisual projectM"; + info[0].author = "Peter Sperl"; + info[0].version = "1.00"; + info[0].about = "projectM"; + info[0].help = ""; + + info[0].init = lv_projectm_init; + info[0].cleanup = lv_projectm_cleanup; + info[0].events = lv_projectm_events; + + info[0].plugin = VISUAL_OBJECT (&actor[0]); + *count = sizeof (info) / sizeof (*info); + + VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_ALPHA_SIZE, 8); + VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_DEPTH_SIZE, 16); + VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_DOUBLEBUFFER, 1); + + VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_RED_SIZE, 8); + VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_GREEN_SIZE, 8); + VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_BLUE_SIZE, 8); + return info; +} + + +/* This function is called before we really start rendering, it's the init function */ +extern "C" int lv_projectm_init (VisPluginData *plugin) +{ + char projectM_data[1024]; + ProjectmPrivate *priv; + + read_config(); + /* Allocate the projectm private data structure, and register it as a private */ + + priv = new ProjectmPrivate; + visual_mem_set (priv, 0, sizeof (ProjectmPrivate)); + + + //priv = visual_mem_new0 (ProjectmPrivate, 1); + visual_object_set_private (VISUAL_OBJECT (plugin), priv); + + //FIXME + priv->PM = visual_mem_new0 (projectM, 1); + //globalPM = (projectM *)wipemalloc( sizeof( projectM ) ); + priv->PM->projectM_reset(); + + + //projectM_reset( globalPM ); + + priv->PM->fullscreen = 0; //fullscreen; + priv->PM->renderTarget->texsize = texsize; + priv->PM->renderTarget->usePbuffers = 1; + priv->PM->gx=gx; + priv->PM->gy=gy; + priv->PM->fps=fps; + + + strcpy(projectM_data, PROJECTM_DATADIR); + strcpy(projectM_data+strlen(PROJECTM_DATADIR), FONTS_DIR); + projectM_data[strlen(PROJECTM_DATADIR)+strlen(FONTS_DIR)]='\0'; + + priv->PM->fontURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( priv->PM->fontURL, projectM_data ); + + strcpy(projectM_data+strlen(PROJECTM_DATADIR), PRESETS_DIR); + projectM_data[strlen(PROJECTM_DATADIR)+strlen(PRESETS_DIR)]='\0'; + + priv->PM->presetURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( priv->PM->presetURL, projectM_data ); + + priv->PM->projectM_init(); + + priv->PM->projectM_resetGL( wvw, wvh ); + + return 0; +} + +extern "C" int lv_projectm_cleanup (VisPluginData *plugin) +{ + ProjectmPrivate *priv = (ProjectmPrivate*)visual_object_get_private (VISUAL_OBJECT (plugin)); + + /* Cleanup, and thus also free our private */ + visual_mem_free (priv->PM); + visual_mem_free (priv); + return 0; +} + +/* This is used to ask a plugin if it can handle a certain size, and if not, to + * set the size it wants by putting a value in width, height that represents the + * required size */ +extern "C" int lv_projectm_requisition (VisPluginData *plugin, int *width, int *height) +{ + int reqw, reqh; + + /* Size negotiate with the window */ + reqw = *width; + reqh = *height; + + if (reqw < 64) + reqw = 64; + + if (reqh < 64) + reqh = 64; + + *width = reqw; + *height = reqh; + + return 0; +} + +extern "C" int lv_projectm_dimension (VisPluginData *plugin, VisVideo *video, int width, int height) +{ + ProjectmPrivate *priv = (ProjectmPrivate*)visual_object_get_private (VISUAL_OBJECT (plugin)); + + visual_video_set_dimension (video, width, height); + + priv->PM->projectM_resetGL( width, height ); + + return 0; +} + +/* This is the main event loop, where all kind of events can be handled, more information + * regarding these can be found at: + * http://libvisual.sourceforge.net/newdocs/docs/html/union__VisEvent.html + */ +extern "C" int lv_projectm_events (VisPluginData *plugin, VisEventQueue *events) +{ + ProjectmPrivate *priv = (ProjectmPrivate*)visual_object_get_private (VISUAL_OBJECT (plugin)); + VisEvent ev; + VisParamEntry *param; + + projectMEvent evt; + projectMKeycode key; + projectMModifier mod; + + while (visual_event_queue_poll (events, &ev)) + { + switch (ev.type) + { + case VISUAL_EVENT_KEYUP: + + evt = lv2pmEvent( ev.type ); + key = lv2pmKeycode( ev.event.keyboard.keysym.sym ); + mod = lv2pmModifier( ev.event.keyboard.keysym.mod ); + priv->PM->key_handler(PROJECTM_KEYDOWN, key,mod); + + break; + case VISUAL_EVENT_RESIZE: + lv_projectm_dimension (plugin, ev.event.resize.video, + ev.event.resize.width, ev.event.resize.height); + break; + + default: /* to avoid warnings */ + break; + } + } + + return 0; +} + +/* Using this function we can update the palette when we're in 8bits mode, which + * we aren't with projectm, so just ignore :) */ +extern "C" VisPalette *lv_projectm_palette (VisPluginData *plugin) +{ + return NULL; +} + +/* This is where the real rendering happens! This function is what we call, many times + * a second to get our graphical frames. */ +extern "C" int lv_projectm_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio) +{ + ProjectmPrivate *priv = (ProjectmPrivate*)visual_object_get_private (VISUAL_OBJECT (plugin)); + VisBuffer pcmb; + float pcm[2][512]; + //short pcms[2][512]; + int i; + + visual_buffer_set_data_pair (&pcmb, pcm[0], sizeof (pcm[0])); + visual_audio_get_sample (audio, &pcmb, VISUAL_AUDIO_CHANNEL_LEFT); + + visual_buffer_set_data_pair (&pcmb, pcm[1], sizeof (pcm[1])); + visual_audio_get_sample (audio, &pcmb, VISUAL_AUDIO_CHANNEL_RIGHT); + + /* + for (i = 0; i < 512; i++) { + pcms[0][i] = pcm[0][i] * 32768.0; + pcms[1][i] = pcm[1][i] * 32768.0; + } + + addPCM16Data(pcms,512); + */ + + priv->PM->beatDetect->pcm->addPCMfloat(*pcm,512); + + priv->PM->renderFrame(); + + return 0; +} + + + +void read_config() +{ + + int n; + + char num[80]; + FILE *in; + FILE *out; + + char* home; + char projectM_home[1024]; + char projectM_config[1024]; + + strcpy(projectM_config, PROJECTM_DATADIR); + strcpy(projectM_config+strlen(PROJECTM_DATADIR), CONFIG_FILE); + projectM_config[strlen(PROJECTM_DATADIR)+strlen(CONFIG_FILE)]='\0'; + + home=getenv("HOME"); + strcpy(projectM_home, home); + strcpy(projectM_home+strlen(home), "/.projectM/config"); + projectM_home[strlen(home)+strlen("/.projectM/config")]='\0'; + + + if ((in = fopen(projectM_home, "r")) != 0) + { + printf("reading ~/.projectM/config \n"); + } + else + { + printf("trying to create ~/.projectM/config \n"); + + strcpy(projectM_home, home); + strcpy(projectM_home+strlen(home), "/.projectM"); + projectM_home[strlen(home)+strlen("/.projectM")]='\0'; + mkdir(projectM_home,0755); + + strcpy(projectM_home, home); + strcpy(projectM_home+strlen(home), "/.projectM/config"); + projectM_home[strlen(home)+strlen("/.projectM/config")]='\0'; + + if((out = fopen(projectM_home,"w"))!=0) + { + + if ((in = fopen(projectM_config, "r")) != 0) + { + + while(fgets(num,80,in)!=NULL) + { + fputs(num,out); + } + fclose(in); + fclose(out); + + + if ((in = fopen(projectM_home, "r")) != 0) + { printf("created ~/.projectM/config successfully\n"); } + else{printf("This shouldn't happen, using implementation defualts\n");return;} + } + else{printf("Cannot find projectM default config, using implementation defaults\n");return;} + } + else + { + printf("Cannot create ~/.projectM/config, using default config file\n"); + if ((in = fopen(projectM_config, "r")) != 0) + { printf("Successfully opened default config file\n");} + else{ printf("Using implementation defaults, your system is really messed up, I'm suprised we even got this far\n"); return;} + + } + + } + + + + fgets(num, 80, in); fgets(num, 80, in); fgets(num, 80, in); + if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &texsize); + + fgets(num, 80, in); + if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &gx); + + fgets(num, 80, in); + if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &gy); + + fgets(num, 80, in); + if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &wvw); + + fgets(num, 80, in); + if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &wvh); + + fgets(num, 80, in); + if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fvw); + + fgets(num, 80, in); + if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fvh); + + fgets(num, 80, in); + if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fps); + + fgets(num, 80, in); + if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fullscreen); + /* + fgets(num, 80, in); + fgets(num, 80, in); + + n=0; + while (num[n]!=' ' && num[n]!='\n' && n < 80 && num[n]!=EOF) + { + disp[n]=num[n]; + n++; + } + disp[n]=0; + + + // sprintf(disp,"%s",num ); + setenv("DISPLAY",disp,1); + printf("%s %d\n", disp,strlen(disp)); + setenv("LD_PRELOAD", "/usr/lib/tls/libGL.so.1.0.4496", 1); + */ + fclose(in); + +} diff --git a/src/projectM-libvisual/lvtoprojectM.h b/src/projectM-libvisual/lvtoprojectM.h index 1dd6184ad..15e9acc81 100755 --- a/src/projectM-libvisual/lvtoprojectM.h +++ b/src/projectM-libvisual/lvtoprojectM.h @@ -1,156 +1,156 @@ -/** - * projectM -- Milkdrop-esque visualisation SDK - * Copyright (C)2003-2007 projectM Team - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * See 'LICENSE.txt' included within this release - * - */ -/** - * $Id: sdltoprojectM.h,v 1.1 2004/10/08 00:35:28 cvs Exp $ - * - * Translates SDL -> projectM variables - * - * $Log: sdltoprojectM.h,v $ - * Revision 1.1 2004/10/08 00:35:28 cvs - * Moved and imported - * - * Revision 1.1.1.1 2004/10/04 12:56:00 cvs - * Imported - * - */ - -#include - -projectMEvent lv2pmEvent( VisEventType event ) { - - switch ( event ) { - case VISUAL_EVENT_RESIZE: - return PROJECTM_VIDEORESIZE; - case VISUAL_EVENT_KEYUP: - return PROJECTM_KEYUP; - case VISUAL_EVENT_KEYDOWN: - return PROJECTM_KEYDOWN; - default: - return PROJECTM_KEYUP; - } - } -projectMKeycode lv2pmKeycode( VisKey keysym ) -{ - switch ( keysym ) - { - case VKEY_F1: - return PROJECTM_K_F1; - case VKEY_F2: - return PROJECTM_K_F2; - case VKEY_F3: - return PROJECTM_K_F3; - case VKEY_F4: - return PROJECTM_K_F4; - case VKEY_F5: - return PROJECTM_K_F5; - case VKEY_F6: - return PROJECTM_K_F6; - case VKEY_F7: - return PROJECTM_K_F7; - case VKEY_F8: - return PROJECTM_K_F8; - case VKEY_F9: - return PROJECTM_K_F9; - case VKEY_F10: - return PROJECTM_K_F10; - case VKEY_F11: - return PROJECTM_K_F11; - case VKEY_F12: - return PROJECTM_K_F12; - case VKEY_ESCAPE: - return PROJECTM_K_ESCAPE; - case VKEY_a: - return PROJECTM_K_a; - case VKEY_b: - return PROJECTM_K_b; - case VKEY_c: - return PROJECTM_K_c; - case VKEY_d: - return PROJECTM_K_d; - case VKEY_e: - return PROJECTM_K_e; - case VKEY_f: - return PROJECTM_K_f; - case VKEY_g: - return PROJECTM_K_g; - case VKEY_h: - return PROJECTM_K_h; - case VKEY_i: - return PROJECTM_K_i; - case VKEY_j: - return PROJECTM_K_j; - case VKEY_k: - return PROJECTM_K_k; - case VKEY_l: - return PROJECTM_K_l; - case VKEY_m: - return PROJECTM_K_m; - case VKEY_n: - return PROJECTM_K_n; - case VKEY_o: - return PROJECTM_K_o; - case VKEY_p: - return PROJECTM_K_p; - case VKEY_q: - return PROJECTM_K_q; - case VKEY_r: - return PROJECTM_K_r; - case VKEY_s: - return PROJECTM_K_s; - case VKEY_t: - return PROJECTM_K_t; - case VKEY_u: - return PROJECTM_K_u; - case VKEY_v: - return PROJECTM_K_v; - case VKEY_w: - return PROJECTM_K_w; - case VKEY_x: - return PROJECTM_K_x; - case VKEY_y: - return PROJECTM_K_y; - case VKEY_z: - return PROJECTM_K_z; - case VKEY_UP: - return PROJECTM_K_UP; - case VKEY_RETURN: - return PROJECTM_K_RETURN; - case VKEY_RIGHT: - return PROJECTM_K_RIGHT; - case VKEY_LEFT: - return PROJECTM_K_LEFT; - case VKEY_DOWN: - return PROJECTM_K_DOWN; - case VKEY_PAGEUP: - return PROJECTM_K_PAGEUP; - case VKEY_PAGEDOWN: - return PROJECTM_K_PAGEDOWN; - - - default: - return PROJECTM_K_NONE; - break; - } - } - -projectMModifier lv2pmModifier( int mod ) { - return (projectMModifier) mod; - } +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: sdltoprojectM.hpp,v 1.1 2004/10/08 00:35:28 cvs Exp $ + * + * Translates SDL -> projectM variables + * + * $Log: sdltoprojectM.hpp,v $ + * Revision 1.1 2004/10/08 00:35:28 cvs + * Moved and imported + * + * Revision 1.1.1.1 2004/10/04 12:56:00 cvs + * Imported + * + */ + +#include + +projectMEvent lv2pmEvent( VisEventType event ) { + + switch ( event ) { + case VISUAL_EVENT_RESIZE: + return PROJECTM_VIDEORESIZE; + case VISUAL_EVENT_KEYUP: + return PROJECTM_KEYUP; + case VISUAL_EVENT_KEYDOWN: + return PROJECTM_KEYDOWN; + default: + return PROJECTM_KEYUP; + } + } +projectMKeycode lv2pmKeycode( VisKey keysym ) +{ + switch ( keysym ) + { + case VKEY_F1: + return PROJECTM_K_F1; + case VKEY_F2: + return PROJECTM_K_F2; + case VKEY_F3: + return PROJECTM_K_F3; + case VKEY_F4: + return PROJECTM_K_F4; + case VKEY_F5: + return PROJECTM_K_F5; + case VKEY_F6: + return PROJECTM_K_F6; + case VKEY_F7: + return PROJECTM_K_F7; + case VKEY_F8: + return PROJECTM_K_F8; + case VKEY_F9: + return PROJECTM_K_F9; + case VKEY_F10: + return PROJECTM_K_F10; + case VKEY_F11: + return PROJECTM_K_F11; + case VKEY_F12: + return PROJECTM_K_F12; + case VKEY_ESCAPE: + return PROJECTM_K_ESCAPE; + case VKEY_a: + return PROJECTM_K_a; + case VKEY_b: + return PROJECTM_K_b; + case VKEY_c: + return PROJECTM_K_c; + case VKEY_d: + return PROJECTM_K_d; + case VKEY_e: + return PROJECTM_K_e; + case VKEY_f: + return PROJECTM_K_f; + case VKEY_g: + return PROJECTM_K_g; + case VKEY_h: + return PROJECTM_K_h; + case VKEY_i: + return PROJECTM_K_i; + case VKEY_j: + return PROJECTM_K_j; + case VKEY_k: + return PROJECTM_K_k; + case VKEY_l: + return PROJECTM_K_l; + case VKEY_m: + return PROJECTM_K_m; + case VKEY_n: + return PROJECTM_K_n; + case VKEY_o: + return PROJECTM_K_o; + case VKEY_p: + return PROJECTM_K_p; + case VKEY_q: + return PROJECTM_K_q; + case VKEY_r: + return PROJECTM_K_r; + case VKEY_s: + return PROJECTM_K_s; + case VKEY_t: + return PROJECTM_K_t; + case VKEY_u: + return PROJECTM_K_u; + case VKEY_v: + return PROJECTM_K_v; + case VKEY_w: + return PROJECTM_K_w; + case VKEY_x: + return PROJECTM_K_x; + case VKEY_y: + return PROJECTM_K_y; + case VKEY_z: + return PROJECTM_K_z; + case VKEY_UP: + return PROJECTM_K_UP; + case VKEY_RETURN: + return PROJECTM_K_RETURN; + case VKEY_RIGHT: + return PROJECTM_K_RIGHT; + case VKEY_LEFT: + return PROJECTM_K_LEFT; + case VKEY_DOWN: + return PROJECTM_K_DOWN; + case VKEY_PAGEUP: + return PROJECTM_K_PAGEUP; + case VKEY_PAGEDOWN: + return PROJECTM_K_PAGEDOWN; + + + default: + return PROJECTM_K_NONE; + break; + } + } + +projectMModifier lv2pmModifier( int mod ) { + return (projectMModifier) mod; + } diff --git a/src/projectM-moviegen/mov123.c b/src/projectM-moviegen/mov123.c index 11f627bf8..51dac69ca 100755 --- a/src/projectM-moviegen/mov123.c +++ b/src/projectM-moviegen/mov123.c @@ -1,730 +1,730 @@ -// -// SlimServer Copyright (C) 2003-2004 Sean Adams, Slim Devices Inc. -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License, -// version 2. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// -// mov123 - A very basic Quicktime decoder command line application. -// -// usage: mov123 -// -// opens and decodes the first audio track from a QuickTime compatible file. This includes -// Movie files, m4a AAC files, AIFF, WAV and other formats supported natively by quicktime. -// Sends to standard out the raw uncompressed audio data in stereo 44.1kS/sec 16bit. -// Output goes to stdout -// -// Todo: - extract channel, sample rate, and sample size information from the movie for -// use in reencoding later -// - CLI options for: -// - specifying output file -// - output files for AIFF and WAV -// - changing sample rate, sample size, channel count, codec -// - usage -// - be graceful about failures -// -// Portions based on Apple's ConvertMovieSndTrack sample code. -// - -#include -#include - -//#include - - -#ifdef WIN32 -#include "stdafx.h" -#include "Movies.h" -#include "SoundComponents.h" -#include "QTML.h" -#else -#include -#include -#endif - -#include - -#define kVideoTimeScale 600 - -extern projectM_t *globalPM; - -int path2fss( FSSpec *fss, char *path ) { - char buf[256]; - char *p = &buf[1]; - strcpy( p, path ); - buf[0] = strlen( p ); - - return FSMakeFSSpec( 0, 0, (unsigned char *)buf, fss ); - } - -#define BailErr(x) {err = x; if (err != noErr) { fprintf(stderr, "Failed at line: %d\n", __LINE__); goto bail; } } - -const UInt32 kMaxBufferSize = 64 * 1024; // max size of input buffer - -// functions -OSErr ConvertMovieSndTrack( const char* inFileToConvert, Movie *movie, - Media *videoMedia, Media *audioMedia, - Track *videoTrack, Track *audioTrack ); - -typedef struct { - ExtendedSoundComponentData compData; - Handle hSource; // source media buffer - Media sourceMedia; // sound media identifier - TimeValue getMediaAtThisTime; - TimeValue sourceDuration; - - UInt32 maxBufferSize; - Boolean isThereMoreSource; - Boolean isSourceVBR; -} SCFillBufferData, *SCFillBufferDataPtr; - -FILE* outFile; - -#ifdef WIN32 -int _tmain(int argc, _TCHAR* argv[]) -#else -int main123(int argc, char *argv[]) -#endif -{ - - FSSpec theDestFSSpec; - OSErr result = 0; - OSErr err = noErr; - short resRefNum = 0; - short resId = movieInDataForkResID; - Movie newMovie; - Media audioMedia, videoMedia; - Track audioTrack, videoTrack; -// StringPtr fileName = QTUtils_ConvertCToPascalString( argv[2] ); - - outFile = stderr; - -#ifdef WIN32 - setmode(fileno(outFile), O_BINARY); - InitializeQTML(0); // Initialize QTML -#endif - EnterMovies(); - - if (argc > 2) - path2fss( &theDestFSSpec, argv[2] ); - - /** Create the new output movie */ - err = - CreateMovieFile( &theDestFSSpec, FOUR_CHAR_CODE('TV0D'), - smSystemScript, - createMovieFileDeleteCurFile | createMovieFileDontCreateResFile | newMovieActive, - &resRefNum, &newMovie ); - if ( err != noErr ) { - printf( "failed to CreateMovieFile()\n" ); - } else { - printf( "created movie ok\n" ); - } - - /** Create the video track */ - videoTrack = - NewMovieTrack( newMovie, 512, 512, kNoVolume ); - - videoMedia = - NewTrackMedia( videoTrack, VideoMediaType, kVideoTimeScale, nil, - 0 ); - - /** Establish a media edit session */ - err = BeginMediaEdits( videoMedia ); - if ( err != noErr ) { - printf( "failed to BeginMediaEdits( video )\n" ); - } else { - printf( "beginning video media edit ok\n" ); - } - - /** Create the audio track */ - audioTrack = - NewMovieTrack( newMovie, 0, 0, kFullVolume ); - audioMedia = - NewTrackMedia( audioTrack, SoundMediaType, 44000, nil, 0 ); - - err = BeginMediaEdits( audioMedia ); - if ( err != noErr ) { - printf( "failed to BeginMediaEdits( audio )\n" ); - } else { - printf( "beginning audio media edits ok\n" ); - } - - /** Convert the input sound data into a movie file with video and audio */ - result = ConvertMovieSndTrack( argv[1], &newMovie, &videoMedia, &audioMedia, - &videoTrack, &audioTrack ); - - /** End media edits */ - err = EndMediaEdits( videoMedia ); - - err = EndMediaEdits( audioMedia ); - - /** Insert the audio track into the media */ - err = InsertMediaIntoTrack( audioTrack, 0, 0, - GetMediaDuration( audioMedia ), fixed1 ); - if ( err != noErr ) { - printf( "failed to insert audio media into audio track\n" ); - } else { - printf( "injected audio media into audio track ok\n" ); - } - - /** Add the movie resource to the file */ - err = AddMovieResource( newMovie, resRefNum, &resId, argv[2] ); - if ( err != noErr ) { - printf( "failed to AddMovieResource()\n" ); - } - if ( resRefNum ) { - CloseMovieFile( resRefNum ); - } - -//bail: - if (result != 0) { fprintf(stderr, "Conversion failed with error: %d\n", result); } - return result; -} - - -#ifndef AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER - // these didn't make it into the QT6 framework for 10.1.x so include - // them here if we're not on 10.2 or later - if you have a newer framework - // or are building a carbon CFM version you shouldn't need these - enum { - scSoundVBRCompressionOK = 'cvbr', /* pointer to Boolean*/ - scSoundInputSampleRateType = 'ssir', /* pointer to UnsignedFixed*/ - scSoundSampleRateChangeOK = 'rcok', /* pointer to Boolean*/ - scAvailableCompressionListType = 'avai' /* pointer to OSType Handle*/ - }; -#endif - - -// * ---------------------------- -// SoundConverterFillBufferDataProc -// -// the callback routine that provides the SOURCE DATA for conversion - it provides data by setting -// outData to a pointer to a properly filled out ExtendedSoundComponentData structure -static pascal Boolean SoundConverterFillBufferDataProc(SoundComponentDataPtr *outData, void *inRefCon) -{ - int i, j; - - float nframes = 0; - - SCFillBufferDataPtr pFillData = (SCFillBufferDataPtr)inRefCon; - - OSErr err; - - // if after getting the last chunk of data the total time is over the duration, we're done - if (pFillData->getMediaAtThisTime >= pFillData->sourceDuration) { - pFillData->isThereMoreSource = false; - pFillData->compData.desc.buffer = NULL; - pFillData->compData.desc.sampleCount = 0; - pFillData->compData.bufferSize = 0; - pFillData->compData.commonFrameSize = 0; - } - - if (pFillData->isThereMoreSource) { - - long sourceBytesReturned; - long numberOfSamples; - TimeValue sourceReturnedTime, durationPerSample; - - // in calling GetMediaSample, we'll get a buffer that consists of equal sized frames - the - // degenerate case is only 1 frame -- for non-self-framed vbr formats (like AAC in QT 6) - // we need to provide some more framing information - either the frameCount, frameSizeArray pair or - // the commonFrameSize field must be valid -- because we always get equal sized frames, we can use - // commonFrameSize and set the kExtendedSoundCommonFrameSizeValid flag -- if there is - // only 1 frame then (common frame size == media sample size), if there are multiple frames, - // then (common frame size == media sample size / number of frames). - - err = GetMediaSample(pFillData->sourceMedia, // specifies the media for this operation - pFillData->hSource, // function returns the sample data into this handle - pFillData->maxBufferSize, // maximum number of bytes of sample data to be returned - &sourceBytesReturned, // the number of bytes of sample data returned - pFillData->getMediaAtThisTime, // starting time of the sample to be retrieved (must be in Media's TimeScale) - &sourceReturnedTime, // indicates the actual time of the returned sample data - &durationPerSample, // duration of each sample in the media - NULL, // sample description corresponding to the returned sample data (NULL to ignore) - NULL, // index value to the sample description that corresponds to the returned sample data (NULL to ignore) - 0, // maximum number of samples to be returned (0 to use a value that is appropriate for the media) - &numberOfSamples, // number of samples it actually returned - NULL); // flags that describe the sample (NULL to ignore) - - if ((noErr != err) || (sourceBytesReturned == 0)) { - pFillData->isThereMoreSource = false; - pFillData->compData.desc.buffer = NULL; - pFillData->compData.desc.sampleCount = 0; - pFillData->compData.bufferSize = 0; - pFillData->compData.commonFrameSize = 0; - - if ((err != noErr) && (sourceBytesReturned > 0)) - printf("GetMediaSample - Failed in FillBufferDataProc"); - } - - pFillData->getMediaAtThisTime = sourceReturnedTime + (durationPerSample * numberOfSamples); - - // sampleCount is the number of PCM samples - pFillData->compData.desc.sampleCount = numberOfSamples * durationPerSample; - - // kExtendedSoundBufferSizeValid was specified - make sure this field is filled in correctly - pFillData->compData.bufferSize = sourceBytesReturned; - - // for VBR audio we specified the kExtendedSoundCommonFrameSizeValid flag - make sure this field is filled in correctly - if (pFillData->isSourceVBR) pFillData->compData.commonFrameSize = sourceBytesReturned / numberOfSamples; - } - - // set outData to a properly filled out ExtendedSoundComponentData struct - *outData = (SoundComponentDataPtr)&pFillData->compData; - - return (pFillData->isThereMoreSource); -} - -// * ---------------------------- -// GetMovieMedia -// -// returns a Media identifier - if the file is a System 7 Sound a non-in-place import is done and -// a handle to the data is passed back to the caller who is responsible for disposing of it -static OSErr GetMovieMedia(const char* inFile, Movie *outMovie, Media *outMedia) -{ - Movie theMovie = 0; - Track theTrack; - short theRefNum; - short theResID = 0; // we want the first movie - OSErr err = noErr; - - BailErr(err); - - Boolean wasChanged; - - // open the movie file - if (strncmp(inFile, "http:", strlen("http:")) && - strncmp(inFile, "rtsp:", strlen("rtsp:")) && - strncmp(inFile, "ftp:", strlen("ftp:") )) { - FSSpec theFSSpec; -#ifdef WIN32 - OSErr result = NativePathNameToFSSpec((char*)inFile, &theFSSpec, 0 /* flags */); -#else - FSRef ref; // intermediate struct - FSPathMakeRef( (const UInt8*)inFile, &ref, NULL ); - OSErr result = FSGetCatalogInfo( &ref, kFSCatInfoNone , NULL, NULL, &theFSSpec, NULL); -#endif - if (result) {printf("NativePathNameToFSSpec failed on source file %s with %d\n", inFile, result); goto bail; } - err = OpenMovieFile(&theFSSpec, &theRefNum, fsRdPerm); - // instantiate the movie - BailErr(err); - err = NewMovieFromFile(&theMovie, theRefNum, &theResID, NULL, newMovieActive, &wasChanged); - CloseMovieFile(theRefNum); - } else { - - Handle urlDataRef; - - urlDataRef = NewHandle(strlen(inFile) + 1); - if ( ( err = MemError()) != noErr) goto bail; - - BlockMoveData(inFile, *urlDataRef, strlen(inFile) + 1); - - err = NewMovieFromDataRef(&theMovie, newMovieActive, nil, urlDataRef, URLDataHandlerSubType); - if (err) {printf("NewMovieFrom Data Ref failed on source file %s with %d\n", inFile, err); goto bail; } - - DisposeHandle(urlDataRef); - - } - - BailErr(err); - - // get the first sound track - theTrack = GetMovieIndTrackType(theMovie, 1, SoundMediaType, movieTrackMediaType); - if (NULL == theTrack ) BailErr(invalidTrack); - - // get and return the sound track media - *outMedia = GetTrackMedia(theTrack); - if (NULL == *outMedia) err = invalidMedia; - - *outMovie = theMovie; - -bail: - return err; -} - -// * ---------------------------- -// GetSoundDescriptionInfo -// -// this function will extract the information needed to decompress the sound file, this includes -// retrieving the sample description and the decompression atom saved as a Sample Description Extention -static OSErr GetSoundDescriptionInfo(Media inMedia, Ptr *outAudioAtom, SoundDescriptionPtr outSoundDesc) -{ - OSErr err = noErr; - - Size size; - Handle extension = NULL; - SoundDescriptionHandle hSoundDescription = (SoundDescriptionHandle)NewHandle(0); - - // get the description of the sample data - GetMediaSampleDescription(inMedia, 1, (SampleDescriptionHandle)hSoundDescription); - BailErr(GetMoviesError()); - - extension = NewHandle(0); - BailErr(MemError()); - - // get the "magic" decompression atom - // This extension to the SoundDescription information stores data specific to a given audio decompressor. - // Some audio decompression algorithms require a set of out-of-stream values to configure the decompressor - // which are stored in a siDecompressionParams atom. The contents of the siDecompressionParams atom are dependent - // on the sound decompressor. - err = GetSoundDescriptionExtension(hSoundDescription, &extension, siDecompressionParams); - if (noErr == err) { - size = GetHandleSize(extension); - HLock(extension); - *outAudioAtom = NewPtr(size); - BailErr(MemError()); - // copy the atom data to our Ptr... - BlockMoveData(*extension, *outAudioAtom, size); - HUnlock(extension); - } else { - // if it doesn't have an atom, that's ok - err = noErr; - } - - // set up our sound header - outSoundDesc->dataFormat = (*hSoundDescription)->dataFormat; - outSoundDesc->numChannels = (*hSoundDescription)->numChannels; - outSoundDesc->sampleSize = (*hSoundDescription)->sampleSize; - outSoundDesc->sampleRate = (*hSoundDescription)->sampleRate; - outSoundDesc->compressionID = (*hSoundDescription)->compressionID; - -bail: - if (extension) DisposeHandle(extension); - if (hSoundDescription) DisposeHandle((Handle)hSoundDescription); - - return err; -} - -// * ---------------------------- -// ConvertMovieSndTrack -// -// this function does the actual work -OSErr ConvertMovieSndTrack(const char* inFileToConvert, Movie *movie, - Media *videoMedia, Media *audioMedia, - Track *videoTrack, Track *audioTrack ) { - - SoundConverter mySoundConverter = NULL; - - Movie theSrcMovie = 0; - Media theSrcMedia = 0; - - Ptr theDecompressionParams = NULL; - Handle theCompressionParams = NULL; - - SoundDescription theSrcInputFormatInfo; - SoundDescriptionV1Handle hSoundDescription = NULL; - UnsignedFixed theOutputSampleRate; - SoundComponentData theInputFormat, - theOutputFormat; - - SCFillBufferData scFillBufferData = { NULL }; - Ptr pDecomBuffer = NULL; - - Boolean isSoundDone = false; - - OSErr err = noErr; - - int i, j; - int sindex = 0; - unsigned short pcmdata[2][512]; - unsigned short *dptr; - - // *********** SOURCE: Get sound data info from the first source movie sound track - - err = GetMovieMedia(inFileToConvert, &theSrcMovie, &theSrcMedia); - BailErr(err); - - err = GetSoundDescriptionInfo(theSrcMedia, (Ptr *)&theDecompressionParams, &theSrcInputFormatInfo); - if (noErr == err) { - // setup input format for sound converter - theInputFormat.flags = 0; - theInputFormat.format = theSrcInputFormatInfo.dataFormat; - theInputFormat.numChannels = theSrcInputFormatInfo.numChannels; - theInputFormat.sampleSize = theSrcInputFormatInfo.sampleSize; - theInputFormat.sampleRate = theSrcInputFormatInfo. sampleRate; - theInputFormat.sampleCount = 0; - theInputFormat.buffer = NULL; - theInputFormat.reserved = 0; - - theOutputFormat.flags = kNoRealtimeProcessing; - theOutputFormat.format = k16BitBigEndianFormat; - theOutputFormat.numChannels = 2; // theInputFormat.numChannels; - theOutputFormat.sampleSize = 16; - theOutputFormat.sampleRate = 44100 << 16; //theInputFormat.sampleRate; - theOutputFormat.sampleCount = 0; - theOutputFormat.buffer = NULL; - theOutputFormat.reserved = 0; - - // *********** SOUND CONVERTER: Open converter and prepare for buffer conversion...captain! - - err = SoundConverterOpen(&theInputFormat, &theOutputFormat, &mySoundConverter); - BailErr(err); - - // tell the sound converter we're cool with VBR formats -// SoundConverterSetInfo(mySoundConverter, siClientAcceptsVBR, Ptr(true)); - - // set up the sound converters compression environment - // pass down siCompressionSampleRate, siCompressionChannels then siCompressionParams - SoundConverterSetInfo(mySoundConverter, siCompressionSampleRate, &theOutputFormat.sampleRate); // ignore errors - SoundConverterSetInfo(mySoundConverter, siCompressionChannels, &theOutputFormat.numChannels); - - // set up the compression environment by passing in the 'magic' compression params aquired from - // standard sound compression eariler - if (theCompressionParams) { - HLock(theCompressionParams); - err = SoundConverterSetInfo(mySoundConverter, siCompressionParams, *theCompressionParams); - BailErr(err); - HUnlock(theCompressionParams); - } - - // set up the decompresson environment by passing in the 'magic' decompression params - if (theDecompressionParams) { - // don't check for an error, if the decompressor didn't need the - // decompression atom for whatever reason we should still be ok - SoundConverterSetInfo(mySoundConverter, siDecompressionParams, theDecompressionParams); - } - - // we need to know if the output sample rate was changed so we can write it in the image description - // few codecs (but some) will implement this - MPEG4 for example may change the output sample rate if - // the user selects a low bit rate - ignore errors - theOutputSampleRate = theOutputFormat.sampleRate; - SoundConverterGetInfo(mySoundConverter, siCompressionOutputSampleRate, &theOutputSampleRate); - - err = SoundConverterBeginConversion(mySoundConverter); - BailErr(err); - - // we need to get info about data/frame sizes - // good practice to fill in the size of this structure - CompressionInfo compressionFactor = { sizeof(compressionFactor), 0 }; - - hSoundDescription = (SoundDescriptionV1Handle)NewHandleClear(sizeof(SoundDescriptionV1)); - BailErr(MemError()); - - err = SoundConverterGetInfo(mySoundConverter, siCompressionFactor, &compressionFactor); - BailErr(err); - - HLock((Handle)hSoundDescription); - - (*hSoundDescription)->desc.descSize = sizeof(SoundDescriptionV1); - (*hSoundDescription)->desc.dataFormat = (long)theOutputFormat.format; // compression format - (*hSoundDescription)->desc.resvd1 = 0; // must be 0 - (*hSoundDescription)->desc.resvd2 = 0; // must be 0 - (*hSoundDescription)->desc.dataRefIndex = 0; // 0 - we'll let AddMediaXXX determine the index - (*hSoundDescription)->desc.version = 1; // set to 1 - (*hSoundDescription)->desc.revlevel = 0; // set to 0 - (*hSoundDescription)->desc.vendor = 0; - (*hSoundDescription)->desc.numChannels = theOutputFormat.numChannels; // number of channels - (*hSoundDescription)->desc.sampleSize = theOutputFormat.sampleSize; // bits per sample - everything but 8 bit can be set to 16 - (*hSoundDescription)->desc.compressionID = compressionFactor.compressionID; // the compression ID (eg. variableCompression) - (*hSoundDescription)->desc.packetSize = 0; // set to 0 - (*hSoundDescription)->desc.sampleRate = theOutputSampleRate; // the sample rate - // version 1 stuff - (*hSoundDescription)->samplesPerPacket = compressionFactor.samplesPerPacket; // the samples per packet holds the PCM sample count per audio frame (packet) - (*hSoundDescription)->bytesPerPacket = compressionFactor.bytesPerPacket; // the bytes per packet - - // bytesPerFrame isn't necessarily calculated for us and returned as part of the CompressionFactor - not all codecs that - // implement siCompressionFactor fill out bytesPerFrame - so we do it here - note that VBR doesn't deserve this treatment - // but it's not harmful, the Sound Manager would do calculations itself as part of GetCompressionInfo() - // It should be noted that GetCompressionInfo() doesn't work for codecs that need configuration with 'magic' settings. - // This requires explicit opening of the codec and the siCompressionFactor selector for SoundComponentGetInfo() - (*hSoundDescription)->bytesPerFrame = compressionFactor.bytesPerPacket * theOutputFormat.numChannels; - (*hSoundDescription)->bytesPerSample = compressionFactor.bytesPerSample; - - // the theCompressionParams are not necessarily present - if (theCompressionParams) { - // a Sound Description can't be locked when calling AddSoundDescriptionExtension so make sure it's unlocked - HUnlock((Handle)hSoundDescription); - err = AddSoundDescriptionExtension((SoundDescriptionHandle)hSoundDescription, theCompressionParams, siDecompressionParams); - BailErr(err); - HLock((Handle)hSoundDescription); - } - - // VBR implies a different media layout, this will affect how AddMediaSample() is called below - Boolean outputFormatIsVBR = ((*hSoundDescription)->desc.compressionID == variableCompression); - - // *********** SOUND CONVERTER: Create buffers and Convert Data - - // figure out sizes for the input and output buffers - // the input buffer has to be large enough so GetMediaSample isn't going to fail - // start with some rough numbers which should work well - UInt32 inputBytes = ((1000 + (theInputFormat.sampleRate >> 16)) * theInputFormat.numChannels) * 4, - outputBytes = 0, - maxPacketSize = 0; - - // ask about maximum packet size (or worst case packet size) so we don't allocate a destination (output) - // buffer that's too small - an output buffer smaller than MaxPacketSize would be really bad - init maxPacketSize - // to 0 so if the request isn't understood we can create a number (some multiple of maxPacketSize) and go from there - // this is likely only implemented by VBR codecs so don't get anxious about it not being implemented - SoundConverterGetInfo(mySoundConverter, siCompressionMaxPacketSize, &maxPacketSize); - - // start with this - you don't really need to use GetBufferSizes just as long as the output buffer is larger than - // the MaxPacketSize if implemented - we use kMaxBufferSize which is 64k as a minimum - SoundConverterGetBufferSizes(mySoundConverter, kMaxBufferSize, NULL, NULL, &outputBytes); - - if (0 == maxPacketSize) - maxPacketSize = kMaxBufferSize; // kMaxBufferSize is 64k - - if (inputBytes < kMaxBufferSize) // kMaxBufferSize is 64k - inputBytes = kMaxBufferSize; // note this is still too small for DV (NTSC=120000, PAL=144000) - - if (outputBytes < maxPacketSize) - outputBytes = maxPacketSize; - - // allocate conversion buffer - pDecomBuffer = NewPtr(outputBytes); - BailErr(MemError()); - - // fill in struct that gets passed to SoundConverterFillBufferDataProc via the refcon - // this includes the ExtendedSoundComponentData information - scFillBufferData.sourceMedia = theSrcMedia; - scFillBufferData.getMediaAtThisTime = 0; - scFillBufferData.sourceDuration = GetMediaDuration(theSrcMedia); - scFillBufferData.isThereMoreSource = true; - scFillBufferData.maxBufferSize = inputBytes; - - // if the source is VBR it means we're going to set the kExtendedSoundCommonFrameSizeValid - // flag and use the commonFrameSize field in the FillBuffer callback - scFillBufferData.isSourceVBR = (theSrcInputFormatInfo.compressionID == variableCompression); - - scFillBufferData.hSource = NewHandle((long)scFillBufferData.maxBufferSize); // allocate source media buffer - BailErr(MemError()); - HLockHi((Handle)scFillBufferData.hSource); - - scFillBufferData.compData.desc = theInputFormat; - scFillBufferData.compData.desc.buffer = (BytePtr)*scFillBufferData.hSource; - scFillBufferData.compData.desc.flags = kExtendedSoundData; - scFillBufferData.compData.recordSize = sizeof(ExtendedSoundComponentData); - scFillBufferData.compData.extendedFlags = kExtendedSoundBufferSizeValid; - if (scFillBufferData.isSourceVBR) scFillBufferData.compData.extendedFlags |= kExtendedSoundCommonFrameSizeValid; - scFillBufferData.compData.bufferSize = 0; // filled in during FillBuffer callback - - if (err == noErr) { - - UInt32 outputFrames, - actualOutputBytes, - outputFlags, - durationPerMediaSample, - numberOfMediaSamples; - - SoundConverterFillBufferDataUPP theFillBufferDataUPP = NewSoundConverterFillBufferDataUPP(SoundConverterFillBufferDataProc); - - while (!isSoundDone) { - printf( "."); - err = SoundConverterFillBuffer(mySoundConverter, // a sound converter - theFillBufferDataUPP, // the callback UPP - &scFillBufferData, // refCon passed to FillDataProc - pDecomBuffer, // the destination data buffer - outputBytes, // size of the destination buffer - &actualOutputBytes, // number of output bytes - &outputFrames, // number of output frames - &outputFlags); // FillBuffer retured advisor flags - if (err) break; - if((outputFlags & kSoundConverterHasLeftOverData) == false) { - isSoundDone = true; - } - - // see if output buffer is filled so we can write some data - if (actualOutputBytes > 0) { - // so, what are we going to pass to AddMediaSample? - // - // for variableCompression, a media sample == an audio packet (compressed), this is also true for uncompressed audio - // for fixedCompression, a media sample is a portion of an audio packet - it is 1 / compInfo.samplesPerPacket worth - // of data, there's no way to access just a portion of the samples - // therefore, we need to know if our compression format is VBR or Fixed and make the correct calculations for - // either VBR or not - Fixed and uncompressed are treated the same - if (outputFormatIsVBR) { - numberOfMediaSamples = outputFrames; - durationPerMediaSample = compressionFactor.samplesPerPacket; - } else { - numberOfMediaSamples = outputFrames * compressionFactor.samplesPerPacket; - durationPerMediaSample = 1; - } - - i = 0; - sindex = 0; - dptr = (unsigned short *)pDecomBuffer; - while ( i < numberOfMediaSamples ) { - for ( j = 0 ; j < 512 ; j++ ) { - pcmdata[0][j] = *dptr; - *dptr++; - pcmdata[1][j] = *dptr; - *dptr++; - i++; - } - - /** Render the frame */ - renderLoop( globalPM, pcmdata ); - - /** Stuff frame into movie */ - - /** Stuff audio into movie */ - err = - AddMediaSample( *audioMedia, pDecomBuffer, - 0, actualOutputBytes, - durationPerMediaSample, - nil, numberOfMediaSamples, - 0, nil ); - - } - -// printf( "samples: %d (%d bytes)\n", numberOfMediaSamples, actualOutputBytes ); - -// if (!fwrite(pDecomBuffer, actualOutputBytes, 1, outFile)) goto bail; - } - - } // while - - SoundConverterEndConversion(mySoundConverter, pDecomBuffer, &outputFrames, &actualOutputBytes); - - // if there's any left over data write it out - if (noErr == err && actualOutputBytes > 0) { - // see above comments regarding these calculations - if (outputFormatIsVBR) { - numberOfMediaSamples = outputFrames; - durationPerMediaSample = compressionFactor.samplesPerPacket; - } else { - numberOfMediaSamples = outputFrames * compressionFactor.samplesPerPacket; - durationPerMediaSample = 1; - } - -// if (!fwrite(pDecomBuffer, actualOutputBytes, 1, outFile)) goto bail; - - BailErr(err); - } - - if (theFillBufferDataUPP) { - DisposeSoundConverterFillBufferDataUPP(theFillBufferDataUPP); - } - } - - } - -bail: - if (mySoundConverter) - SoundConverterClose(mySoundConverter); - - if (scFillBufferData.hSource) - DisposeHandle(scFillBufferData.hSource); - - if (pDecomBuffer) - DisposePtr(pDecomBuffer); - - if (theCompressionParams) - DisposeHandle(theCompressionParams); - - if (theDecompressionParams) - DisposePtr((Ptr)theDecompressionParams); - - if (hSoundDescription) - DisposeHandle((Handle)hSoundDescription); - - if (theSrcMovie) - DisposeMovie(theSrcMovie); - - return err; -} +// +// SlimServer Copyright (C) 2003-2004 Sean Adams, Slim Devices Inc. +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License, +// version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// +// mov123 - A very basic Quicktime decoder command line application. +// +// usage: mov123 +// +// opens and decodes the first audio track from a QuickTime compatible file. This includes +// Movie files, m4a AAC files, AIFF, WAV and other formats supported natively by quicktime. +// Sends to standard out the raw uncompressed audio data in stereo 44.1kS/sec 16bit. +// Output goes to stdout +// +// Todo: - extract channel, sample rate, and sample size information from the movie for +// use in reencoding later +// - CLI options for: +// - specifying output file +// - output files for AIFF and WAV +// - changing sample rate, sample size, channel count, codec +// - usage +// - be graceful about failures +// +// Portions based on Apple's ConvertMovieSndTrack sample code. +// + +#include +#include + +//#include + + +#ifdef WIN32 +#include "stdafx.h" +#include "Movies.h" +#include "SoundComponents.h" +#include "QTML.h" +#else +#include +#include +#endif + +#include + +#define kVideoTimeScale 600 + +extern projectM_t *globalPM; + +int path2fss( FSSpec *fss, char *path ) { + char buf[256]; + char *p = &buf[1]; + strcpy( p, path ); + buf[0] = strlen( p ); + + return FSMakeFSSpec( 0, 0, (unsigned char *)buf, fss ); + } + +#define BailErr(x) {err = x; if (err != noErr) { fprintf(stderr, "Failed at line: %d\n", __LINE__); goto bail; } } + +const UInt32 kMaxBufferSize = 64 * 1024; // max size of input buffer + +// functions +OSErr ConvertMovieSndTrack( const char* inFileToConvert, Movie *movie, + Media *videoMedia, Media *audioMedia, + Track *videoTrack, Track *audioTrack ); + +typedef struct { + ExtendedSoundComponentData compData; + Handle hSource; // source media buffer + Media sourceMedia; // sound media identifier + TimeValue getMediaAtThisTime; + TimeValue sourceDuration; + + UInt32 maxBufferSize; + Boolean isThereMoreSource; + Boolean isSourceVBR; +} SCFillBufferData, *SCFillBufferDataPtr; + +FILE* outFile; + +#ifdef WIN32 +int _tmain(int argc, _TCHAR* argv[]) +#else +int main123(int argc, char *argv[]) +#endif +{ + + FSSpec theDestFSSpec; + OSErr result = 0; + OSErr err = noErr; + short resRefNum = 0; + short resId = movieInDataForkResID; + Movie newMovie; + Media audioMedia, videoMedia; + Track audioTrack, videoTrack; +// StringPtr fileName = QTUtils_ConvertCToPascalString( argv[2] ); + + outFile = stderr; + +#ifdef WIN32 + setmode(fileno(outFile), O_BINARY); + InitializeQTML(0); // Initialize QTML +#endif + EnterMovies(); + + if (argc > 2) + path2fss( &theDestFSSpec, argv[2] ); + + /** Create the new output movie */ + err = + CreateMovieFile( &theDestFSSpec, FOUR_CHAR_CODE('TV0D'), + smSystemScript, + createMovieFileDeleteCurFile | createMovieFileDontCreateResFile | newMovieActive, + &resRefNum, &newMovie ); + if ( err != noErr ) { + printf( "failed to CreateMovieFile()\n" ); + } else { + printf( "created movie ok\n" ); + } + + /** Create the video track */ + videoTrack = + NewMovieTrack( newMovie, 512, 512, kNoVolume ); + + videoMedia = + NewTrackMedia( videoTrack, VideoMediaType, kVideoTimeScale, nil, + 0 ); + + /** Establish a media edit session */ + err = BeginMediaEdits( videoMedia ); + if ( err != noErr ) { + printf( "failed to BeginMediaEdits( video )\n" ); + } else { + printf( "beginning video media edit ok\n" ); + } + + /** Create the audio track */ + audioTrack = + NewMovieTrack( newMovie, 0, 0, kFullVolume ); + audioMedia = + NewTrackMedia( audioTrack, SoundMediaType, 44000, nil, 0 ); + + err = BeginMediaEdits( audioMedia ); + if ( err != noErr ) { + printf( "failed to BeginMediaEdits( audio )\n" ); + } else { + printf( "beginning audio media edits ok\n" ); + } + + /** Convert the input sound data into a movie file with video and audio */ + result = ConvertMovieSndTrack( argv[1], &newMovie, &videoMedia, &audioMedia, + &videoTrack, &audioTrack ); + + /** End media edits */ + err = EndMediaEdits( videoMedia ); + + err = EndMediaEdits( audioMedia ); + + /** Insert the audio track into the media */ + err = InsertMediaIntoTrack( audioTrack, 0, 0, + GetMediaDuration( audioMedia ), fixed1 ); + if ( err != noErr ) { + printf( "failed to insert audio media into audio track\n" ); + } else { + printf( "injected audio media into audio track ok\n" ); + } + + /** Add the movie resource to the file */ + err = AddMovieResource( newMovie, resRefNum, &resId, argv[2] ); + if ( err != noErr ) { + printf( "failed to AddMovieResource()\n" ); + } + if ( resRefNum ) { + CloseMovieFile( resRefNum ); + } + +//bail: + if (result != 0) { fprintf(stderr, "Conversion failed with error: %d\n", result); } + return result; +} + + +#ifndef AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER + // these didn't make it into the QT6 framework for 10.1.x so include + // them here if we're not on 10.2 or later - if you have a newer framework + // or are building a carbon CFM version you shouldn't need these + enum { + scSoundVBRCompressionOK = 'cvbr', /* pointer to Boolean*/ + scSoundInputSampleRateType = 'ssir', /* pointer to UnsignedFixed*/ + scSoundSampleRateChangeOK = 'rcok', /* pointer to Boolean*/ + scAvailableCompressionListType = 'avai' /* pointer to OSType Handle*/ + }; +#endif + + +// * ---------------------------- +// SoundConverterFillBufferDataProc +// +// the callback routine that provides the SOURCE DATA for conversion - it provides data by setting +// outData to a pointer to a properly filled out ExtendedSoundComponentData structure +static pascal Boolean SoundConverterFillBufferDataProc(SoundComponentDataPtr *outData, void *inRefCon) +{ + int i, j; + + float nframes = 0; + + SCFillBufferDataPtr pFillData = (SCFillBufferDataPtr)inRefCon; + + OSErr err; + + // if after getting the last chunk of data the total time is over the duration, we're done + if (pFillData->getMediaAtThisTime >= pFillData->sourceDuration) { + pFillData->isThereMoreSource = false; + pFillData->compData.desc.buffer = NULL; + pFillData->compData.desc.sampleCount = 0; + pFillData->compData.bufferSize = 0; + pFillData->compData.commonFrameSize = 0; + } + + if (pFillData->isThereMoreSource) { + + long sourceBytesReturned; + long numberOfSamples; + TimeValue sourceReturnedTime, durationPerSample; + + // in calling GetMediaSample, we'll get a buffer that consists of equal sized frames - the + // degenerate case is only 1 frame -- for non-self-framed vbr formats (like AAC in QT 6) + // we need to provide some more framing information - either the frameCount, frameSizeArray pair or + // the commonFrameSize field must be valid -- because we always get equal sized frames, we can use + // commonFrameSize and set the kExtendedSoundCommonFrameSizeValid flag -- if there is + // only 1 frame then (common frame size == media sample size), if there are multiple frames, + // then (common frame size == media sample size / number of frames). + + err = GetMediaSample(pFillData->sourceMedia, // specifies the media for this operation + pFillData->hSource, // function returns the sample data into this handle + pFillData->maxBufferSize, // maximum number of bytes of sample data to be returned + &sourceBytesReturned, // the number of bytes of sample data returned + pFillData->getMediaAtThisTime, // starting time of the sample to be retrieved (must be in Media's TimeScale) + &sourceReturnedTime, // indicates the actual time of the returned sample data + &durationPerSample, // duration of each sample in the media + NULL, // sample description corresponding to the returned sample data (NULL to ignore) + NULL, // index value to the sample description that corresponds to the returned sample data (NULL to ignore) + 0, // maximum number of samples to be returned (0 to use a value that is appropriate for the media) + &numberOfSamples, // number of samples it actually returned + NULL); // flags that describe the sample (NULL to ignore) + + if ((noErr != err) || (sourceBytesReturned == 0)) { + pFillData->isThereMoreSource = false; + pFillData->compData.desc.buffer = NULL; + pFillData->compData.desc.sampleCount = 0; + pFillData->compData.bufferSize = 0; + pFillData->compData.commonFrameSize = 0; + + if ((err != noErr) && (sourceBytesReturned > 0)) + printf("GetMediaSample - Failed in FillBufferDataProc"); + } + + pFillData->getMediaAtThisTime = sourceReturnedTime + (durationPerSample * numberOfSamples); + + // sampleCount is the number of PCM samples + pFillData->compData.desc.sampleCount = numberOfSamples * durationPerSample; + + // kExtendedSoundBufferSizeValid was specified - make sure this field is filled in correctly + pFillData->compData.bufferSize = sourceBytesReturned; + + // for VBR audio we specified the kExtendedSoundCommonFrameSizeValid flag - make sure this field is filled in correctly + if (pFillData->isSourceVBR) pFillData->compData.commonFrameSize = sourceBytesReturned / numberOfSamples; + } + + // set outData to a properly filled out ExtendedSoundComponentData struct + *outData = (SoundComponentDataPtr)&pFillData->compData; + + return (pFillData->isThereMoreSource); +} + +// * ---------------------------- +// GetMovieMedia +// +// returns a Media identifier - if the file is a System 7 Sound a non-in-place import is done and +// a handle to the data is passed back to the caller who is responsible for disposing of it +static OSErr GetMovieMedia(const char* inFile, Movie *outMovie, Media *outMedia) +{ + Movie theMovie = 0; + Track theTrack; + short theRefNum; + short theResID = 0; // we want the first movie + OSErr err = noErr; + + BailErr(err); + + Boolean wasChanged; + + // open the movie file + if (strncmp(inFile, "http:", strlen("http:")) && + strncmp(inFile, "rtsp:", strlen("rtsp:")) && + strncmp(inFile, "ftp:", strlen("ftp:") )) { + FSSpec theFSSpec; +#ifdef WIN32 + OSErr result = NativePathNameToFSSpec((char*)inFile, &theFSSpec, 0 /* flags */); +#else + FSRef ref; // intermediate struct + FSPathMakeRef( (const UInt8*)inFile, &ref, NULL ); + OSErr result = FSGetCatalogInfo( &ref, kFSCatInfoNone , NULL, NULL, &theFSSpec, NULL); +#endif + if (result) {printf("NativePathNameToFSSpec failed on source file %s with %d\n", inFile, result); goto bail; } + err = OpenMovieFile(&theFSSpec, &theRefNum, fsRdPerm); + // instantiate the movie + BailErr(err); + err = NewMovieFromFile(&theMovie, theRefNum, &theResID, NULL, newMovieActive, &wasChanged); + CloseMovieFile(theRefNum); + } else { + + Handle urlDataRef; + + urlDataRef = NewHandle(strlen(inFile) + 1); + if ( ( err = MemError()) != noErr) goto bail; + + BlockMoveData(inFile, *urlDataRef, strlen(inFile) + 1); + + err = NewMovieFromDataRef(&theMovie, newMovieActive, nil, urlDataRef, URLDataHandlerSubType); + if (err) {printf("NewMovieFrom Data Ref failed on source file %s with %d\n", inFile, err); goto bail; } + + DisposeHandle(urlDataRef); + + } + + BailErr(err); + + // get the first sound track + theTrack = GetMovieIndTrackType(theMovie, 1, SoundMediaType, movieTrackMediaType); + if (NULL == theTrack ) BailErr(invalidTrack); + + // get and return the sound track media + *outMedia = GetTrackMedia(theTrack); + if (NULL == *outMedia) err = invalidMedia; + + *outMovie = theMovie; + +bail: + return err; +} + +// * ---------------------------- +// GetSoundDescriptionInfo +// +// this function will extract the information needed to decompress the sound file, this includes +// retrieving the sample description and the decompression atom saved as a Sample Description Extention +static OSErr GetSoundDescriptionInfo(Media inMedia, Ptr *outAudioAtom, SoundDescriptionPtr outSoundDesc) +{ + OSErr err = noErr; + + Size size; + Handle extension = NULL; + SoundDescriptionHandle hSoundDescription = (SoundDescriptionHandle)NewHandle(0); + + // get the description of the sample data + GetMediaSampleDescription(inMedia, 1, (SampleDescriptionHandle)hSoundDescription); + BailErr(GetMoviesError()); + + extension = NewHandle(0); + BailErr(MemError()); + + // get the "magic" decompression atom + // This extension to the SoundDescription information stores data specific to a given audio decompressor. + // Some audio decompression algorithms require a set of out-of-stream values to configure the decompressor + // which are stored in a siDecompressionParams atom. The contents of the siDecompressionParams atom are dependent + // on the sound decompressor. + err = GetSoundDescriptionExtension(hSoundDescription, &extension, siDecompressionParams); + if (noErr == err) { + size = GetHandleSize(extension); + HLock(extension); + *outAudioAtom = NewPtr(size); + BailErr(MemError()); + // copy the atom data to our Ptr... + BlockMoveData(*extension, *outAudioAtom, size); + HUnlock(extension); + } else { + // if it doesn't have an atom, that's ok + err = noErr; + } + + // set up our sound header + outSoundDesc->dataFormat = (*hSoundDescription)->dataFormat; + outSoundDesc->numChannels = (*hSoundDescription)->numChannels; + outSoundDesc->sampleSize = (*hSoundDescription)->sampleSize; + outSoundDesc->sampleRate = (*hSoundDescription)->sampleRate; + outSoundDesc->compressionID = (*hSoundDescription)->compressionID; + +bail: + if (extension) DisposeHandle(extension); + if (hSoundDescription) DisposeHandle((Handle)hSoundDescription); + + return err; +} + +// * ---------------------------- +// ConvertMovieSndTrack +// +// this function does the actual work +OSErr ConvertMovieSndTrack(const char* inFileToConvert, Movie *movie, + Media *videoMedia, Media *audioMedia, + Track *videoTrack, Track *audioTrack ) { + + SoundConverter mySoundConverter = NULL; + + Movie theSrcMovie = 0; + Media theSrcMedia = 0; + + Ptr theDecompressionParams = NULL; + Handle theCompressionParams = NULL; + + SoundDescription theSrcInputFormatInfo; + SoundDescriptionV1Handle hSoundDescription = NULL; + UnsignedFixed theOutputSampleRate; + SoundComponentData theInputFormat, + theOutputFormat; + + SCFillBufferData scFillBufferData = { NULL }; + Ptr pDecomBuffer = NULL; + + Boolean isSoundDone = false; + + OSErr err = noErr; + + int i, j; + int sindex = 0; + unsigned short pcmdata[2][512]; + unsigned short *dptr; + + // *********** SOURCE: Get sound data info from the first source movie sound track + + err = GetMovieMedia(inFileToConvert, &theSrcMovie, &theSrcMedia); + BailErr(err); + + err = GetSoundDescriptionInfo(theSrcMedia, (Ptr *)&theDecompressionParams, &theSrcInputFormatInfo); + if (noErr == err) { + // setup input format for sound converter + theInputFormat.flags = 0; + theInputFormat.format = theSrcInputFormatInfo.dataFormat; + theInputFormat.numChannels = theSrcInputFormatInfo.numChannels; + theInputFormat.sampleSize = theSrcInputFormatInfo.sampleSize; + theInputFormat.sampleRate = theSrcInputFormatInfo. sampleRate; + theInputFormat.sampleCount = 0; + theInputFormat.buffer = NULL; + theInputFormat.reserved = 0; + + theOutputFormat.flags = kNoRealtimeProcessing; + theOutputFormat.format = k16BitBigEndianFormat; + theOutputFormat.numChannels = 2; // theInputFormat.numChannels; + theOutputFormat.sampleSize = 16; + theOutputFormat.sampleRate = 44100 << 16; //theInputFormat.sampleRate; + theOutputFormat.sampleCount = 0; + theOutputFormat.buffer = NULL; + theOutputFormat.reserved = 0; + + // *********** SOUND CONVERTER: Open converter and prepare for buffer conversion...captain! + + err = SoundConverterOpen(&theInputFormat, &theOutputFormat, &mySoundConverter); + BailErr(err); + + // tell the sound converter we're cool with VBR formats +// SoundConverterSetInfo(mySoundConverter, siClientAcceptsVBR, Ptr(true)); + + // set up the sound converters compression environment + // pass down siCompressionSampleRate, siCompressionChannels then siCompressionParams + SoundConverterSetInfo(mySoundConverter, siCompressionSampleRate, &theOutputFormat.sampleRate); // ignore errors + SoundConverterSetInfo(mySoundConverter, siCompressionChannels, &theOutputFormat.numChannels); + + // set up the compression environment by passing in the 'magic' compression params aquired from + // standard sound compression eariler + if (theCompressionParams) { + HLock(theCompressionParams); + err = SoundConverterSetInfo(mySoundConverter, siCompressionParams, *theCompressionParams); + BailErr(err); + HUnlock(theCompressionParams); + } + + // set up the decompresson environment by passing in the 'magic' decompression params + if (theDecompressionParams) { + // don't check for an error, if the decompressor didn't need the + // decompression atom for whatever reason we should still be ok + SoundConverterSetInfo(mySoundConverter, siDecompressionParams, theDecompressionParams); + } + + // we need to know if the output sample rate was changed so we can write it in the image description + // few codecs (but some) will implement this - MPEG4 for example may change the output sample rate if + // the user selects a low bit rate - ignore errors + theOutputSampleRate = theOutputFormat.sampleRate; + SoundConverterGetInfo(mySoundConverter, siCompressionOutputSampleRate, &theOutputSampleRate); + + err = SoundConverterBeginConversion(mySoundConverter); + BailErr(err); + + // we need to get info about data/frame sizes + // good practice to fill in the size of this structure + CompressionInfo compressionFactor = { sizeof(compressionFactor), 0 }; + + hSoundDescription = (SoundDescriptionV1Handle)NewHandleClear(sizeof(SoundDescriptionV1)); + BailErr(MemError()); + + err = SoundConverterGetInfo(mySoundConverter, siCompressionFactor, &compressionFactor); + BailErr(err); + + HLock((Handle)hSoundDescription); + + (*hSoundDescription)->desc.descSize = sizeof(SoundDescriptionV1); + (*hSoundDescription)->desc.dataFormat = (long)theOutputFormat.format; // compression format + (*hSoundDescription)->desc.resvd1 = 0; // must be 0 + (*hSoundDescription)->desc.resvd2 = 0; // must be 0 + (*hSoundDescription)->desc.dataRefIndex = 0; // 0 - we'll let AddMediaXXX determine the index + (*hSoundDescription)->desc.version = 1; // set to 1 + (*hSoundDescription)->desc.revlevel = 0; // set to 0 + (*hSoundDescription)->desc.vendor = 0; + (*hSoundDescription)->desc.numChannels = theOutputFormat.numChannels; // number of channels + (*hSoundDescription)->desc.sampleSize = theOutputFormat.sampleSize; // bits per sample - everything but 8 bit can be set to 16 + (*hSoundDescription)->desc.compressionID = compressionFactor.compressionID; // the compression ID (eg. variableCompression) + (*hSoundDescription)->desc.packetSize = 0; // set to 0 + (*hSoundDescription)->desc.sampleRate = theOutputSampleRate; // the sample rate + // version 1 stuff + (*hSoundDescription)->samplesPerPacket = compressionFactor.samplesPerPacket; // the samples per packet holds the PCM sample count per audio frame (packet) + (*hSoundDescription)->bytesPerPacket = compressionFactor.bytesPerPacket; // the bytes per packet + + // bytesPerFrame isn't necessarily calculated for us and returned as part of the CompressionFactor - not all codecs that + // implement siCompressionFactor fill out bytesPerFrame - so we do it here - note that VBR doesn't deserve this treatment + // but it's not harmful, the Sound Manager would do calculations itself as part of GetCompressionInfo() + // It should be noted that GetCompressionInfo() doesn't work for codecs that need configuration with 'magic' settings. + // This requires explicit opening of the codec and the siCompressionFactor selector for SoundComponentGetInfo() + (*hSoundDescription)->bytesPerFrame = compressionFactor.bytesPerPacket * theOutputFormat.numChannels; + (*hSoundDescription)->bytesPerSample = compressionFactor.bytesPerSample; + + // the theCompressionParams are not necessarily present + if (theCompressionParams) { + // a Sound Description can't be locked when calling AddSoundDescriptionExtension so make sure it's unlocked + HUnlock((Handle)hSoundDescription); + err = AddSoundDescriptionExtension((SoundDescriptionHandle)hSoundDescription, theCompressionParams, siDecompressionParams); + BailErr(err); + HLock((Handle)hSoundDescription); + } + + // VBR implies a different media layout, this will affect how AddMediaSample() is called below + Boolean outputFormatIsVBR = ((*hSoundDescription)->desc.compressionID == variableCompression); + + // *********** SOUND CONVERTER: Create buffers and Convert Data + + // figure out sizes for the input and output buffers + // the input buffer has to be large enough so GetMediaSample isn't going to fail + // start with some rough numbers which should work well + UInt32 inputBytes = ((1000 + (theInputFormat.sampleRate >> 16)) * theInputFormat.numChannels) * 4, + outputBytes = 0, + maxPacketSize = 0; + + // ask about maximum packet size (or worst case packet size) so we don't allocate a destination (output) + // buffer that's too small - an output buffer smaller than MaxPacketSize would be really bad - init maxPacketSize + // to 0 so if the request isn't understood we can create a number (some multiple of maxPacketSize) and go from there + // this is likely only implemented by VBR codecs so don't get anxious about it not being implemented + SoundConverterGetInfo(mySoundConverter, siCompressionMaxPacketSize, &maxPacketSize); + + // start with this - you don't really need to use GetBufferSizes just as long as the output buffer is larger than + // the MaxPacketSize if implemented - we use kMaxBufferSize which is 64k as a minimum + SoundConverterGetBufferSizes(mySoundConverter, kMaxBufferSize, NULL, NULL, &outputBytes); + + if (0 == maxPacketSize) + maxPacketSize = kMaxBufferSize; // kMaxBufferSize is 64k + + if (inputBytes < kMaxBufferSize) // kMaxBufferSize is 64k + inputBytes = kMaxBufferSize; // note this is still too small for DV (NTSC=120000, PAL=144000) + + if (outputBytes < maxPacketSize) + outputBytes = maxPacketSize; + + // allocate conversion buffer + pDecomBuffer = NewPtr(outputBytes); + BailErr(MemError()); + + // fill in struct that gets passed to SoundConverterFillBufferDataProc via the refcon + // this includes the ExtendedSoundComponentData information + scFillBufferData.sourceMedia = theSrcMedia; + scFillBufferData.getMediaAtThisTime = 0; + scFillBufferData.sourceDuration = GetMediaDuration(theSrcMedia); + scFillBufferData.isThereMoreSource = true; + scFillBufferData.maxBufferSize = inputBytes; + + // if the source is VBR it means we're going to set the kExtendedSoundCommonFrameSizeValid + // flag and use the commonFrameSize field in the FillBuffer callback + scFillBufferData.isSourceVBR = (theSrcInputFormatInfo.compressionID == variableCompression); + + scFillBufferData.hSource = NewHandle((long)scFillBufferData.maxBufferSize); // allocate source media buffer + BailErr(MemError()); + HLockHi((Handle)scFillBufferData.hSource); + + scFillBufferData.compData.desc = theInputFormat; + scFillBufferData.compData.desc.buffer = (BytePtr)*scFillBufferData.hSource; + scFillBufferData.compData.desc.flags = kExtendedSoundData; + scFillBufferData.compData.recordSize = sizeof(ExtendedSoundComponentData); + scFillBufferData.compData.extendedFlags = kExtendedSoundBufferSizeValid; + if (scFillBufferData.isSourceVBR) scFillBufferData.compData.extendedFlags |= kExtendedSoundCommonFrameSizeValid; + scFillBufferData.compData.bufferSize = 0; // filled in during FillBuffer callback + + if (err == noErr) { + + UInt32 outputFrames, + actualOutputBytes, + outputFlags, + durationPerMediaSample, + numberOfMediaSamples; + + SoundConverterFillBufferDataUPP theFillBufferDataUPP = NewSoundConverterFillBufferDataUPP(SoundConverterFillBufferDataProc); + + while (!isSoundDone) { + printf( "."); + err = SoundConverterFillBuffer(mySoundConverter, // a sound converter + theFillBufferDataUPP, // the callback UPP + &scFillBufferData, // refCon passed to FillDataProc + pDecomBuffer, // the destination data buffer + outputBytes, // size of the destination buffer + &actualOutputBytes, // number of output bytes + &outputFrames, // number of output frames + &outputFlags); // FillBuffer retured advisor flags + if (err) break; + if((outputFlags & kSoundConverterHasLeftOverData) == false) { + isSoundDone = true; + } + + // see if output buffer is filled so we can write some data + if (actualOutputBytes > 0) { + // so, what are we going to pass to AddMediaSample? + // + // for variableCompression, a media sample == an audio packet (compressed), this is also true for uncompressed audio + // for fixedCompression, a media sample is a portion of an audio packet - it is 1 / compInfo.samplesPerPacket worth + // of data, there's no way to access just a portion of the samples + // therefore, we need to know if our compression format is VBR or Fixed and make the correct calculations for + // either VBR or not - Fixed and uncompressed are treated the same + if (outputFormatIsVBR) { + numberOfMediaSamples = outputFrames; + durationPerMediaSample = compressionFactor.samplesPerPacket; + } else { + numberOfMediaSamples = outputFrames * compressionFactor.samplesPerPacket; + durationPerMediaSample = 1; + } + + i = 0; + sindex = 0; + dptr = (unsigned short *)pDecomBuffer; + while ( i < numberOfMediaSamples ) { + for ( j = 0 ; j < 512 ; j++ ) { + pcmdata[0][j] = *dptr; + *dptr++; + pcmdata[1][j] = *dptr; + *dptr++; + i++; + } + + /** Render the frame */ + renderLoop( globalPM, pcmdata ); + + /** Stuff frame into movie */ + + /** Stuff audio into movie */ + err = + AddMediaSample( *audioMedia, pDecomBuffer, + 0, actualOutputBytes, + durationPerMediaSample, + nil, numberOfMediaSamples, + 0, nil ); + + } + +// printf( "samples: %d (%d bytes)\n", numberOfMediaSamples, actualOutputBytes ); + +// if (!fwrite(pDecomBuffer, actualOutputBytes, 1, outFile)) goto bail; + } + + } // while + + SoundConverterEndConversion(mySoundConverter, pDecomBuffer, &outputFrames, &actualOutputBytes); + + // if there's any left over data write it out + if (noErr == err && actualOutputBytes > 0) { + // see above comments regarding these calculations + if (outputFormatIsVBR) { + numberOfMediaSamples = outputFrames; + durationPerMediaSample = compressionFactor.samplesPerPacket; + } else { + numberOfMediaSamples = outputFrames * compressionFactor.samplesPerPacket; + durationPerMediaSample = 1; + } + +// if (!fwrite(pDecomBuffer, actualOutputBytes, 1, outFile)) goto bail; + + BailErr(err); + } + + if (theFillBufferDataUPP) { + DisposeSoundConverterFillBufferDataUPP(theFillBufferDataUPP); + } + } + + } + +bail: + if (mySoundConverter) + SoundConverterClose(mySoundConverter); + + if (scFillBufferData.hSource) + DisposeHandle(scFillBufferData.hSource); + + if (pDecomBuffer) + DisposePtr(pDecomBuffer); + + if (theCompressionParams) + DisposeHandle(theCompressionParams); + + if (theDecompressionParams) + DisposePtr((Ptr)theDecompressionParams); + + if (hSoundDescription) + DisposeHandle((Handle)hSoundDescription); + + if (theSrcMovie) + DisposeMovie(theSrcMovie); + + return err; +} diff --git a/src/projectM-moviegen/projectMmovie.c b/src/projectM-moviegen/projectMmovie.c index 50f34e116..6198e8239 100755 --- a/src/projectM-moviegen/projectMmovie.c +++ b/src/projectM-moviegen/projectMmovie.c @@ -1,260 +1,260 @@ -/** - * projectM -- Milkdrop-esque visualisation SDK - * Copyright (C)2003-2004 projectM Team - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * See 'LICENSE.txt' included within this release - * - */ - -#include -#include "projectM/projectM.h" -#include "event/sdltoprojectM.h" - -#ifdef DEBUG -FILE *debugFile = NULL; -#endif - -projectM_t *globalPM = NULL; - -int dumpFrame = 0; -int frameNumber = 0; -GLubyte *fbuffer = NULL; - -void renderLoop( projectM_t *pm, short pcm_data[2][512] ) { - - int i; - int x, y; - int index; - - /** Handle any keys... */ - projectMEvent evt; - projectMKeycode key; - projectMModifier mod; - - /** Process SDL events */ - SDL_Event event; - while ( SDL_PollEvent( &event ) ) { - /** Translate into projectM codes and process */ - evt = sdl2pmEvent( event ); - key = sdl2pmKeycode( event.key.keysym.sym ); - mod = sdl2pmModifier( event.key.keysym.mod ); - if ( evt == PROJECTM_KEYDOWN ) { - key_handler( evt, key, mod ); - } - } - - /** Add the waveform data */ - addPCM16( pcm_data ); - - /** Render the new frame */ - renderFrame( pm ); - - if ( dumpFrame ) { - char fname[1024]; - FILE *f; - sprintf( fname, "projectM_%08d.ppm", frameNumber++ ); - f = fopen( fname, "wb" ); - fprintf( f, "P3\n#\n%d %d\n255\n", pm->wvw, pm->wvh ); - glReadPixels( 0, 0, pm->wvw, pm->wvh, GL_RGB, GL_UNSIGNED_BYTE, fbuffer ); - index = 0; - for ( y = 0 ; y < pm->wvh ; y++ ) { - for ( x = 0 ; x < pm->wvw ; x++ ) { - fprintf( f, "%d %d %d ", fbuffer[index++], fbuffer[index++], fbuffer[index++] ); - } - fprintf( f, "\n" ); - } - fclose( f ); - } - - SDL_GL_SwapBuffers(); - - } - - -int main( int argc, char **argv ) { - - /** Variables */ - int fullscreen = 0; - int width = 512, - height = 512; - SDL_Surface *screen; - -#ifdef DEBUG - int value; - int rgb_size[3]; -#endif - - const SDL_VideoInfo* info = NULL; - int bpp = 0; - /* Flags we will pass into SDL_SetVideoMode. */ - int flags = 0; - -#ifdef DEBUG -#ifdef WIN32 - /** Init debug */ - debugFile = fopen( "c:\\projectMvis.txt", "wb" ); -#else - debugFile = fopen( "/tmp/projectMvis.txt", "wb" ); -#endif /** WIN32 */ -#endif /** DEBUG */ - - /** Allocate the SDL windows */ - /* Information about the current video settings. */ - /* First, initialize SDL's video subsystem. */ - if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { - /* Failed, exit. */ -#ifdef DEBUG - fprintf( debugFile, "Video initialization failed: %s\n", - SDL_GetError( ) ); -#endif - //projectM_vtable.disable_plugin (&projectM_vtable); - return PROJECTM_ERROR; - - } - - /* Let's get some video information. */ - info = SDL_GetVideoInfo( ); - if( !info ) { - /* This should probably never happen. */ -#ifdef DEBUG - fprintf( debugFile, "Video query failed: %s\n", - SDL_GetError( ) ); -#endif - // projectM_vtable.disable_plugin (&projectM_vtable); - return PROJECTM_ERROR; - } - - bpp = info->vfmt->BitsPerPixel; - -// SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); -// SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); -// SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); - - SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 8 ); - SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 8 ); - SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 8 ); - SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 ); - SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); - SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); - - if (fullscreen==0) - flags = SDL_OPENGL | SDL_HWSURFACE; - else flags = SDL_OPENGL | SDL_HWSURFACE |SDL_FULLSCREEN; - -// w = 512; h = 512; bpp = 16; -#ifdef DEBUG -fprintf( debugFile, "pre SDL_SetVideoMode()\n" ); -#endif - screen = SDL_SetVideoMode( width, height, bpp, flags ) ; -#ifdef DEBUG -fprintf( debugFile, "post SDL_SetVideoMode()\n" ); -#endif - - - if(screen == NULL ) { - /* - * This could happen for a variety of reasons, - * including DISPLAY not being set, the specified - * resolution not being available, etc. - */ -#ifdef DEBUG - fprintf( debugFile, "Video mode set failed: %s\n", - SDL_GetError( ) ); -#endif - - // projectM_vtable.disable_plugin (&projectM_vtable); - return PROJECTM_ERROR; - } - -#ifdef DEBUG - fprintf(debugFile, "Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel); - fprintf(debugFile, "\n"); - fprintf( debugFile, "Vendor : %s\n", glGetString( GL_VENDOR ) ); - fprintf( debugFile, "Renderer : %s\n", glGetString( GL_RENDERER ) ); - fprintf( debugFile, "Version : %s\n", glGetString( GL_VERSION ) ); - fprintf( debugFile, "Extensions : %s\n", glGetString( GL_EXTENSIONS ) ); - fprintf(debugFile, "\n"); - - rgb_size[0] = 8; - rgb_size[1] = 8; - rgb_size[2] = 8; - SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value ); - fprintf( debugFile, "SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0],value); - SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value ); - fprintf( debugFile, "SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1],value); - SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value ); - fprintf( debugFile, "SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2],value); - SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value ); - fprintf( debugFile, "SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value ); - SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value ); - fprintf( debugFile, "SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value ); -#ifdef PANTS - if ( fsaa ) { - SDL_GL_GetAttribute( SDL_GL_MULTISAMPLEBUFFERS, &value ); - printf( "SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value ); - SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &value ); - printf( "SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value ); - } -#endif -#endif - - /** Setup some window stuff */ - SDL_WM_SetCaption( PROJECTM_TITLE, NULL ); - - /** Initialise projectM */ - globalPM = (projectM_t *)malloc( sizeof( projectM_t ) ); - projectM_reset( globalPM ); - - globalPM->fullscreen = 0; - globalPM->renderTarget->texsize = 1024; -// globalPM->renderTarget->origCcontext = (void *)aglGetCurrentContext(); -#ifdef DEBUG - if ( debugFile != NULL ) { - fprintf( debugFile, "current context: %X\n", - globalPM->renderTarget->origContext ); - fflush( debugFile ); - } -#endif - -#ifdef MACOS - globalPM->fontURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( globalPM->fontURL, "../../fonts" ); - - globalPM->presetURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( globalPM->presetURL, "../../presets" ); -#else - globalPM->fontURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( globalPM->fontURL, "c:\\tmp\\projectM\\fonts" ); - - globalPM->presetURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( globalPM->presetURL, "c:\\tmp\\projectM\\presets_test" ); -#endif /** MACOS */ - - projectM_init( globalPM ); - - projectM_resetGL( globalPM, width, height ); - - /** Allocate the buffer for frame dumping, if applicable */ - if ( dumpFrame ) { - fbuffer = (GLubyte *)malloc( sizeof( GLubyte ) * globalPM->wvw * globalPM->wvh * 3 ); - } - - /** Initialise the thread */ -// renderLoop( globalPM ); - main123( argc, argv ); - - return PROJECTM_SUCCESS; - } +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ + +#include +#include "projectM/projectM.hpp" +#include "event/sdltoprojectM.hpp" + +#ifdef DEBUG +FILE *debugFile = NULL; +#endif + +projectM_t *globalPM = NULL; + +int dumpFrame = 0; +int frameNumber = 0; +GLubyte *fbuffer = NULL; + +void renderLoop( projectM_t *pm, short pcm_data[2][512] ) { + + int i; + int x, y; + int index; + + /** Handle any keys... */ + projectMEvent evt; + projectMKeycode key; + projectMModifier mod; + + /** Process SDL events */ + SDL_Event event; + while ( SDL_PollEvent( &event ) ) { + /** Translate into projectM codes and process */ + evt = sdl2pmEvent( event ); + key = sdl2pmKeycode( event.key.keysym.sym ); + mod = sdl2pmModifier( event.key.keysym.mod ); + if ( evt == PROJECTM_KEYDOWN ) { + key_handler( evt, key, mod ); + } + } + + /** Add the waveform data */ + addPCM16( pcm_data ); + + /** Render the new frame */ + renderFrame( pm ); + + if ( dumpFrame ) { + char fname[1024]; + FILE *f; + sprintf( fname, "projectM_%08d.ppm", frameNumber++ ); + f = fopen( fname, "wb" ); + fprintf( f, "P3\n#\n%d %d\n255\n", pm->wvw, pm->wvh ); + glReadPixels( 0, 0, pm->wvw, pm->wvh, GL_RGB, GL_UNSIGNED_BYTE, fbuffer ); + index = 0; + for ( y = 0 ; y < pm->wvh ; y++ ) { + for ( x = 0 ; x < pm->wvw ; x++ ) { + fprintf( f, "%d %d %d ", fbuffer[index++], fbuffer[index++], fbuffer[index++] ); + } + fprintf( f, "\n" ); + } + fclose( f ); + } + + SDL_GL_SwapBuffers(); + + } + + +int main( int argc, char **argv ) { + + /** Variables */ + int fullscreen = 0; + int width = 512, + height = 512; + SDL_Surface *screen; + +#ifdef DEBUG + int value; + int rgb_size[3]; +#endif + + const SDL_VideoInfo* info = NULL; + int bpp = 0; + /* Flags we will pass into SDL_SetVideoMode. */ + int flags = 0; + +#ifdef DEBUG +#ifdef WIN32 + /** Init debug */ + debugFile = fopen( "c:\\projectMvis.txt", "wb" ); +#else + debugFile = fopen( "/tmp/projectMvis.txt", "wb" ); +#endif /** WIN32 */ +#endif /** DEBUG */ + + /** Allocate the SDL windows */ + /* Information about the current video settings. */ + /* First, initialize SDL's video subsystem. */ + if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { + /* Failed, exit. */ +#ifdef DEBUG + fprintf( debugFile, "Video initialization failed: %s\n", + SDL_GetError( ) ); +#endif + //projectM_vtable.disable_plugin (&projectM_vtable); + return PROJECTM_ERROR; + + } + + /* Let's get some video information. */ + info = SDL_GetVideoInfo( ); + if( !info ) { + /* This should probably never happen. */ +#ifdef DEBUG + fprintf( debugFile, "Video query failed: %s\n", + SDL_GetError( ) ); +#endif + // projectM_vtable.disable_plugin (&projectM_vtable); + return PROJECTM_ERROR; + } + + bpp = info->vfmt->BitsPerPixel; + +// SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); +// SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); +// SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); + + SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 8 ); + SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 8 ); + SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 8 ); + SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 ); + SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); + + if (fullscreen==0) + flags = SDL_OPENGL | SDL_HWSURFACE; + else flags = SDL_OPENGL | SDL_HWSURFACE |SDL_FULLSCREEN; + +// w = 512; h = 512; bpp = 16; +#ifdef DEBUG +fprintf( debugFile, "pre SDL_SetVideoMode()\n" ); +#endif + screen = SDL_SetVideoMode( width, height, bpp, flags ) ; +#ifdef DEBUG +fprintf( debugFile, "post SDL_SetVideoMode()\n" ); +#endif + + + if(screen == NULL ) { + /* + * This could happen for a variety of reasons, + * including DISPLAY not being set, the specified + * resolution not being available, etc. + */ +#ifdef DEBUG + fprintf( debugFile, "Video mode set failed: %s\n", + SDL_GetError( ) ); +#endif + + // projectM_vtable.disable_plugin (&projectM_vtable); + return PROJECTM_ERROR; + } + +#ifdef DEBUG + fprintf(debugFile, "Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel); + fprintf(debugFile, "\n"); + fprintf( debugFile, "Vendor : %s\n", glGetString( GL_VENDOR ) ); + fprintf( debugFile, "Renderer : %s\n", glGetString( GL_RENDERER ) ); + fprintf( debugFile, "Version : %s\n", glGetString( GL_VERSION ) ); + fprintf( debugFile, "Extensions : %s\n", glGetString( GL_EXTENSIONS ) ); + fprintf(debugFile, "\n"); + + rgb_size[0] = 8; + rgb_size[1] = 8; + rgb_size[2] = 8; + SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value ); + fprintf( debugFile, "SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0],value); + SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value ); + fprintf( debugFile, "SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1],value); + SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value ); + fprintf( debugFile, "SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2],value); + SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value ); + fprintf( debugFile, "SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value ); + SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value ); + fprintf( debugFile, "SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value ); +#ifdef PANTS + if ( fsaa ) { + SDL_GL_GetAttribute( SDL_GL_MULTISAMPLEBUFFERS, &value ); + printf( "SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value ); + SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &value ); + printf( "SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value ); + } +#endif +#endif + + /** Setup some window stuff */ + SDL_WM_SetCaption( PROJECTM_TITLE, NULL ); + + /** Initialise projectM */ + globalPM = (projectM_t *)malloc( sizeof( projectM_t ) ); + projectM_reset( globalPM ); + + globalPM->fullscreen = 0; + globalPM->renderTarget->texsize = 1024; +// globalPM->renderTarget->origCcontext = (void *)aglGetCurrentContext(); +#ifdef DEBUG + if ( debugFile != NULL ) { + fprintf( debugFile, "current context: %X\n", + globalPM->renderTarget->origContext ); + fflush( debugFile ); + } +#endif + +#ifdef MACOS + globalPM->fontURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( globalPM->fontURL, "../../fonts" ); + + globalPM->presetURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( globalPM->presetURL, "../../presets" ); +#else + globalPM->fontURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( globalPM->fontURL, "c:\\tmp\\projectM\\fonts" ); + + globalPM->presetURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( globalPM->presetURL, "c:\\tmp\\projectM\\presets_test" ); +#endif /** MACOS */ + + projectM_init( globalPM ); + + projectM_resetGL( globalPM, width, height ); + + /** Allocate the buffer for frame dumping, if applicable */ + if ( dumpFrame ) { + fbuffer = (GLubyte *)malloc( sizeof( GLubyte ) * globalPM->wvw * globalPM->wvh * 3 ); + } + + /** Initialise the thread */ +// renderLoop( globalPM ); + main123( argc, argv ); + + return PROJECTM_SUCCESS; + } diff --git a/src/projectM-screensaver/wprojectMsaver.cpp b/src/projectM-screensaver/wprojectMsaver.cpp index 4b8d954a6..e2b2130d9 100755 --- a/src/projectM-screensaver/wprojectMsaver.cpp +++ b/src/projectM-screensaver/wprojectMsaver.cpp @@ -1,518 +1,518 @@ -/** - * projectM -- Milkdrop-esque visualisation SDK - * Copyright (C)2003-2004 projectM Team - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * See 'LICENSE.txt' included within this release - * - */ -/** - * $Id: wprojectMsaver.cpp,v 1.4 2004/11/15 15:09:44 cvs Exp $ - * - * projectM-based screensaver for Windows - * - */ - -#include -#include -#include -#include -#include "resource.h" -#include "tsaver.h" -#ifdef WIN32 -extern "C" { -#include - } -#endif /** WIN32 */ - -#ifdef DEBUG -FILE *debugFile = NULL; -#endif - -//#pragma warning(disable: 4800) -//#pragma warning(disable: 4305) -//#pragma warning(disable: 4244) - -HINSTANCE hInstance=NULL; -HWND hScrWindow=NULL; - -TSaverSettings *ss=NULL; - -/** Name */ -TCHAR szAppName[32]; - -/** Visualiser */ -projectM_t *globalPM = NULL; - -void initGL(int width, int height) -{ - projectM_resetGL( globalPM, width, height ); - - switchPreset( RANDOM_NEXT, HARD_CUT ); -} - -void display() { - - int i; - short pcm_data[2][512]; - - /** Produce some fake PCM data to stuff into projectM */ - if ( globalPM->count % 5 == 0 ) { - for ( i = 0 ; i < 512 ; i++ ) { - pcm_data[0][i] = 0; - pcm_data[1][i] = 0; - } - } else { - for ( i = 0 ; i < 512 ; i++ ) { - if ( i % 2 == 0 ) { - pcm_data[0][i] = (float)( rand() / ( (float)RAND_MAX ) * (pow(2,i%14) ) ); - pcm_data[1][i] = (float)( rand() / ( (float)RAND_MAX ) * (pow(2,i/2%14) ) ); - } else { - pcm_data[0][i] = (float)( rand() / ( (float)RAND_MAX ) * (pow(2,i/2%14) ) ); - pcm_data[1][i] = (float)( rand() / ( (float)RAND_MAX ) * (pow(2,i%14) ) ); - } - if ( i % 2 == 1 ) { - pcm_data[0][i] = -pcm_data[0][i]; - pcm_data[1][i] = -pcm_data[1][i]; - } - } - } - - /** Add the waveform data */ - addPCM16( pcm_data ); - - /** Render the new frame */ - renderFrame( globalPM ); - } - -BOOL VerifyPassword(HWND hwnd) -{ - // Under NT, we return true immediately. This lets the saver quit, and the system manages passwords. - // Under '95, we call VerifyScreenSavePwd. This checks the appropriate registry key and, if necessary, pops up a verify dialog - OSVERSIONINFO osv; - osv.dwOSVersionInfoSize = sizeof(osv); - - GetVersionEx(&osv); - - if( osv.dwPlatformId==VER_PLATFORM_WIN32_NT ) - return true; - - HINSTANCE hpwdcpl = ::LoadLibrary("PASSWORD.CPL"); - if( hpwdcpl==NULL ) - return true; - - typedef BOOL (WINAPI *VERIFYSCREENSAVEPWD)(HWND hwnd); - VERIFYSCREENSAVEPWD VerifyScreenSavePwd; - VerifyScreenSavePwd = (VERIFYSCREENSAVEPWD)GetProcAddress(hpwdcpl,"VerifyScreenSavePwd"); - - if( VerifyScreenSavePwd==NULL ) - { - FreeLibrary(hpwdcpl); - return true; - } - - BOOL bres = VerifyScreenSavePwd(hwnd); - FreeLibrary(hpwdcpl); - return bres; -} - -void ChangePassword(HWND hwnd) -{ - // This only ever gets called under '95, when started with the /a option. - HINSTANCE hmpr = ::LoadLibrary("MPR.DLL"); - if( hmpr==NULL ) - return; - - typedef VOID (WINAPI *PWDCHANGEPASSWORD) (LPCSTR lpcRegkeyname,HWND hwnd,UINT uiReserved1,UINT uiReserved2); - PWDCHANGEPASSWORD PwdChangePassword=(PWDCHANGEPASSWORD)::GetProcAddress(hmpr,"PwdChangePasswordA"); - if( PwdChangePassword==NULL ) - { - FreeLibrary(hmpr); - return; - } - - PwdChangePassword("SCRSAVE",hwnd,0,0); FreeLibrary(hmpr); -} - - -LRESULT CALLBACK SaverWindowProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) -{ - // If you have a problem that's really not going away, put a debug in here: - // Debug(MessageName(msg)); - // This will make a log of every single message that gets sent to the window. - static PAINTSTRUCT ps; - switch (msg) - { - case WM_CREATE: - { - ss->hwnd=hwnd; - GetCursorPos(&(ss->InitCursorPos)); - ss->InitTime=GetTickCount(); - } break; - case WM_ACTIVATE: - case WM_ACTIVATEAPP: - case WM_NCACTIVATE: - { - if( ScrMode==smSaver && !ss->IsDialogActive && LOWORD(wParam)==WA_INACTIVE ) - ss->CloseSaverWindow(); - } break; - case WM_SETCURSOR: - { - if( ScrMode==smSaver && !ss->IsDialogActive ) - SetCursor(NULL); - else - SetCursor(LoadCursor(NULL,IDC_ARROW)); - } break; - case WM_LBUTTONDOWN: - case WM_MBUTTONDOWN: - case WM_RBUTTONDOWN: - case WM_KEYDOWN: - { -#ifdef DEBUG - fprintf( debugFile, "key: %d\n", (int)wParam ); - fflush( debugFile ); -#endif - if ( ScrMode == smSaver && !ss->IsDialogActive ) { - if ( (int)wParam == 'R' ) { - switchPreset( RANDOM_NEXT, HARD_CUT ); - } else { - if ( (int)wParam == 'N' ) { - switchPreset( ALPHA_NEXT, HARD_CUT ); - } else { - if ( (int)wParam == 'P' ) { - switchPreset( ALPHA_PREVIOUS, HARD_CUT ); - } - } - } - } else { - ss->CloseSaverWindow(); - } - } break; - case WM_MOUSEMOVE: - { - if( ScrMode==smSaver && !ss->IsDialogActive ) - { - POINT pt; - GetCursorPos(&pt); - int dx = pt.x-ss->InitCursorPos.x; - if( dx<0 ) - dx = -dx; - int dy = pt.y-ss->InitCursorPos.y; - if( dy<0 ) - dy = -dy; - if( dx>(int)ss->MouseThreshold || dy>(int)ss->MouseThreshold ) - ss->CloseSaverWindow(); - } - } break; - case (WM_SYSCOMMAND): - { - if( ScrMode==smSaver ) - { - if( wParam==SC_SCREENSAVE ) - return false; - if( wParam==SC_CLOSE ) - return false; - } - } break; - case (WM_CLOSE): - { - if( ScrMode==smSaver && ss->ReallyClose && !ss->IsDialogActive ) - { - BOOL CanClose = true; - if( GetTickCount()-ss->InitTime > 1000*ss->PasswordDelay ) - { - ss->StartDialog(); - CanClose = VerifyPassword(hwnd); - ss->EndDialog(); - } - if( CanClose ) - DestroyWindow(hwnd); - } - if( ScrMode==smSaver ) - return false; // so that DefWindowProc doesn't get called, because it would just DestroyWindow - } break; - case (WM_DESTROY): - { - if( ss->idTimer!=0 ) - KillTimer(hwnd,ss->idTimer); - ss->idTimer=0; - PostQuitMessage(0); - } break; - } - return DefWindowProc(hwnd,msg,wParam,lParam); -} - -void DoSaver(HWND hparwnd, int nCmdShow) -{ - WNDCLASS wc; - wc.style=CS_HREDRAW | CS_VREDRAW | CS_OWNDC; - wc.lpfnWndProc = SaverWindowProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = hInstance; - wc.hIcon = NULL; - wc.hCursor = NULL; - wc.hbrBackground = NULL; - wc.lpszMenuName = NULL; - wc.lpszClassName = "OpenGL"; - - if( !RegisterClass(&wc) ) { - MessageBox(NULL, "RegisterClass() failed: " - "Cannot register window class.", "Error", MB_OK); - return; - } - - int cx, cy; - if( ScrMode==smPreview ) - { - RECT rc; - GetWindowRect(hparwnd,&rc); - cx = rc.right - rc.left; - cy = rc.bottom - rc.top; - hScrWindow = - CreateWindow("OpenGL", "SaverWindow", WS_CHILD|WS_VISIBLE,0, 0, cx, cy, hparwnd, NULL, hInstance, NULL); - } - else - { - cx = GetSystemMetrics(SM_CXSCREEN); - cy = GetSystemMetrics(SM_CYSCREEN); - DWORD exstyle, style; - - exstyle = WS_EX_TOPMOST; - style = WS_POPUP|WS_VISIBLE; - - hScrWindow = CreateWindow ("OpenGL", "SaverWindow", style,0, 0, cx, cy, NULL, NULL, hInstance, NULL); - - } - - if( hScrWindow==NULL ) - return; - - UINT oldval; - - if( ScrMode==smSaver ) - SystemParametersInfo(SPI_SCREENSAVERRUNNING,1,&oldval,0); - - HDC hDC = ::GetDC(hScrWindow); - - PIXELFORMATDESCRIPTOR pfd; - memset(&pfd, 0, sizeof(pfd)); - pfd.nSize = sizeof(pfd); - pfd.nVersion = 1; - pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; - pfd.iPixelType = PFD_TYPE_RGBA; - pfd.cColorBits = 32; - - int pf = ChoosePixelFormat(hDC, &pfd); - if (pf == 0) { - MessageBox(NULL, "ChoosePixelFormat() failed: " - "Cannot find a suitable pixel format.", "Error", MB_OK); - return; - } - - if (SetPixelFormat(hDC, pf, &pfd) == FALSE) { - MessageBox(NULL, "SetPixelFormat() failed: " - "Cannot set format specified.", "Error", MB_OK); - return; - } - - DescribePixelFormat(hDC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd); - - HGLRC hRC = wglCreateContext(hDC); - wglMakeCurrent(hDC, hRC); - - initGL(cx, cy); - - ShowWindow(hScrWindow, nCmdShow); - - MSG msg; - - bool done = false; - while(!done) // Loop That Runs While done=FALSE - { - if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting? - { - if (msg.message==WM_QUIT) // Have We Received A Quit Message? - done=TRUE; // If So done=TRUE - else // If Not, Deal With Window Messages - { - TranslateMessage(&msg); // Translate The Message - DispatchMessage(&msg); // Dispatch The Message - } - } - else // If There Are No Messages - { -// display(cx, cy ); - display(); - SwapBuffers(hDC); // Swap Buffers (Double Buffering) - - //Sleep(10); - } - } - - wglMakeCurrent(NULL, NULL); - ReleaseDC(hScrWindow, hDC); - wglDeleteContext(hRC); - - if( ScrMode==smSaver ) - SystemParametersInfo(SPI_SCREENSAVERRUNNING,0,&oldval,0); - return; -} - -BOOL CALLBACK ConfigDialogProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) -{ - switch (msg) - { - case WM_INITDIALOG: - { - CheckDlgButton(hwnd,IDC_FLASH,ss->Rotate); - return true; - } - case WM_COMMAND: - { - int id=LOWORD(wParam); - if( id==IDOK ) - { - ss->Rotate = (IsDlgButtonChecked(hwnd,IDC_FLASH)==BST_CHECKED); - ss->WriteConfigRegistry(); - } - if( id==IDOK || id==IDCANCEL ) - EndDialog(hwnd,id); - } break; - } - return false; -} - -int WINAPI WinMain(HINSTANCE h, HINSTANCE,LPSTR,int nCmdShow) -{ - hInstance = h; - - LoadString( hInstance, IDS_APPNAME, szAppName, 31 ); - - char *c = GetCommandLine(); - if(*c == '\"' ) - { - c++; - while( *c!=0 && *c!='\"' ) - c++; - } - else - { - while( *c!=0 && *c!=' ' ) - c++; - } - - if( *c!=0 ) - c++; - - while( *c==' ' ) - c++; - - HWND hwnd=NULL; - if( *c==0 ) - { - ScrMode = smConfig; - hwnd=NULL; - } - else - { - if( *c=='-' || *c=='/' ) - c++; - if( *c=='p' || *c=='P' || *c=='l' || *c=='L' ) - { - c++; - while( *c==' ' || *c==':' ) - c++; - hwnd = (HWND)atoi(c); - - ScrMode = smPreview; - } - else if( *c=='s' || *c=='S' ) - { - ScrMode=smSaver; - } - else if( *c=='c' || *c=='C' ) - { - c++; - while( *c==' ' || *c==':' ) - c++; - if( *c==0 ) - hwnd = GetForegroundWindow(); - else - hwnd = (HWND)atoi(c); - ScrMode = smConfig; - } - else if( *c=='a' || *c=='A' ) - { - c++; - while( *c==' ' || *c==':' ) - c++; - hwnd = (HWND)atoi(c); - ScrMode = smPassword; - } - } - - /** Set the app name */ -// LoadString( hInstance, IDS_APPNAME, szAppName, 31 ); - - // We create a global TSaverSettings here, for convenience. It will get used by the config dialog and - // by the saver as it runs - ss = new TSaverSettings(); - ss->ReadGeneralRegistry(); - ss->ReadConfigRegistry(); - - if( ScrMode==smPassword ) - ChangePassword(hwnd); - if( ScrMode==smConfig ) - DialogBox(hInstance,MAKEINTRESOURCE(DLG_CONFIG),hwnd,ConfigDialogProc); - if( ScrMode == smSaver || ScrMode==smPreview ) { - -#ifdef DEBUG - debugFile = fopen( "c:\\wprojectMsaver.txt", "w" ); -#endif - - /** Initialise projectM */ - globalPM = (projectM_t *)wipemalloc( sizeof( projectM_t ) ); - projectM_reset( globalPM ); - -#ifdef DEBUG - fprintf( debugFile, "here1\n" ); - fflush( debugFile ); -#endif - - globalPM->fullscreen = 0; - globalPM->texsize = 512; - - globalPM->fontURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( globalPM->fontURL, "c:\\Program Files\\projectM\\fonts" ); - - globalPM->presetURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( globalPM->presetURL, "c:\\Program Files\\projectM\\presets" ); - - projectM_init( globalPM ); - -#ifdef DEBUG - fprintf( debugFile, "here2\n" ); - fflush( debugFile ); -#endif - - DoSaver(hwnd, nCmdShow); - } - delete ss; - - return 0; -} - - +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: wprojectMsaver.cpp,v 1.4 2004/11/15 15:09:44 cvs Exp $ + * + * projectM-based screensaver for Windows + * + */ + +#include +#include +#include +#include +#include "resource.h" +#include "tsaver.h" +#ifdef WIN32 +extern "C" { +#include + } +#endif /** WIN32 */ + +#ifdef DEBUG +FILE *debugFile = NULL; +#endif + +//#pragma warning(disable: 4800) +//#pragma warning(disable: 4305) +//#pragma warning(disable: 4244) + +HINSTANCE hInstance=NULL; +HWND hScrWindow=NULL; + +TSaverSettings *ss=NULL; + +/** Name */ +TCHAR szAppName[32]; + +/** Visualiser */ +projectM_t *globalPM = NULL; + +void initGL(int width, int height) +{ + projectM_resetGL( globalPM, width, height ); + + switchPreset( RANDOM_NEXT, HARD_CUT ); +} + +void display() { + + int i; + short pcm_data[2][512]; + + /** Produce some fake PCM data to stuff into projectM */ + if ( globalPM->count % 5 == 0 ) { + for ( i = 0 ; i < 512 ; i++ ) { + pcm_data[0][i] = 0; + pcm_data[1][i] = 0; + } + } else { + for ( i = 0 ; i < 512 ; i++ ) { + if ( i % 2 == 0 ) { + pcm_data[0][i] = (float)( rand() / ( (float)RAND_MAX ) * (pow(2,i%14) ) ); + pcm_data[1][i] = (float)( rand() / ( (float)RAND_MAX ) * (pow(2,i/2%14) ) ); + } else { + pcm_data[0][i] = (float)( rand() / ( (float)RAND_MAX ) * (pow(2,i/2%14) ) ); + pcm_data[1][i] = (float)( rand() / ( (float)RAND_MAX ) * (pow(2,i%14) ) ); + } + if ( i % 2 == 1 ) { + pcm_data[0][i] = -pcm_data[0][i]; + pcm_data[1][i] = -pcm_data[1][i]; + } + } + } + + /** Add the waveform data */ + addPCM16( pcm_data ); + + /** Render the new frame */ + renderFrame( globalPM ); + } + +BOOL VerifyPassword(HWND hwnd) +{ + // Under NT, we return true immediately. This lets the saver quit, and the system manages passwords. + // Under '95, we call VerifyScreenSavePwd. This checks the appropriate registry key and, if necessary, pops up a verify dialog + OSVERSIONINFO osv; + osv.dwOSVersionInfoSize = sizeof(osv); + + GetVersionEx(&osv); + + if( osv.dwPlatformId==VER_PLATFORM_WIN32_NT ) + return true; + + HINSTANCE hpwdcpl = ::LoadLibrary("PASSWORD.CPL"); + if( hpwdcpl==NULL ) + return true; + + typedef BOOL (WINAPI *VERIFYSCREENSAVEPWD)(HWND hwnd); + VERIFYSCREENSAVEPWD VerifyScreenSavePwd; + VerifyScreenSavePwd = (VERIFYSCREENSAVEPWD)GetProcAddress(hpwdcpl,"VerifyScreenSavePwd"); + + if( VerifyScreenSavePwd==NULL ) + { + FreeLibrary(hpwdcpl); + return true; + } + + BOOL bres = VerifyScreenSavePwd(hwnd); + FreeLibrary(hpwdcpl); + return bres; +} + +void ChangePassword(HWND hwnd) +{ + // This only ever gets called under '95, when started with the /a option. + HINSTANCE hmpr = ::LoadLibrary("MPR.DLL"); + if( hmpr==NULL ) + return; + + typedef VOID (WINAPI *PWDCHANGEPASSWORD) (LPCSTR lpcRegkeyname,HWND hwnd,UINT uiReserved1,UINT uiReserved2); + PWDCHANGEPASSWORD PwdChangePassword=(PWDCHANGEPASSWORD)::GetProcAddress(hmpr,"PwdChangePasswordA"); + if( PwdChangePassword==NULL ) + { + FreeLibrary(hmpr); + return; + } + + PwdChangePassword("SCRSAVE",hwnd,0,0); FreeLibrary(hmpr); +} + + +LRESULT CALLBACK SaverWindowProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) +{ + // If you have a problem that's really not going away, put a debug in here: + // Debug(MessageName(msg)); + // This will make a log of every single message that gets sent to the window. + static PAINTSTRUCT ps; + switch (msg) + { + case WM_CREATE: + { + ss->hwnd=hwnd; + GetCursorPos(&(ss->InitCursorPos)); + ss->InitTime=GetTickCount(); + } break; + case WM_ACTIVATE: + case WM_ACTIVATEAPP: + case WM_NCACTIVATE: + { + if( ScrMode==smSaver && !ss->IsDialogActive && LOWORD(wParam)==WA_INACTIVE ) + ss->CloseSaverWindow(); + } break; + case WM_SETCURSOR: + { + if( ScrMode==smSaver && !ss->IsDialogActive ) + SetCursor(NULL); + else + SetCursor(LoadCursor(NULL,IDC_ARROW)); + } break; + case WM_LBUTTONDOWN: + case WM_MBUTTONDOWN: + case WM_RBUTTONDOWN: + case WM_KEYDOWN: + { +#ifdef DEBUG + fprintf( debugFile, "key: %d\n", (int)wParam ); + fflush( debugFile ); +#endif + if ( ScrMode == smSaver && !ss->IsDialogActive ) { + if ( (int)wParam == 'R' ) { + switchPreset( RANDOM_NEXT, HARD_CUT ); + } else { + if ( (int)wParam == 'N' ) { + switchPreset( ALPHA_NEXT, HARD_CUT ); + } else { + if ( (int)wParam == 'P' ) { + switchPreset( ALPHA_PREVIOUS, HARD_CUT ); + } + } + } + } else { + ss->CloseSaverWindow(); + } + } break; + case WM_MOUSEMOVE: + { + if( ScrMode==smSaver && !ss->IsDialogActive ) + { + POINT pt; + GetCursorPos(&pt); + int dx = pt.x-ss->InitCursorPos.x; + if( dx<0 ) + dx = -dx; + int dy = pt.y-ss->InitCursorPos.y; + if( dy<0 ) + dy = -dy; + if( dx>(int)ss->MouseThreshold || dy>(int)ss->MouseThreshold ) + ss->CloseSaverWindow(); + } + } break; + case (WM_SYSCOMMAND): + { + if( ScrMode==smSaver ) + { + if( wParam==SC_SCREENSAVE ) + return false; + if( wParam==SC_CLOSE ) + return false; + } + } break; + case (WM_CLOSE): + { + if( ScrMode==smSaver && ss->ReallyClose && !ss->IsDialogActive ) + { + BOOL CanClose = true; + if( GetTickCount()-ss->InitTime > 1000*ss->PasswordDelay ) + { + ss->StartDialog(); + CanClose = VerifyPassword(hwnd); + ss->EndDialog(); + } + if( CanClose ) + DestroyWindow(hwnd); + } + if( ScrMode==smSaver ) + return false; // so that DefWindowProc doesn't get called, because it would just DestroyWindow + } break; + case (WM_DESTROY): + { + if( ss->idTimer!=0 ) + KillTimer(hwnd,ss->idTimer); + ss->idTimer=0; + PostQuitMessage(0); + } break; + } + return DefWindowProc(hwnd,msg,wParam,lParam); +} + +void DoSaver(HWND hparwnd, int nCmdShow) +{ + WNDCLASS wc; + wc.style=CS_HREDRAW | CS_VREDRAW | CS_OWNDC; + wc.lpfnWndProc = SaverWindowProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = hInstance; + wc.hIcon = NULL; + wc.hCursor = NULL; + wc.hbrBackground = NULL; + wc.lpszMenuName = NULL; + wc.lpszClassName = "OpenGL"; + + if( !RegisterClass(&wc) ) { + MessageBox(NULL, "RegisterClass() failed: " + "Cannot register window class.", "Error", MB_OK); + return; + } + + int cx, cy; + if( ScrMode==smPreview ) + { + RECT rc; + GetWindowRect(hparwnd,&rc); + cx = rc.right - rc.left; + cy = rc.bottom - rc.top; + hScrWindow = + CreateWindow("OpenGL", "SaverWindow", WS_CHILD|WS_VISIBLE,0, 0, cx, cy, hparwnd, NULL, hInstance, NULL); + } + else + { + cx = GetSystemMetrics(SM_CXSCREEN); + cy = GetSystemMetrics(SM_CYSCREEN); + DWORD exstyle, style; + + exstyle = WS_EX_TOPMOST; + style = WS_POPUP|WS_VISIBLE; + + hScrWindow = CreateWindow ("OpenGL", "SaverWindow", style,0, 0, cx, cy, NULL, NULL, hInstance, NULL); + + } + + if( hScrWindow==NULL ) + return; + + UINT oldval; + + if( ScrMode==smSaver ) + SystemParametersInfo(SPI_SCREENSAVERRUNNING,1,&oldval,0); + + HDC hDC = ::GetDC(hScrWindow); + + PIXELFORMATDESCRIPTOR pfd; + memset(&pfd, 0, sizeof(pfd)); + pfd.nSize = sizeof(pfd); + pfd.nVersion = 1; + pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.cColorBits = 32; + + int pf = ChoosePixelFormat(hDC, &pfd); + if (pf == 0) { + MessageBox(NULL, "ChoosePixelFormat() failed: " + "Cannot find a suitable pixel format.", "Error", MB_OK); + return; + } + + if (SetPixelFormat(hDC, pf, &pfd) == FALSE) { + MessageBox(NULL, "SetPixelFormat() failed: " + "Cannot set format specified.", "Error", MB_OK); + return; + } + + DescribePixelFormat(hDC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd); + + HGLRC hRC = wglCreateContext(hDC); + wglMakeCurrent(hDC, hRC); + + initGL(cx, cy); + + ShowWindow(hScrWindow, nCmdShow); + + MSG msg; + + bool done = false; + while(!done) // Loop That Runs While done=FALSE + { + if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting? + { + if (msg.message==WM_QUIT) // Have We Received A Quit Message? + done=TRUE; // If So done=TRUE + else // If Not, Deal With Window Messages + { + TranslateMessage(&msg); // Translate The Message + DispatchMessage(&msg); // Dispatch The Message + } + } + else // If There Are No Messages + { +// display(cx, cy ); + display(); + SwapBuffers(hDC); // Swap Buffers (Double Buffering) + + //Sleep(10); + } + } + + wglMakeCurrent(NULL, NULL); + ReleaseDC(hScrWindow, hDC); + wglDeleteContext(hRC); + + if( ScrMode==smSaver ) + SystemParametersInfo(SPI_SCREENSAVERRUNNING,0,&oldval,0); + return; +} + +BOOL CALLBACK ConfigDialogProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) +{ + switch (msg) + { + case WM_INITDIALOG: + { + CheckDlgButton(hwnd,IDC_FLASH,ss->Rotate); + return true; + } + case WM_COMMAND: + { + int id=LOWORD(wParam); + if( id==IDOK ) + { + ss->Rotate = (IsDlgButtonChecked(hwnd,IDC_FLASH)==BST_CHECKED); + ss->WriteConfigRegistry(); + } + if( id==IDOK || id==IDCANCEL ) + EndDialog(hwnd,id); + } break; + } + return false; +} + +int WINAPI WinMain(HINSTANCE h, HINSTANCE,LPSTR,int nCmdShow) +{ + hInstance = h; + + LoadString( hInstance, IDS_APPNAME, szAppName, 31 ); + + char *c = GetCommandLine(); + if(*c == '\"' ) + { + c++; + while( *c!=0 && *c!='\"' ) + c++; + } + else + { + while( *c!=0 && *c!=' ' ) + c++; + } + + if( *c!=0 ) + c++; + + while( *c==' ' ) + c++; + + HWND hwnd=NULL; + if( *c==0 ) + { + ScrMode = smConfig; + hwnd=NULL; + } + else + { + if( *c=='-' || *c=='/' ) + c++; + if( *c=='p' || *c=='P' || *c=='l' || *c=='L' ) + { + c++; + while( *c==' ' || *c==':' ) + c++; + hwnd = (HWND)atoi(c); + + ScrMode = smPreview; + } + else if( *c=='s' || *c=='S' ) + { + ScrMode=smSaver; + } + else if( *c=='c' || *c=='C' ) + { + c++; + while( *c==' ' || *c==':' ) + c++; + if( *c==0 ) + hwnd = GetForegroundWindow(); + else + hwnd = (HWND)atoi(c); + ScrMode = smConfig; + } + else if( *c=='a' || *c=='A' ) + { + c++; + while( *c==' ' || *c==':' ) + c++; + hwnd = (HWND)atoi(c); + ScrMode = smPassword; + } + } + + /** Set the app name */ +// LoadString( hInstance, IDS_APPNAME, szAppName, 31 ); + + // We create a global TSaverSettings here, for convenience. It will get used by the config dialog and + // by the saver as it runs + ss = new TSaverSettings(); + ss->ReadGeneralRegistry(); + ss->ReadConfigRegistry(); + + if( ScrMode==smPassword ) + ChangePassword(hwnd); + if( ScrMode==smConfig ) + DialogBox(hInstance,MAKEINTRESOURCE(DLG_CONFIG),hwnd,ConfigDialogProc); + if( ScrMode == smSaver || ScrMode==smPreview ) { + +#ifdef DEBUG + debugFile = fopen( "c:\\wprojectMsaver.txt", "w" ); +#endif + + /** Initialise projectM */ + globalPM = (projectM_t *)wipemalloc( sizeof( projectM_t ) ); + projectM_reset( globalPM ); + +#ifdef DEBUG + fprintf( debugFile, "here1\n" ); + fflush( debugFile ); +#endif + + globalPM->fullscreen = 0; + globalPM->texsize = 512; + + globalPM->fontURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( globalPM->fontURL, "c:\\Program Files\\projectM\\fonts" ); + + globalPM->presetURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( globalPM->presetURL, "c:\\Program Files\\projectM\\presets" ); + + projectM_init( globalPM ); + +#ifdef DEBUG + fprintf( debugFile, "here2\n" ); + fflush( debugFile ); +#endif + + DoSaver(hwnd, nCmdShow); + } + delete ss; + + return 0; +} + + diff --git a/src/projectM-sdlvis/projectMvis.cc b/src/projectM-sdlvis/projectMvis.cc index 82f80d33f..3c0c52970 100755 --- a/src/projectM-sdlvis/projectMvis.cc +++ b/src/projectM-sdlvis/projectMvis.cc @@ -1,293 +1,293 @@ -/** - * projectM -- Milkdrop-esque visualisation SDK - * Copyright (C)2003-2004 projectM Team - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * See 'LICENSE.txt' included within this release - * - */ - -#include -#include -#include - -#ifdef DEBUG -FILE *debugFile = NULL; -#endif - -projectM *globalPM = NULL; - -int dumpFrame = 0; -int frameNumber = 0; -GLubyte *fbuffer = NULL; - -extern void addPCM16(short [2][512]); - -void renderLoop( projectM *pm ) { - - int i; - int x, y; - int index; - short pcm_data[2][512]; - - while ( 1 ) { - projectMEvent evt; - projectMKeycode key; - projectMModifier mod; - - /** Process SDL events */ - SDL_Event event; - while ( SDL_PollEvent( &event ) ) { - /** Translate into projectM codes and process */ - evt = sdl2pmEvent( event ); - key = sdl2pmKeycode( event.key.keysym.sym ); - mod = sdl2pmModifier( event.key.keysym.mod ); - if ( evt == PROJECTM_KEYDOWN ) { - pm->key_handler( evt, key, mod ); - } - } - - /** Produce some fake PCM data to stuff into projectM */ - if ( pm->count % 5 == 0 ) { - for ( i = 0 ; i < 512 ; i++ ) { - pcm_data[0][i] = 0; - pcm_data[1][i] = 0; - } - } else { - for ( i = 0 ; i < 512 ; i++ ) { - if ( i % 2 == 0 ) { - pcm_data[0][i] = (float)( rand() / ( (float)RAND_MAX ) * (pow(2,14) ) ); - pcm_data[1][i] = (float)( rand() / ( (float)RAND_MAX ) * (pow(2,14) ) ); - } else { - pcm_data[0][i] = (float)( rand() / ( (float)RAND_MAX ) * (pow(2,14) ) ); - pcm_data[1][i] = (float)( rand() / ( (float)RAND_MAX ) * (pow(2,14) ) ); - } - if ( i % 2 == 1 ) { - pcm_data[0][i] = -pcm_data[0][i]; - pcm_data[1][i] = -pcm_data[1][i]; - } - } - } - - /** Add the waveform data */ - //addPCM16( pcm_data ); - - /** Render the new frame */ - pm->renderFrame(); - - if ( dumpFrame ) { - char fname[1024]; - FILE *f; - sprintf( fname, "projectM_%08d.ppm", frameNumber++ ); - f = fopen( fname, "wb" ); - fprintf( f, "P3\n#\n%d %d\n255\n", pm->wvw, pm->wvh ); - glReadPixels( 0, 0, pm->wvw, pm->wvh, GL_RGB, GL_UNSIGNED_BYTE, fbuffer ); - index = 0; - for ( y = 0 ; y < pm->wvh ; y++ ) { - for ( x = 0 ; x < pm->wvw ; x++ ) { - fprintf( f, "%d %d %d ", fbuffer[index++], fbuffer[index++], fbuffer[index++] ); - } - fprintf( f, "\n" ); - } - fclose( f ); - } - - SDL_GL_SwapBuffers(); - } - - printf("Worker thread: Exiting\n"); - } - - -int main( int argc, char *argv[] ) { - - /** Variables */ - int fullscreen = 0; - int width = 784, - height = 784; - SDL_Surface *screen; - -#ifdef DEBUG - int value; - int rgb_size[3]; -#endif - - const SDL_VideoInfo* info = NULL; - int bpp = 0; - /* Flags we will pass into SDL_SetVideoMode. */ - int flags = 0; - -#ifdef DEBUG -#ifdef WIN32 - /** Init debug */ - debugFile = fopen( "c:\\projectMvis.txt", "wb" ); -#else - debugFile = fopen( "/tmp/projectMvis.txt", "wb" ); -#endif /** WIN32 */ -#endif /** DEBUG */ - - /** Allocate the SDL windows */ - /* Information about the current video settings. */ - /* First, initialize SDL's video subsystem. */ - if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { - /* Failed, exit. */ -#ifdef DEBUG - fprintf( debugFile, "Video initialization failed: %s\n", - SDL_GetError( ) ); -#endif - //projectM_vtable.disable_plugin (&projectM_vtable); - return PROJECTM_ERROR; - - } - - /* Let's get some video information. */ - info = SDL_GetVideoInfo( ); - if( !info ) { - /* This should probably never happen. */ -#ifdef DEBUG - fprintf( debugFile, "Video query failed: %s\n", - SDL_GetError( ) ); -#endif - // projectM_vtable.disable_plugin (&projectM_vtable); - return PROJECTM_ERROR; - } - - bpp = info->vfmt->BitsPerPixel; - -// SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); -// SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); -// SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); - - //SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 8 ); - // SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 8 ); - // SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 8 ); - SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 ); - SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); - SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); - - if (fullscreen==0) - flags = SDL_OPENGL | SDL_HWSURFACE; - else flags = SDL_OPENGL | SDL_HWSURFACE |SDL_FULLSCREEN; - -// w = 512; h = 512; bpp = 16; -#ifdef DEBUG -fprintf( debugFile, "pre SDL_SetVideoMode()\n" ); -#endif - screen = SDL_SetVideoMode( width, height, bpp, flags ) ; -#ifdef DEBUG -fprintf( debugFile, "post SDL_SetVideoMode()\n" ); -#endif - - - if(screen == NULL ) { - /* - * This could happen for a variety of reasons, - * including DISPLAY not being set, the specified - * resolution not being available, etc. - */ -#ifdef DEBUG - fprintf( debugFile, "Video mode set failed: %s\n", - SDL_GetError( ) ); -#endif - - // projectM_vtable.disable_plugin (&projectM_vtable); - return PROJECTM_ERROR; - } - -#ifdef DEBUG - fprintf(debugFile, "Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel); - fprintf(debugFile, "\n"); - fprintf( debugFile, "Vendor : %s\n", glGetString( GL_VENDOR ) ); - fprintf( debugFile, "Renderer : %s\n", glGetString( GL_RENDERER ) ); - fprintf( debugFile, "Version : %s\n", glGetString( GL_VERSION ) ); - fprintf( debugFile, "Extensions : %s\n", glGetString( GL_EXTENSIONS ) ); - fprintf(debugFile, "\n"); - - rgb_size[0] = 8; - rgb_size[1] = 8; - rgb_size[2] = 8; - SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value ); - fprintf( debugFile, "SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0],value); - SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value ); - fprintf( debugFile, "SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1],value); - SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value ); - fprintf( debugFile, "SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2],value); - SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value ); - fprintf( debugFile, "SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value ); - SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value ); - fprintf( debugFile, "SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value ); -#ifdef PANTS - if ( fsaa ) { - SDL_GL_GetAttribute( SDL_GL_MULTISAMPLEBUFFERS, &value ); - printf( "SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value ); - SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &value ); - printf( "SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value ); - } -#endif -#endif - - /** Setup some window stuff */ - SDL_WM_SetCaption( PROJECTM_TITLE, NULL ); - - /** Initialise projectM */ - globalPM = (projectM *)malloc( sizeof( projectM ) ); - globalPM->projectM_reset(); - - globalPM->fullscreen = 0; -// globalPM->renderTarget->texsize = 1024; -// globalPM->renderTarget->context1 = (void *)aglGetCurrentContext(); -#ifdef DEBUG22 - if ( debugFile != NULL ) { - fprintf( debugFile, "current context: %X\n", - globalPM->renderTarget->context1 ); - fflush( debugFile ); - } -#endif - -#ifdef MACOS - globalPM->fontURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( globalPM->fontURL, "../../fonts" ); - - globalPM->presetURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( globalPM->presetURL, "../../presets" ); -#endif -#ifdef WIN32 - globalPM->fontURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( globalPM->fontURL, "c:\\tmp\\projectM\\fonts" ); - - globalPM->presetURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( globalPM->presetURL, "c:\\tmp\\projectM\\presets_test" ); -#endif -#ifdef LINUX - globalPM->fontURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( globalPM->fontURL, "/etc/projectM/fonts" ); - - globalPM->presetURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( globalPM->presetURL, "/etc/projectM/presets" ); -#endif - globalPM->projectM_init(); - - globalPM->projectM_resetGL( width, height ); - - /** Allocate the buffer for frame dumping, if applicable */ - if ( dumpFrame ) { - fbuffer = (GLubyte *)malloc( sizeof( GLubyte ) * globalPM->wvw * globalPM->wvh * 3 ); - } - - /** Initialise the thread */ - renderLoop( globalPM ); - - return PROJECTM_SUCCESS; - } +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ + +#include +#include +#include + +#ifdef DEBUG +FILE *debugFile = NULL; +#endif + +projectM *globalPM = NULL; + +int dumpFrame = 0; +int frameNumber = 0; +GLubyte *fbuffer = NULL; + +extern void addPCM16(short [2][512]); + +void renderLoop( projectM *pm ) { + + int i; + int x, y; + int index; + short pcm_data[2][512]; + + while ( 1 ) { + projectMEvent evt; + projectMKeycode key; + projectMModifier mod; + + /** Process SDL events */ + SDL_Event event; + while ( SDL_PollEvent( &event ) ) { + /** Translate into projectM codes and process */ + evt = sdl2pmEvent( event ); + key = sdl2pmKeycode( event.key.keysym.sym ); + mod = sdl2pmModifier( event.key.keysym.mod ); + if ( evt == PROJECTM_KEYDOWN ) { + pm->key_handler( evt, key, mod ); + } + } + + /** Produce some fake PCM data to stuff into projectM */ + if ( pm->count % 5 == 0 ) { + for ( i = 0 ; i < 512 ; i++ ) { + pcm_data[0][i] = 0; + pcm_data[1][i] = 0; + } + } else { + for ( i = 0 ; i < 512 ; i++ ) { + if ( i % 2 == 0 ) { + pcm_data[0][i] = (float)( rand() / ( (float)RAND_MAX ) * (pow(2,14) ) ); + pcm_data[1][i] = (float)( rand() / ( (float)RAND_MAX ) * (pow(2,14) ) ); + } else { + pcm_data[0][i] = (float)( rand() / ( (float)RAND_MAX ) * (pow(2,14) ) ); + pcm_data[1][i] = (float)( rand() / ( (float)RAND_MAX ) * (pow(2,14) ) ); + } + if ( i % 2 == 1 ) { + pcm_data[0][i] = -pcm_data[0][i]; + pcm_data[1][i] = -pcm_data[1][i]; + } + } + } + + /** Add the waveform data */ + //addPCM16( pcm_data ); + + /** Render the new frame */ + pm->renderFrame(); + + if ( dumpFrame ) { + char fname[1024]; + FILE *f; + sprintf( fname, "projectM_%08d.ppm", frameNumber++ ); + f = fopen( fname, "wb" ); + fprintf( f, "P3\n#\n%d %d\n255\n", pm->wvw, pm->wvh ); + glReadPixels( 0, 0, pm->wvw, pm->wvh, GL_RGB, GL_UNSIGNED_BYTE, fbuffer ); + index = 0; + for ( y = 0 ; y < pm->wvh ; y++ ) { + for ( x = 0 ; x < pm->wvw ; x++ ) { + fprintf( f, "%d %d %d ", fbuffer[index++], fbuffer[index++], fbuffer[index++] ); + } + fprintf( f, "\n" ); + } + fclose( f ); + } + + SDL_GL_SwapBuffers(); + } + + printf("Worker thread: Exiting\n"); + } + + +int main( int argc, char *argv[] ) { + + /** Variables */ + int fullscreen = 0; + int width = 784, + height = 784; + SDL_Surface *screen; + +#ifdef DEBUG + int value; + int rgb_size[3]; +#endif + + const SDL_VideoInfo* info = NULL; + int bpp = 0; + /* Flags we will pass into SDL_SetVideoMode. */ + int flags = 0; + +#ifdef DEBUG +#ifdef WIN32 + /** Init debug */ + debugFile = fopen( "c:\\projectMvis.txt", "wb" ); +#else + debugFile = fopen( "/tmp/projectMvis.txt", "wb" ); +#endif /** WIN32 */ +#endif /** DEBUG */ + + /** Allocate the SDL windows */ + /* Information about the current video settings. */ + /* First, initialize SDL's video subsystem. */ + if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { + /* Failed, exit. */ +#ifdef DEBUG + fprintf( debugFile, "Video initialization failed: %s\n", + SDL_GetError( ) ); +#endif + //projectM_vtable.disable_plugin (&projectM_vtable); + return PROJECTM_ERROR; + + } + + /* Let's get some video information. */ + info = SDL_GetVideoInfo( ); + if( !info ) { + /* This should probably never happen. */ +#ifdef DEBUG + fprintf( debugFile, "Video query failed: %s\n", + SDL_GetError( ) ); +#endif + // projectM_vtable.disable_plugin (&projectM_vtable); + return PROJECTM_ERROR; + } + + bpp = info->vfmt->BitsPerPixel; + +// SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); +// SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); +// SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); + + //SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 8 ); + // SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 8 ); + // SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 8 ); + SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 ); + SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); + + if (fullscreen==0) + flags = SDL_OPENGL | SDL_HWSURFACE; + else flags = SDL_OPENGL | SDL_HWSURFACE |SDL_FULLSCREEN; + +// w = 512; h = 512; bpp = 16; +#ifdef DEBUG +fprintf( debugFile, "pre SDL_SetVideoMode()\n" ); +#endif + screen = SDL_SetVideoMode( width, height, bpp, flags ) ; +#ifdef DEBUG +fprintf( debugFile, "post SDL_SetVideoMode()\n" ); +#endif + + + if(screen == NULL ) { + /* + * This could happen for a variety of reasons, + * including DISPLAY not being set, the specified + * resolution not being available, etc. + */ +#ifdef DEBUG + fprintf( debugFile, "Video mode set failed: %s\n", + SDL_GetError( ) ); +#endif + + // projectM_vtable.disable_plugin (&projectM_vtable); + return PROJECTM_ERROR; + } + +#ifdef DEBUG + fprintf(debugFile, "Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel); + fprintf(debugFile, "\n"); + fprintf( debugFile, "Vendor : %s\n", glGetString( GL_VENDOR ) ); + fprintf( debugFile, "Renderer : %s\n", glGetString( GL_RENDERER ) ); + fprintf( debugFile, "Version : %s\n", glGetString( GL_VERSION ) ); + fprintf( debugFile, "Extensions : %s\n", glGetString( GL_EXTENSIONS ) ); + fprintf(debugFile, "\n"); + + rgb_size[0] = 8; + rgb_size[1] = 8; + rgb_size[2] = 8; + SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value ); + fprintf( debugFile, "SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0],value); + SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value ); + fprintf( debugFile, "SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1],value); + SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value ); + fprintf( debugFile, "SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2],value); + SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value ); + fprintf( debugFile, "SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value ); + SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value ); + fprintf( debugFile, "SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value ); +#ifdef PANTS + if ( fsaa ) { + SDL_GL_GetAttribute( SDL_GL_MULTISAMPLEBUFFERS, &value ); + printf( "SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value ); + SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &value ); + printf( "SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value ); + } +#endif +#endif + + /** Setup some window stuff */ + SDL_WM_SetCaption( PROJECTM_TITLE, NULL ); + + /** Initialise projectM */ + globalPM = (projectM *)malloc( sizeof( projectM ) ); + globalPM->projectM_reset(); + + globalPM->fullscreen = 0; +// globalPM->renderTarget->texsize = 1024; +// globalPM->renderTarget->context1 = (void *)aglGetCurrentContext(); +#ifdef DEBUG22 + if ( debugFile != NULL ) { + fprintf( debugFile, "current context: %X\n", + globalPM->renderTarget->context1 ); + fflush( debugFile ); + } +#endif + +#ifdef MACOS + globalPM->fontURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( globalPM->fontURL, "../../fonts" ); + + globalPM->presetURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( globalPM->presetURL, "../../presets" ); +#endif +#ifdef WIN32 + globalPM->fontURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( globalPM->fontURL, "c:\\tmp\\projectM\\fonts" ); + + globalPM->presetURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( globalPM->presetURL, "c:\\tmp\\projectM\\presets_test" ); +#endif +#ifdef LINUX + globalPM->fontURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( globalPM->fontURL, "/etc/projectM/fonts" ); + + globalPM->presetURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( globalPM->presetURL, "/etc/projectM/presets" ); +#endif + globalPM->projectM_init(); + + globalPM->projectM_resetGL( width, height ); + + /** Allocate the buffer for frame dumping, if applicable */ + if ( dumpFrame ) { + fbuffer = (GLubyte *)malloc( sizeof( GLubyte ) * globalPM->wvw * globalPM->wvh * 3 ); + } + + /** Initialise the thread */ + renderLoop( globalPM ); + + return PROJECTM_SUCCESS; + } diff --git a/src/projectM-sdlvis/sdltoprojectM.h b/src/projectM-sdlvis/sdltoprojectM.h index dd9e77e38..1628fdbd2 100755 --- a/src/projectM-sdlvis/sdltoprojectM.h +++ b/src/projectM-sdlvis/sdltoprojectM.h @@ -1,165 +1,165 @@ -/** - * projectM -- Milkdrop-esque visualisation SDK - * Copyright (C)2003-2007 projectM Team - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * See 'LICENSE.txt' included within this release - * - */ -/** - * $Id: sdltoprojectM.h,v 1.1 2004/10/08 00:35:28 cvs Exp $ - * - * Translates SDL -> projectM variables - * - * $Log: sdltoprojectM.h,v $ - * Revision 1.1 2004/10/08 00:35:28 cvs - * Moved and imported - * - * Revision 1.1.1.1 2004/10/04 12:56:00 cvs - * Imported - * - */ - -#ifndef _SDLTOPROJECTM_H -#define _SDLTOPROJECTM_H - -#include "event.h" - - //#include "projectM/projectM.h" -#ifdef WIN32 -#include -#else -#include -#endif - -projectMEvent sdl2pmEvent( SDL_Event event ) { \ - - switch ( event.type ) { \ - case SDL_VIDEORESIZE: - return PROJECTM_VIDEORESIZE; \ - case SDL_KEYUP: \ - return PROJECTM_KEYUP; \ - case SDL_KEYDOWN: \ - return PROJECTM_KEYDOWN; \ - default: - return PROJECTM_KEYUP; \ - } \ - } \ - -projectMKeycode sdl2pmKeycode( SDLKey keysym ) { \ - switch ( keysym ) { \ - case SDLK_F1: \ - return PROJECTM_K_F1; \ - case SDLK_F2: \ - return PROJECTM_K_F2; \ - case SDLK_F3: \ - return PROJECTM_K_F3; \ - case SDLK_F4: \ - return PROJECTM_K_F4; \ - case SDLK_F5: \ - return PROJECTM_K_F5; \ - case SDLK_F6: \ - return PROJECTM_K_F6; \ - case SDLK_F7: \ - return PROJECTM_K_F7; \ - case SDLK_F8: \ - return PROJECTM_K_F8; \ - case SDLK_F9: \ - return PROJECTM_K_F9; \ - case SDLK_F10: \ - return PROJECTM_K_F10; \ - case SDLK_F11: \ - return PROJECTM_K_F11; \ - case SDLK_F12: \ - return PROJECTM_K_F12; \ - case SDLK_ESCAPE: \ - return PROJECTM_K_ESCAPE; - case SDLK_a: - return PROJECTM_K_a; - case SDLK_b: - return PROJECTM_K_b; - case SDLK_c: - return PROJECTM_K_c; - case SDLK_d: - return PROJECTM_K_d; - case SDLK_e: - return PROJECTM_K_e; - case SDLK_f: - return PROJECTM_K_f; - case SDLK_g: - return PROJECTM_K_g; - case SDLK_h: - return PROJECTM_K_h; - case SDLK_i: - return PROJECTM_K_i; - case SDLK_j: - return PROJECTM_K_j; - case SDLK_k: - return PROJECTM_K_k; - case SDLK_l: - return PROJECTM_K_l; - case SDLK_m: - return PROJECTM_K_m; - case SDLK_n: - return PROJECTM_K_n; - case SDLK_o: - return PROJECTM_K_o; - case SDLK_p: - return PROJECTM_K_p; - case SDLK_q: - return PROJECTM_K_q; - case SDLK_r: - return PROJECTM_K_r; - case SDLK_s: - return PROJECTM_K_s; - case SDLK_t: - return PROJECTM_K_t; - case SDLK_u: - return PROJECTM_K_u; - case SDLK_v: - return PROJECTM_K_v; - case SDLK_w: - return PROJECTM_K_w; - case SDLK_x: - return PROJECTM_K_x; - case SDLK_y: - return PROJECTM_K_y; - case SDLK_z: - return PROJECTM_K_z; - case SDLK_UP: - return PROJECTM_K_UP; - case SDLK_RETURN: - return PROJECTM_K_RETURN; - case SDLK_RIGHT: - return PROJECTM_K_RIGHT; - case SDLK_LEFT: - return PROJECTM_K_LEFT; - case SDLK_DOWN: - return PROJECTM_K_DOWN; - case SDLK_PAGEUP: - return PROJECTM_K_PAGEUP; - case SDLK_PAGEDOWN: - return PROJECTM_K_PAGEDOWN; - - default: \ - return PROJECTM_K_NONE; \ - } \ - } \ - -projectMModifier sdl2pmModifier( SDLMod mod ) { \ - return PROJECTM_KMOD_LSHIFT; \ - } \ - -#endif /** _SDLTOPROJECTM_H */ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: sdltoprojectM.hpp,v 1.1 2004/10/08 00:35:28 cvs Exp $ + * + * Translates SDL -> projectM variables + * + * $Log: sdltoprojectM.hpp,v $ + * Revision 1.1 2004/10/08 00:35:28 cvs + * Moved and imported + * + * Revision 1.1.1.1 2004/10/04 12:56:00 cvs + * Imported + * + */ + +#ifndef _SDLTOPROJECTM_H +#define _SDLTOPROJECTM_H + +#include "event.h" + + //#include "projectM/projectM.hpp" +#ifdef WIN32 +#include +#else +#include +#endif + +projectMEvent sdl2pmEvent( SDL_Event event ) { \ + + switch ( event.type ) { \ + case SDL_VIDEORESIZE: + return PROJECTM_VIDEORESIZE; \ + case SDL_KEYUP: \ + return PROJECTM_KEYUP; \ + case SDL_KEYDOWN: \ + return PROJECTM_KEYDOWN; \ + default: + return PROJECTM_KEYUP; \ + } \ + } \ + +projectMKeycode sdl2pmKeycode( SDLKey keysym ) { \ + switch ( keysym ) { \ + case SDLK_F1: \ + return PROJECTM_K_F1; \ + case SDLK_F2: \ + return PROJECTM_K_F2; \ + case SDLK_F3: \ + return PROJECTM_K_F3; \ + case SDLK_F4: \ + return PROJECTM_K_F4; \ + case SDLK_F5: \ + return PROJECTM_K_F5; \ + case SDLK_F6: \ + return PROJECTM_K_F6; \ + case SDLK_F7: \ + return PROJECTM_K_F7; \ + case SDLK_F8: \ + return PROJECTM_K_F8; \ + case SDLK_F9: \ + return PROJECTM_K_F9; \ + case SDLK_F10: \ + return PROJECTM_K_F10; \ + case SDLK_F11: \ + return PROJECTM_K_F11; \ + case SDLK_F12: \ + return PROJECTM_K_F12; \ + case SDLK_ESCAPE: \ + return PROJECTM_K_ESCAPE; + case SDLK_a: + return PROJECTM_K_a; + case SDLK_b: + return PROJECTM_K_b; + case SDLK_c: + return PROJECTM_K_c; + case SDLK_d: + return PROJECTM_K_d; + case SDLK_e: + return PROJECTM_K_e; + case SDLK_f: + return PROJECTM_K_f; + case SDLK_g: + return PROJECTM_K_g; + case SDLK_h: + return PROJECTM_K_h; + case SDLK_i: + return PROJECTM_K_i; + case SDLK_j: + return PROJECTM_K_j; + case SDLK_k: + return PROJECTM_K_k; + case SDLK_l: + return PROJECTM_K_l; + case SDLK_m: + return PROJECTM_K_m; + case SDLK_n: + return PROJECTM_K_n; + case SDLK_o: + return PROJECTM_K_o; + case SDLK_p: + return PROJECTM_K_p; + case SDLK_q: + return PROJECTM_K_q; + case SDLK_r: + return PROJECTM_K_r; + case SDLK_s: + return PROJECTM_K_s; + case SDLK_t: + return PROJECTM_K_t; + case SDLK_u: + return PROJECTM_K_u; + case SDLK_v: + return PROJECTM_K_v; + case SDLK_w: + return PROJECTM_K_w; + case SDLK_x: + return PROJECTM_K_x; + case SDLK_y: + return PROJECTM_K_y; + case SDLK_z: + return PROJECTM_K_z; + case SDLK_UP: + return PROJECTM_K_UP; + case SDLK_RETURN: + return PROJECTM_K_RETURN; + case SDLK_RIGHT: + return PROJECTM_K_RIGHT; + case SDLK_LEFT: + return PROJECTM_K_LEFT; + case SDLK_DOWN: + return PROJECTM_K_DOWN; + case SDLK_PAGEUP: + return PROJECTM_K_PAGEUP; + case SDLK_PAGEDOWN: + return PROJECTM_K_PAGEDOWN; + + default: \ + return PROJECTM_K_NONE; \ + } \ + } \ + +projectMModifier sdl2pmModifier( SDLMod mod ) { \ + return PROJECTM_KMOD_LSHIFT; \ + } \ + +#endif /** _SDLTOPROJECTM_H */ diff --git a/src/projectM-wxvis/wxvisApp.cpp b/src/projectM-wxvis/wxvisApp.cpp index 185963e68..46a566415 100755 --- a/src/projectM-wxvis/wxvisApp.cpp +++ b/src/projectM-wxvis/wxvisApp.cpp @@ -1,172 +1,172 @@ -/** - * projectM -- Milkdrop-esque visualisation SDK - * Copyright (C)2003-2004 projectM Team - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * See 'LICENSE.txt' included within this release - * - */ -/** - * $Id: wxvisApp.cpp,v 1.6 2004/11/12 15:47:27 cvs Exp $ - * - */ - -#include -#include -#include - -#include "wxvisApp.h" -#include "wxvisFrame.h" -#include "wxvisCanvas.h" - -#ifdef DEBUG -FILE *debugFile = NULL; -#endif - -projectM *globalPM = NULL; - -IMPLEMENT_APP(wxvisApp) - -BEGIN_EVENT_TABLE(wxvisApp,wxApp) - EVT_IDLE(wxvisApp::OnIdle) -END_EVENT_TABLE() - -/** Parse command-line options and create the main wxvis windows */ -bool wxvisApp::OnInit() { - -#ifdef DEBUG -#ifndef WIN32 - /** Open the debug file */ - debugFile = fopen( "/tmp/wxvis.txt", "w" ); -#else - /** Open the debug file */ - debugFile = fopen( "c:\\wxvis.txt", "w" ); -#endif /** __WXMAC__ */ -#else -// debugFile = NULL; -#endif - -#ifdef WIN32 - /** Retrieve the key from the registry for the base installation directory */ - installationRoot = (unsigned char *)malloc( sizeof( unsigned char ) * 1024 ); - installationRoot[0] = '\0'; - HKEY key; - if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Archaeoptics\\wxvis3D", - 0, KEY_QUERY_VALUE, &key ) != ERROR_SUCCESS ) { -// MessageBox( NULL, "Failed to open registry key: SOFTWARE\\Archaeoptics\\wxvis\nHelp and NPR textures may be unavailable!", "projectM", MB_OK | MB_ICONEXCLAMATION ); - sprintf( (char *)installationRoot, "%s", "c:\\Program Files\\Archaeoptics\\wxvis3D" ); - } else { - DWORD installRootType = REG_SZ; - DWORD installRootSize = 1024; - LONG rv = RegQueryValueEx( key, "InstallRoot", NULL, &installRootType, installationRoot, &installRootSize ); - if ( rv != ERROR_SUCCESS ) { - /** This section causes things to crash weirdly... */ -// MessageBox( NULL, "Failed to query registry key: SOFTWARE\\Archaeoptics\\wxvis\nHelp and textures may be unavailable!", "projectM", MB_OK | MB_ICONEXCLAMATION ); -/* char msg[128]; - sprintf( msg, "Error code: %d", rv ); - wxMessageBox( msg, "projectM", wxOK | wxICON_EXCLAMATION ); */ - sprintf( (char *)installationRoot, "%s", "c:\\Program Files\\Archaeoptics\\wxvis3D" ); - } - RegCloseKey( key ); - } - -#ifdef DEBUG2 - fprintf( debugFile, "Installation Root: %s\n", installationRoot ); - fflush( debugFile ); -#endif /** DEBUG */ -#else - installationRoot = NULL; -#endif /** WIN32 */ - - /** Empty out various structures before initialisation */ - _visFrame = NULL; - - /** Load the icon */ - _icon = wxIcon( "ARCHAEOPTICS_ICON" ); - - /** Create the rendering frame */ - wxPoint pt; - wxSize sz; - pt.x = 50; pt.y = 50; - sz.x = 640; sz.y = 480; - _visFrame = new wxvisFrame( this, wxString( "projectM" ), pt, sz ); - _visFrame->canvas = new wxvisCanvas( _visFrame ); - _visFrame->SetIcon( _icon ); - _visFrame->Show( TRUE ); - - /** Check depth and stencil capabilities */ - int depthBits = _visFrame->canvas->getDepthBits(); - int stencilBits = _visFrame->canvas->getStencilBits(); - if ( depthBits < 24 || stencilBits < 1 ) { - char msg[256]; - sprintf( msg, "Depth and stencil bit settings are sub-optimal\nBlack and White Ink Rendering and Elevation Extraction\nmay not work correctly\nDepth Bits: %d\nStencil Bits: %d\n(Should be at least 24 and 1)", depthBits, stencilBits ); -// wxMessageBox( msg, "projectM", wxOK | wxICON_EXCLAMATION ); - } - -#ifdef WIN32 - /** Update file associations */ - /** Create the base wxvis key */ - int rv; - rv = RegCreateKey( HKEY_CLASSES_ROOT, "projectM", &rootAssociationKey ); - rv = RegSetValue( rootAssociationKey, "", REG_SZ, "MilkDrop Preset", 0 ); - - /** This sets the command line for "projectM" */ - char exename[256]; - sprintf( exename, "%s\\wxvis.exe %%1", installationRoot ); - rv = RegCreateKey( HKEY_CLASSES_ROOT, "projectM", &rootAssociationKey ); - rv = RegSetValue( rootAssociationKey, "shell\\open\\command", REG_SZ, exename, MAX_PATH ); - - /** Set the icon */ - char iconname[256]; - sprintf( iconname, "%s\\archaeoptics_icon_64x64.ico", installationRoot ); - rv = RegCreateKey( HKEY_CLASSES_ROOT, "projectM", &rootAssociationKey ); - rv = RegSetValue( rootAssociationKey, "DefaultIcon", REG_SZ, iconname, MAX_PATH ); -#endif - - /** Check for a model name on the command line */ -#ifdef DEBUG2 - fprintf( debugFile, "argc: %d\n", argc ); - fflush( debugFile ); -#endif - if ( argc >= 2 ) { - if ( ( strstr( argv[1], ".milk" ) != NULL ) || - ( strstr( argv[1], ".MILK" ) != NULL ) ) { - /** Load a fixed preset */ - } - } - - return TRUE; - } - -/** Shuts down the application */ -void wxvisApp::shutdown() { - /** Free local resources */ - if ( _visFrame ) { - _visFrame->canvas->Destroy(); - _visFrame->Destroy(); - } - -#ifdef DEBUG2 - fclose( debugFile ); -#endif /** DEBUG */ - - exit( 0 ); - } - -void wxvisApp::OnIdle( wxIdleEvent &event ) { - if ( _visFrame ) { - _visFrame->canvas->Refresh( FALSE ); - } - } +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: wxvisApp.cpp,v 1.6 2004/11/12 15:47:27 cvs Exp $ + * + */ + +#include +#include +#include + +#include "wxvisApp.h" +#include "wxvisFrame.h" +#include "wxvisCanvas.h" + +#ifdef DEBUG +FILE *debugFile = NULL; +#endif + +projectM *globalPM = NULL; + +IMPLEMENT_APP(wxvisApp) + +BEGIN_EVENT_TABLE(wxvisApp,wxApp) + EVT_IDLE(wxvisApp::OnIdle) +END_EVENT_TABLE() + +/** Parse command-line options and create the main wxvis windows */ +bool wxvisApp::OnInit() { + +#ifdef DEBUG +#ifndef WIN32 + /** Open the debug file */ + debugFile = fopen( "/tmp/wxvis.txt", "w" ); +#else + /** Open the debug file */ + debugFile = fopen( "c:\\wxvis.txt", "w" ); +#endif /** __WXMAC__ */ +#else +// debugFile = NULL; +#endif + +#ifdef WIN32 + /** Retrieve the key from the registry for the base installation directory */ + installationRoot = (unsigned char *)malloc( sizeof( unsigned char ) * 1024 ); + installationRoot[0] = '\0'; + HKEY key; + if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Archaeoptics\\wxvis3D", + 0, KEY_QUERY_VALUE, &key ) != ERROR_SUCCESS ) { +// MessageBox( NULL, "Failed to open registry key: SOFTWARE\\Archaeoptics\\wxvis\nHelp and NPR textures may be unavailable!", "projectM", MB_OK | MB_ICONEXCLAMATION ); + sprintf( (char *)installationRoot, "%s", "c:\\Program Files\\Archaeoptics\\wxvis3D" ); + } else { + DWORD installRootType = REG_SZ; + DWORD installRootSize = 1024; + LONG rv = RegQueryValueEx( key, "InstallRoot", NULL, &installRootType, installationRoot, &installRootSize ); + if ( rv != ERROR_SUCCESS ) { + /** This section causes things to crash weirdly... */ +// MessageBox( NULL, "Failed to query registry key: SOFTWARE\\Archaeoptics\\wxvis\nHelp and textures may be unavailable!", "projectM", MB_OK | MB_ICONEXCLAMATION ); +/* char msg[128]; + sprintf( msg, "Error code: %d", rv ); + wxMessageBox( msg, "projectM", wxOK | wxICON_EXCLAMATION ); */ + sprintf( (char *)installationRoot, "%s", "c:\\Program Files\\Archaeoptics\\wxvis3D" ); + } + RegCloseKey( key ); + } + +#ifdef DEBUG2 + fprintf( debugFile, "Installation Root: %s\n", installationRoot ); + fflush( debugFile ); +#endif /** DEBUG */ +#else + installationRoot = NULL; +#endif /** WIN32 */ + + /** Empty out various structures before initialisation */ + _visFrame = NULL; + + /** Load the icon */ + _icon = wxIcon( "ARCHAEOPTICS_ICON" ); + + /** Create the rendering frame */ + wxPoint pt; + wxSize sz; + pt.x = 50; pt.y = 50; + sz.x = 640; sz.y = 480; + _visFrame = new wxvisFrame( this, wxString( "projectM" ), pt, sz ); + _visFrame->canvas = new wxvisCanvas( _visFrame ); + _visFrame->SetIcon( _icon ); + _visFrame->Show( TRUE ); + + /** Check depth and stencil capabilities */ + int depthBits = _visFrame->canvas->getDepthBits(); + int stencilBits = _visFrame->canvas->getStencilBits(); + if ( depthBits < 24 || stencilBits < 1 ) { + char msg[256]; + sprintf( msg, "Depth and stencil bit settings are sub-optimal\nBlack and White Ink Rendering and Elevation Extraction\nmay not work correctly\nDepth Bits: %d\nStencil Bits: %d\n(Should be at least 24 and 1)", depthBits, stencilBits ); +// wxMessageBox( msg, "projectM", wxOK | wxICON_EXCLAMATION ); + } + +#ifdef WIN32 + /** Update file associations */ + /** Create the base wxvis key */ + int rv; + rv = RegCreateKey( HKEY_CLASSES_ROOT, "projectM", &rootAssociationKey ); + rv = RegSetValue( rootAssociationKey, "", REG_SZ, "MilkDrop Preset", 0 ); + + /** This sets the command line for "projectM" */ + char exename[256]; + sprintf( exename, "%s\\wxvis.exe %%1", installationRoot ); + rv = RegCreateKey( HKEY_CLASSES_ROOT, "projectM", &rootAssociationKey ); + rv = RegSetValue( rootAssociationKey, "shell\\open\\command", REG_SZ, exename, MAX_PATH ); + + /** Set the icon */ + char iconname[256]; + sprintf( iconname, "%s\\archaeoptics_icon_64x64.ico", installationRoot ); + rv = RegCreateKey( HKEY_CLASSES_ROOT, "projectM", &rootAssociationKey ); + rv = RegSetValue( rootAssociationKey, "DefaultIcon", REG_SZ, iconname, MAX_PATH ); +#endif + + /** Check for a model name on the command line */ +#ifdef DEBUG2 + fprintf( debugFile, "argc: %d\n", argc ); + fflush( debugFile ); +#endif + if ( argc >= 2 ) { + if ( ( strstr( argv[1], ".milk" ) != NULL ) || + ( strstr( argv[1], ".MILK" ) != NULL ) ) { + /** Load a fixed preset */ + } + } + + return TRUE; + } + +/** Shuts down the application */ +void wxvisApp::shutdown() { + /** Free local resources */ + if ( _visFrame ) { + _visFrame->canvas->Destroy(); + _visFrame->Destroy(); + } + +#ifdef DEBUG2 + fclose( debugFile ); +#endif /** DEBUG */ + + exit( 0 ); + } + +void wxvisApp::OnIdle( wxIdleEvent &event ) { + if ( _visFrame ) { + _visFrame->canvas->Refresh( FALSE ); + } + } diff --git a/src/projectM-wxvis/wxvisCanvas.cpp b/src/projectM-wxvis/wxvisCanvas.cpp index a54ef4567..964c07f20 100755 --- a/src/projectM-wxvis/wxvisCanvas.cpp +++ b/src/projectM-wxvis/wxvisCanvas.cpp @@ -1,303 +1,303 @@ -/** - * projectM -- Milkdrop-esque visualisation SDK - * Copyright (C)2003-2004 projectM Team - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * See 'LICENSE.txt' included within this release - * - */ -/** - * $Id: wxvisCanvas.cpp,v 1.5 2004/11/12 15:47:27 cvs Exp $ - * - * Handles all the OpenGL drawing in the main wxvis display - */ - -#include -#ifdef WIN32 -#include -#endif /** WIN32 */ -#include -#include - -#include -#include -#include - -#include "wxvisApp.h" -#include "wxvisFrame.h" -#include "wxvisCanvas.h" - -/** Event handler table */ -BEGIN_EVENT_TABLE(wxvisCanvas,wxGLCanvas) - EVT_SIZE(wxvisCanvas::OnSize) - EVT_PAINT(wxvisCanvas::OnPaint) - EVT_ERASE_BACKGROUND(wxvisCanvas::OnEraseBackground) - EVT_KEY_DOWN(wxvisCanvas::OnKeyPress) -END_EVENT_TABLE() - -/** Create the OpenGL canvas */ -wxvisCanvas::wxvisCanvas( wxFrame *parent, const wxWindowID id, - const wxPoint &pos, const wxSize &dims, - long style, const wxString &name ) : - wxGLCanvas( parent, (wxGLCanvas *)NULL, id, - pos, dims, style, name ) { - - _parent = (wxvisFrame *)parent; - _hasInitialised = 0; - - pm = NULL; - - /** Create a semaphore to regulate thread access to the refresh function */ -#ifdef WIN32 - refreshSemaphore = - CreateSemaphore( NULL, 1, 1, "Redraw Semaphore" ); - - InitializeCriticalSection( &refreshMutex ); -#endif - } - -/** Repaint the canvas */ -void wxvisCanvas::OnPaint( wxPaintEvent &event ) { - - /** Acquire the semaphore before running... */ -#ifdef WIN32 -#ifdef DEBUG2 - fprintf( debugFile, "-> OnPaint(): Acquiring mutex\n" ); - fflush( debugFile ); -#endif - -// WaitForSingleObject( refreshSemaphore, INFINITE ); - EnterCriticalSection( &refreshMutex ); -#ifdef DEBUG2 - fprintf( debugFile, "-> OnPaint(): Semaphore acquired[]\n" ); - fflush( debugFile ); -#endif -#endif - - wxSize dims = GetClientSize(); - - /** Get the paint device context */ - wxPaintDC dc( this ); - - /** Swap in the OpenGL context */ -#ifndef __WXMOTIF__ - if ( !GetContext() ) { - return; - } -#endif - SetCurrent(); - - /** See if we've initialised */ - if ( !_hasInitialised ) { - printf( "here\n" ); - initialise(); - printf( "here2: %X\n", pm ); - if ( pm != NULL ) { - printf( "here3\n" ); - pm->projectM_resetGL( dims.x, dims.y ); - printf( "here4\n" ); - _hasInitialised = 1; - } else { - goto unlockAndExit; - } - } - - int i; - short pcm_data[2][512]; - - /** Produce some fake PCM data to stuff into projectM */ - if ( pm->count % 5 == 0 ) { - for ( i = 0 ; i < 512 ; i++ ) { - pcm_data[0][i] = 0; - pcm_data[1][i] = 0; - } - } else { - for ( i = 0 ; i < 512 ; i++ ) { - if ( i % 2 == 0 ) { - pcm_data[0][i] = (short)( (float)( rand() / ( (float)RAND_MAX ) * (pow(2,i%14) ) ) ); - pcm_data[1][i] = (short)( (float)( rand() / ( (float)RAND_MAX ) * (pow(2,i/2%14) ) ) ); - } else { - pcm_data[0][i] = (short)( (float)( rand() / ( (float)RAND_MAX ) * (pow(2,i/2%14) ) ) ); - pcm_data[1][i] = (short)( (float)( rand() / ( (float)RAND_MAX ) * (pow(2,i%14) ) ) ); - } - if ( i % 2 == 1 ) { - pcm_data[0][i] = -pcm_data[0][i]; - pcm_data[1][i] = -pcm_data[1][i]; - } - } - } - - /** Add the waveform data */ - DWRITE( "pm: %X\tbeatDetect: %X\tpcm: %X\tpcm_data: %X\n", - pm, pm->beatDetect, pm->beatDetect->pcm, pcm_data ); - pm->beatDetect->pcm->addPCM16( pcm_data ); - - /** Render the new frame */ - pm->renderFrame(); - -#ifdef PANTS - if ( dumpFrame ) { - char fname[1024]; - FILE *f = fopen( fname, "wb" ); - sprintf( fname, "projectM_%08d.ppm", frameNumber++ ); - fprintf( f, "P3\n#\n%d %d\n255\n", pm->wvw, pm->wvh ); - glReadPixels( 0, 0, pm->wvw, pm->wvh, GL_RGB, GL_UNSIGNED_BYTE, fbuffer ); - index = 0; - for ( y = 0 ; y < pm->wvh ; y++ ) { - for ( x = 0 ; x < pm->wvw ; x++ ) { - fprintf( f, "%d %d %d ", fbuffer[index++], fbuffer[index++], fbuffer[index++] ); - } - fprintf( f, "\n" ); - } - fclose( f ); - } -#endif - - /** Buffer swap in here */ - SwapBuffers(); - -unlockAndExit: -#ifdef WIN32 - /** Unlock the mutex */ - LeaveCriticalSection( &refreshMutex ); - -// ReleaseSemaphore( refreshSemaphore, 1, NULL ); -#ifdef DEBUG2 - fprintf( debugFile, "<- OnPaint(): Released semaphore[]\n" ); - fflush( debugFile ); -#endif - -// ExitThread( 0 ); -#endif - - return; - } - -/** Handles resize events */ -void wxvisCanvas::OnSize( wxSizeEvent &event ) { - - wxGLCanvas::OnSize( event ); - - int w, h; - GetClientSize( &w, &h ); - - /** Reset the viewport size */ -#ifndef __WXMOTIF__ - if ( GetContext() ) { -#endif - SetCurrent(); - glViewport( 0, 0, w, h ); -#ifndef __WXMOTIF__ - } -#endif - - if ( pm != NULL && pm->hasInit ) { - pm->projectM_resetGL( w, h ); - } - } - -/** Enables double-buffering, or a reasonable approximation thereof! */ -void wxvisCanvas::OnEraseBackground( wxEraseEvent &event ) { - // Do nothing, to avoid flashing. - } - -/** Initialise the context -- this only happens once */ -void wxvisCanvas::initialise() { - -#ifdef WIN32 - /** Initialise font bitmap lists */ - SelectObject( (HDC)GetHDC(), GetStockObject( SYSTEM_FONT ) ); - glColor3f( 1, 1, 1 ); - wglUseFontBitmaps( (HDC)GetHDC(), 0, 255, 1000 ); -#else -#ifdef __WXMAC__ - /** Initialise font bitmap lists */ - short familyId = 0; - GetFNum( (const unsigned char *)"systemFont", &familyId ); - aglUseFont( aglGetCurrentContext(), familyId, normal, 12, 0, 255, 1000 ); -#endif -#endif - - /** Initialise projectM */ - pm = (projectM *)wipemalloc( sizeof( projectM ) ); - pm->projectM_reset(); - - pm->fullscreen = 0; - pm->renderTarget->texsize = 1024; - -#ifndef WIN32 - pm->fontURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( pm->fontURL, "../../fonts" ); - - pm->presetURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( pm->presetURL, "/Users/descarte/tmp/projectM-1.00/presets_milkdrop" ); -#else - pm->fontURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( pm->fontURL, "c:\\tmp\\projectM-1.00\\fonts" ); - - pm->presetURL = (char *)malloc( sizeof( char ) * 512 ); - strcpy( pm->presetURL, "c:\\tmp\\projectM-1.00\\presets_projectM" ); -#endif /** MACOS */ - - pm->projectM_init(); - } - -/** Returns the number of depth bits */ -int wxvisCanvas::getDepthBits() { - int rv[1]; - - SetCurrent(); - glGetIntegerv( GL_DEPTH_BITS, (GLint *)rv ); - - return rv[0]; - } - -/** Returns the number of stencil bits */ -int wxvisCanvas::getStencilBits() { - int rv[1]; - - SetCurrent(); - glGetIntegerv( GL_STENCIL_BITS, (GLint *)rv ); - - return rv[0]; - } - -/** Handle keypresses */ -void wxvisCanvas::OnKeyPress( wxKeyEvent &event ) { - - int i; - - switch ( event.GetKeyCode() ) { - case 'R': { - pm->switchPreset( RANDOM_NEXT, HARD_CUT ); - break; - } - case 'N': { - pm->switchPreset( ALPHA_NEXT, HARD_CUT ); - break; - } - case 'P': { - pm->switchPreset( ALPHA_PREVIOUS, HARD_CUT ); - break; - } - case WXK_ESCAPE: { - _parent->app->shutdown(); - break; - } - } - - Refresh( FALSE ); - } - +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: wxvisCanvas.cpp,v 1.5 2004/11/12 15:47:27 cvs Exp $ + * + * Handles all the OpenGL drawing in the main wxvis display + */ + +#include +#ifdef WIN32 +#include +#endif /** WIN32 */ +#include +#include + +#include +#include +#include + +#include "wxvisApp.h" +#include "wxvisFrame.h" +#include "wxvisCanvas.h" + +/** Event handler table */ +BEGIN_EVENT_TABLE(wxvisCanvas,wxGLCanvas) + EVT_SIZE(wxvisCanvas::OnSize) + EVT_PAINT(wxvisCanvas::OnPaint) + EVT_ERASE_BACKGROUND(wxvisCanvas::OnEraseBackground) + EVT_KEY_DOWN(wxvisCanvas::OnKeyPress) +END_EVENT_TABLE() + +/** Create the OpenGL canvas */ +wxvisCanvas::wxvisCanvas( wxFrame *parent, const wxWindowID id, + const wxPoint &pos, const wxSize &dims, + long style, const wxString &name ) : + wxGLCanvas( parent, (wxGLCanvas *)NULL, id, + pos, dims, style, name ) { + + _parent = (wxvisFrame *)parent; + _hasInitialised = 0; + + pm = NULL; + + /** Create a semaphore to regulate thread access to the refresh function */ +#ifdef WIN32 + refreshSemaphore = + CreateSemaphore( NULL, 1, 1, "Redraw Semaphore" ); + + InitializeCriticalSection( &refreshMutex ); +#endif + } + +/** Repaint the canvas */ +void wxvisCanvas::OnPaint( wxPaintEvent &event ) { + + /** Acquire the semaphore before running... */ +#ifdef WIN32 +#ifdef DEBUG2 + fprintf( debugFile, "-> OnPaint(): Acquiring mutex\n" ); + fflush( debugFile ); +#endif + +// WaitForSingleObject( refreshSemaphore, INFINITE ); + EnterCriticalSection( &refreshMutex ); +#ifdef DEBUG2 + fprintf( debugFile, "-> OnPaint(): Semaphore acquired[]\n" ); + fflush( debugFile ); +#endif +#endif + + wxSize dims = GetClientSize(); + + /** Get the paint device context */ + wxPaintDC dc( this ); + + /** Swap in the OpenGL context */ +#ifndef __WXMOTIF__ + if ( !GetContext() ) { + return; + } +#endif + SetCurrent(); + + /** See if we've initialised */ + if ( !_hasInitialised ) { + printf( "here\n" ); + initialise(); + printf( "here2: %X\n", pm ); + if ( pm != NULL ) { + printf( "here3\n" ); + pm->projectM_resetGL( dims.x, dims.y ); + printf( "here4\n" ); + _hasInitialised = 1; + } else { + goto unlockAndExit; + } + } + + int i; + short pcm_data[2][512]; + + /** Produce some fake PCM data to stuff into projectM */ + if ( pm->count % 5 == 0 ) { + for ( i = 0 ; i < 512 ; i++ ) { + pcm_data[0][i] = 0; + pcm_data[1][i] = 0; + } + } else { + for ( i = 0 ; i < 512 ; i++ ) { + if ( i % 2 == 0 ) { + pcm_data[0][i] = (short)( (float)( rand() / ( (float)RAND_MAX ) * (pow(2,i%14) ) ) ); + pcm_data[1][i] = (short)( (float)( rand() / ( (float)RAND_MAX ) * (pow(2,i/2%14) ) ) ); + } else { + pcm_data[0][i] = (short)( (float)( rand() / ( (float)RAND_MAX ) * (pow(2,i/2%14) ) ) ); + pcm_data[1][i] = (short)( (float)( rand() / ( (float)RAND_MAX ) * (pow(2,i%14) ) ) ); + } + if ( i % 2 == 1 ) { + pcm_data[0][i] = -pcm_data[0][i]; + pcm_data[1][i] = -pcm_data[1][i]; + } + } + } + + /** Add the waveform data */ + DWRITE( "pm: %X\tbeatDetect: %X\tpcm: %X\tpcm_data: %X\n", + pm, pm->beatDetect, pm->beatDetect->pcm, pcm_data ); + pm->beatDetect->pcm->addPCM16( pcm_data ); + + /** Render the new frame */ + pm->renderFrame(); + +#ifdef PANTS + if ( dumpFrame ) { + char fname[1024]; + FILE *f = fopen( fname, "wb" ); + sprintf( fname, "projectM_%08d.ppm", frameNumber++ ); + fprintf( f, "P3\n#\n%d %d\n255\n", pm->wvw, pm->wvh ); + glReadPixels( 0, 0, pm->wvw, pm->wvh, GL_RGB, GL_UNSIGNED_BYTE, fbuffer ); + index = 0; + for ( y = 0 ; y < pm->wvh ; y++ ) { + for ( x = 0 ; x < pm->wvw ; x++ ) { + fprintf( f, "%d %d %d ", fbuffer[index++], fbuffer[index++], fbuffer[index++] ); + } + fprintf( f, "\n" ); + } + fclose( f ); + } +#endif + + /** Buffer swap in here */ + SwapBuffers(); + +unlockAndExit: +#ifdef WIN32 + /** Unlock the mutex */ + LeaveCriticalSection( &refreshMutex ); + +// ReleaseSemaphore( refreshSemaphore, 1, NULL ); +#ifdef DEBUG2 + fprintf( debugFile, "<- OnPaint(): Released semaphore[]\n" ); + fflush( debugFile ); +#endif + +// ExitThread( 0 ); +#endif + + return; + } + +/** Handles resize events */ +void wxvisCanvas::OnSize( wxSizeEvent &event ) { + + wxGLCanvas::OnSize( event ); + + int w, h; + GetClientSize( &w, &h ); + + /** Reset the viewport size */ +#ifndef __WXMOTIF__ + if ( GetContext() ) { +#endif + SetCurrent(); + glViewport( 0, 0, w, h ); +#ifndef __WXMOTIF__ + } +#endif + + if ( pm != NULL && pm->hasInit ) { + pm->projectM_resetGL( w, h ); + } + } + +/** Enables double-buffering, or a reasonable approximation thereof! */ +void wxvisCanvas::OnEraseBackground( wxEraseEvent &event ) { + // Do nothing, to avoid flashing. + } + +/** Initialise the context -- this only happens once */ +void wxvisCanvas::initialise() { + +#ifdef WIN32 + /** Initialise font bitmap lists */ + SelectObject( (HDC)GetHDC(), GetStockObject( SYSTEM_FONT ) ); + glColor3f( 1, 1, 1 ); + wglUseFontBitmaps( (HDC)GetHDC(), 0, 255, 1000 ); +#else +#ifdef __WXMAC__ + /** Initialise font bitmap lists */ + short familyId = 0; + GetFNum( (const unsigned char *)"systemFont", &familyId ); + aglUseFont( aglGetCurrentContext(), familyId, normal, 12, 0, 255, 1000 ); +#endif +#endif + + /** Initialise projectM */ + pm = (projectM *)wipemalloc( sizeof( projectM ) ); + pm->projectM_reset(); + + pm->fullscreen = 0; + pm->renderTarget->texsize = 1024; + +#ifndef WIN32 + pm->fontURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( pm->fontURL, "../../fonts" ); + + pm->presetURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( pm->presetURL, "/Users/descarte/tmp/projectM-1.00/presets_milkdrop" ); +#else + pm->fontURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( pm->fontURL, "c:\\tmp\\projectM-1.00\\fonts" ); + + pm->presetURL = (char *)malloc( sizeof( char ) * 512 ); + strcpy( pm->presetURL, "c:\\tmp\\projectM-1.00\\presets_projectM" ); +#endif /** MACOS */ + + pm->projectM_init(); + } + +/** Returns the number of depth bits */ +int wxvisCanvas::getDepthBits() { + int rv[1]; + + SetCurrent(); + glGetIntegerv( GL_DEPTH_BITS, (GLint *)rv ); + + return rv[0]; + } + +/** Returns the number of stencil bits */ +int wxvisCanvas::getStencilBits() { + int rv[1]; + + SetCurrent(); + glGetIntegerv( GL_STENCIL_BITS, (GLint *)rv ); + + return rv[0]; + } + +/** Handle keypresses */ +void wxvisCanvas::OnKeyPress( wxKeyEvent &event ) { + + int i; + + switch ( event.GetKeyCode() ) { + case 'R': { + pm->switchPreset( RANDOM_NEXT, HARD_CUT ); + break; + } + case 'N': { + pm->switchPreset( ALPHA_NEXT, HARD_CUT ); + break; + } + case 'P': { + pm->switchPreset( ALPHA_PREVIOUS, HARD_CUT ); + break; + } + case WXK_ESCAPE: { + _parent->app->shutdown(); + break; + } + } + + Refresh( FALSE ); + } +