static PyObject* movie_set_volume (PyObject* self, PyObject* args) { SMPEG* movie = PyMovie_AsSMPEG (self); float value; int volume; if (!PyArg_ParseTuple (args, "f", &value)) return NULL; if (!SDL_WasInit (SDL_INIT_VIDEO)) return RAISE (PyExc_SDLError, "cannot convert without pygame.display initialized"); Py_BEGIN_ALLOW_THREADS; volume = (int) (value * 100); if (volume < 0) volume = 0; if (volume > 100) volume = 100; SMPEG_setvolume (movie, volume); Py_END_ALLOW_THREADS; Py_RETURN_NONE; }
int ONScripter::playMPEG(const char *filename, bool click_flag, bool loop_flag) { unsigned long length = script_h.cBR->getFileLength( filename ); if (length == 0){ fprintf( stderr, " *** can't find file [%s] ***\n", filename ); return 0; } #ifdef ANDROID playVideoAndroid(filename); return 0; #endif int ret = 0; #if !defined(MP3_MAD) && !defined(USE_SDL_RENDERER) unsigned char *mpeg_buffer = new unsigned char[length]; script_h.cBR->getFile( filename, mpeg_buffer ); SMPEG *mpeg_sample = SMPEG_new_rwops( SDL_RWFromMem( mpeg_buffer, length ), NULL, 0 ); if ( !SMPEG_error( mpeg_sample ) ){ SMPEG_enableaudio( mpeg_sample, 0 ); if ( audio_open_flag ){ SMPEG_actualSpec( mpeg_sample, &audio_format ); SMPEG_enableaudio( mpeg_sample, 1 ); } SMPEG_enablevideo( mpeg_sample, 1 ); SMPEG_setdisplay( mpeg_sample, screen_surface, NULL, NULL ); SMPEG_setvolume( mpeg_sample, music_volume ); SMPEG_loop(mpeg_sample, loop_flag); Mix_HookMusic( mp3callback, mpeg_sample ); SMPEG_play( mpeg_sample ); bool done_flag = false; while( !(done_flag & click_flag) && SMPEG_status(mpeg_sample) == SMPEG_PLAYING ){ SDL_Event event; while( SDL_PollEvent( &event ) ){ switch (event.type){ case SDL_KEYUP: if ( ((SDL_KeyboardEvent *)&event)->keysym.sym == SDLK_RETURN || ((SDL_KeyboardEvent *)&event)->keysym.sym == SDLK_SPACE || ((SDL_KeyboardEvent *)&event)->keysym.sym == SDLK_ESCAPE ) done_flag = true; break; case SDL_QUIT: ret = 1; case SDL_MOUSEBUTTONUP: done_flag = true; break; default: break; } } SDL_Delay( 10 ); } SMPEG_stop( mpeg_sample ); Mix_HookMusic( NULL, NULL ); SMPEG_delete( mpeg_sample ); } delete[] mpeg_buffer; #else fprintf( stderr, "mpegplay command is disabled.\n" ); #endif return ret; }
void playVideo(const string &file) { //myFillRect(screen, NULL, 0); //SDL_GL_SwapBuffers(); SMPEG *mpeg; SMPEG_Info info; mpeg = SMPEG_new(file.c_str(), &info, false); bool hasAudio = (info.has_audio > 0); if ( SMPEG_error(mpeg) ) { dout << "MPEG error: " << SMPEG_error(mpeg) << endl; exit(1); } int done = 0; SDL_Surface *videoSurface = SDL_AllocSurface( SDL_SWSURFACE, nearestPow2(info.width), nearestPow2(info.height), 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 ); if ( !videoSurface ) { dout << "Failed to allocate memory for video playback" << endl; exit(1); } SMPEG_enablevideo(mpeg, 1); SDL_mutex *mutex = SDL_CreateMutex(); SMPEG_setdisplay(mpeg, videoSurface, mutex, videoUpdate ); SMPEG_scaleXY(mpeg, info.width, info.height); //SMPEG_setdisplayregion(mpeg, 0, 0, info.width, info.height); //SMPEG_setdisplay(mpeg, screen, NULL, update); if(hasAudio) { SDL_AudioSpec audiofmt; Uint16 format; int freq, channels; /* Tell SMPEG what the audio format is */ Mix_QuerySpec(&freq, &format, &channels); audiofmt.format = format; audiofmt.freq = freq; audiofmt.channels = channels; SMPEG_actualSpec(mpeg, &audiofmt); /* Hook in the MPEG music mixer */ Mix_HookMusic(SMPEG_playAudioSDL, mpeg); SMPEG_enableaudio(mpeg, 1); SMPEG_setvolume(mpeg, 100); } else { Mix_PauseMusic(); SMPEG_enableaudio(mpeg, 0); } glBlendFunc(GL_ONE, GL_ZERO); glEnable(GL_TEXTURE_2D); SMPEG_play(mpeg); while( !done && SMPEG_status( mpeg ) == SMPEG_PLAYING ) { SDL_Event event; while ( SDL_PollEvent(&event) ) { switch (event.type) { case SDL_KEYDOWN: { if ( event.key.keysym.sym == SDLK_SPACE ) { done = 1; } break; } case SDL_QUIT: { exit(1); } default: break; } } if(drawVideoFrame) { SDL_mutexP(mutex); drawVideoFrame = false; drawVideo(videoSurface, info.width, info.height); //printf("draw in %i\n", time(NULL)); SDL_mutexV(mutex); SDL_GL_SwapBuffers(); } } SMPEG_stop(mpeg); if(hasAudio) { Mix_HookMusic(NULL, NULL); } else { Mix_ResumeMusic(); } SDL_FreeSurface(videoSurface); myFillRect(screen, NULL, 0); SDL_GL_SwapBuffers(); SMPEG_delete(mpeg); }
int main(int argc, char *argv[]) { int use_audio, use_video; int fullscreen; int scalesize; int scale_width, scale_height; int loop_play; int i, pause; int volume; Uint32 seek; float skip; int bilinear_filtering; SDL_Surface *screen = NULL; SMPEG *mpeg; SMPEG_Info info; char *basefile; const char *title = NULL; SDL_version sdlver; SMPEG_version smpegver; int fd; char buf[32]; int status; /* Get the command line options */ use_audio = 1; use_video = 1; fullscreen = 0; scalesize = 1; scale_width = 0; scale_height = 0; loop_play = 0; volume = 100; seek = 0; skip = 0; bilinear_filtering = 0; fd = 0; for ( i=1; argv[i] && (argv[i][0] == '-') && (argv[i][1] != 0); ++i ) { if ( (strcmp(argv[i], "--noaudio") == 0) || (strcmp(argv[i], "--nosound") == 0) ) { use_audio = 0; } else if ( strcmp(argv[i], "--novideo") == 0 ) { use_video = 0; } else if ( strcmp(argv[i], "--fullscreen") == 0 ) { fullscreen = 1; } else if ((strcmp(argv[i], "--double") == 0)||(strcmp(argv[i], "-2") == 0)) { scalesize = 2; } else if ((strcmp(argv[i], "--loop") == 0) || (strcmp(argv[i], "-l") == 0)) { loop_play = 1; } else if ( strcmp(argv[i], "--bilinear") == 0 ) { bilinear_filtering = 1; } else if ((strcmp(argv[i], "--seek") == 0)||(strcmp(argv[i], "-S") == 0)) { ++i; if ( argv[i] ) { seek = atol(argv[i]); } } else if ((strcmp(argv[i], "--skip") == 0)||(strcmp(argv[i], "-k") == 0)) { ++i; if ( argv[i] ) { skip = (float)atof(argv[i]); } } else if ((strcmp(argv[i], "--volume") == 0)||(strcmp(argv[i], "-v") == 0)) { ++i; if (i >= argc) { fprintf(stderr, "Please specify volume when using --volume or -v\n"); return(1); } if ( argv[i] ) { volume = atoi(argv[i]); } if ( ( volume < 0 ) || ( volume > 100 ) ) { fprintf(stderr, "Volume must be between 0 and 100\n"); volume = 100; } } else if ((strcmp(argv[i], "--title") == 0)||(strcmp(argv[i], "-t") == 0)) { ++i; if (i >= argc) { fprintf(stderr, "Please specify title when using --title or -t\n"); return(1); } if ( argv[i] ) { title = argv[i]; } } else if ((strcmp(argv[i], "--version") == 0) || (strcmp(argv[i], "-V") == 0)) { sdlver = *SDL_Linked_Version(); SMPEG_VERSION(&smpegver); printf("SDL version: %d.%d.%d\n" "SMPEG version: %d.%d.%d\n", sdlver.major, sdlver.minor, sdlver.patch, smpegver.major, smpegver.minor, smpegver.patch); return(0); } else if ((strcmp(argv[i], "--scale") == 0)||(strcmp(argv[i], "-s") == 0)) { ++i; if ( argv[i] ) { sscanf(argv[i], "%dx%d", &scale_width, &scale_height); } } else if ((strcmp(argv[i], "--help") == 0) || (strcmp(argv[i], "-h") == 0)) { usage(argv[0]); return(0); } else { fprintf(stderr, "Warning: Unknown option: %s\n", argv[i]); } } /* If there were no arguments just print the usage */ if (argc == 1) { usage(argv[0]); return(0); } #if defined(linux) || defined(__FreeBSD__) /* Plaympeg doesn't need a mouse */ putenv("SDL_NOMOUSE=1"); #endif /* Play the mpeg files! */ status = 0; for ( ; argv[i]; ++i ) { /* Initialize SDL */ if ( use_video ) { if ((SDL_Init(SDL_INIT_VIDEO) < 0) || !SDL_VideoDriverName(buf, 1)) { fprintf(stderr, "Warning: Couldn't init SDL video: %s\n", SDL_GetError()); fprintf(stderr, "Will ignore video stream\n"); use_video = 0; } } if ( use_audio ) { if ((SDL_Init(SDL_INIT_AUDIO) < 0) || !SDL_AudioDriverName(buf, 1)) { fprintf(stderr, "Warning: Couldn't init SDL audio: %s\n", SDL_GetError()); fprintf(stderr, "Will ignore audio stream\n"); use_audio = 0; } } /* Allow Ctrl-C when there's no video output */ signal(SIGINT, next_movie); /* Create the MPEG stream */ #ifdef NET_SUPPORT #ifdef RAW_SUPPORT /* Check if source is an IP address and port*/ if((fd = raw_open(argv[i])) != 0) mpeg = SMPEG_new_descr(fd, &info, use_audio); else #endif #ifdef HTTP_SUPPORT /* Check if source is an http URL */ if((fd = http_open(argv[i])) != 0) mpeg = SMPEG_new_descr(fd, &info, use_audio); else #endif #ifdef FTP_SUPPORT /* Check if source is an http URL */ if((fd = ftp_open(argv[i])) != 0) mpeg = SMPEG_new_descr(fd, &info, use_audio); else #endif #endif #ifdef VCD_SUPPORT /* Check if source is a CDROM device */ if((fd = vcd_open(argv[i])) != 0) mpeg = SMPEG_new_descr(fd, &info, use_audio); else #endif { if(strcmp(argv[i], "-") == 0) /* Use stdin for input */ mpeg = SMPEG_new_descr(0, &info, use_audio); else mpeg = SMPEG_new(argv[i], &info, use_audio); } if ( SMPEG_error(mpeg) ) { fprintf(stderr, "%s: %s\n", argv[i], SMPEG_error(mpeg)); SMPEG_delete(mpeg); status = -1; continue; } SMPEG_enableaudio(mpeg, use_audio); SMPEG_enablevideo(mpeg, use_video); SMPEG_setvolume(mpeg, volume); /* Enable software bilinear filtering, if desired */ if ( bilinear_filtering ) { SMPEG_Filter *filter; filter = SMPEGfilter_bilinear(); filter = SMPEG_filter( mpeg, filter ); filter->destroy(filter); } /* Print information about the video */ basefile = strrchr(argv[i], '/'); if ( basefile ) { ++basefile; } else { basefile = argv[i]; } if ( info.has_audio && info.has_video ) { printf("%s: MPEG system stream (audio/video)\n", basefile); } else if ( info.has_audio ) { printf("%s: MPEG audio stream\n", basefile); } else if ( info.has_video ) { printf("%s: MPEG video stream\n", basefile); } if ( info.has_video ) { printf("\tVideo %dx%d resolution\n", info.width, info.height); } if ( info.has_audio ) { printf("\tAudio %s\n", info.audio_string); } if ( info.total_size ) { printf("\tSize: %d\n", info.total_size); } if ( info.total_time ) { printf("\tTotal time: %f\n", info.total_time); } /* Set up video display if needed */ if ( info.has_video && use_video ) { const SDL_VideoInfo *video_info; Uint32 video_flags; int video_bpp; int width, height; /* Get the "native" video mode */ video_info = SDL_GetVideoInfo(); switch (video_info->vfmt->BitsPerPixel) { case 16: case 24: case 32: video_bpp = video_info->vfmt->BitsPerPixel; break; default: video_bpp = 16; break; } if ( scale_width ) { width = scale_width; } else { width = info.width; } width *= scalesize; if ( scale_height ) { height = scale_height; } else { height = info.height; } height *= scalesize; video_flags = SDL_SWSURFACE; if ( fullscreen ) { video_flags = SDL_FULLSCREEN|SDL_DOUBLEBUF|SDL_HWSURFACE; } video_flags |= SDL_ASYNCBLIT; video_flags |= SDL_RESIZABLE; screen = SDL_SetVideoMode(width, height, video_bpp, video_flags); if ( screen == NULL ) { fprintf(stderr, "Unable to set %dx%d video mode: %s\n", width, height, SDL_GetError()); continue; } if (title != NULL) { SDL_WM_SetCaption(title, title); } else { SDL_WM_SetCaption(argv[i], "plaympeg"); } if ( screen->flags & SDL_FULLSCREEN ) { SDL_ShowCursor(0); } SMPEG_setdisplay(mpeg, screen, NULL, update); SMPEG_scaleXY(mpeg, screen->w, screen->h); } else { SDL_QuitSubSystem(SDL_INIT_VIDEO); use_video = 0; } /* Set any special playback parameters */ if ( loop_play ) { SMPEG_loop(mpeg, 1); } /* Seek starting position */ if(seek) SMPEG_seek(mpeg, seek); /* Skip seconds to starting position */ if(skip) SMPEG_skip(mpeg, skip); /* Play it, and wait for playback to complete */ SMPEG_play(mpeg); done = 0; pause = 0; while ( ! done && ( pause || (SMPEG_status(mpeg) == SMPEG_PLAYING) ) ) { SDL_Event event; while ( use_video && SDL_PollEvent(&event) ) { switch (event.type) { case SDL_VIDEORESIZE: { SDL_Surface *old_screen = screen; SMPEG_pause(mpeg); screen = SDL_SetVideoMode(event.resize.w, event.resize.h, screen->format->BitsPerPixel, screen->flags); if ( old_screen != screen ) { SMPEG_setdisplay(mpeg, screen, NULL, update); } SMPEG_scaleXY(mpeg, screen->w, screen->h); SMPEG_pause(mpeg); } break; case SDL_KEYDOWN: if ( (event.key.keysym.sym == SDLK_ESCAPE) || (event.key.keysym.sym == SDLK_q) ) { // Quit done = 1; } else if ( event.key.keysym.sym == SDLK_RETURN ) { // toggle fullscreen if ( event.key.keysym.mod & KMOD_ALT ) { SDL_WM_ToggleFullScreen(screen); fullscreen = (screen->flags & SDL_FULLSCREEN); SDL_ShowCursor(!fullscreen); } } else if ( event.key.keysym.sym == SDLK_UP ) { // Volume up if ( volume < 100 ) { if ( event.key.keysym.mod & KMOD_SHIFT ) { // 10+ volume += 10; } else if ( event.key.keysym.mod & KMOD_CTRL ) { // 100+ volume = 100; } else { // 1+ volume++; } if ( volume > 100 ) volume = 100; SMPEG_setvolume(mpeg, volume); } } else if ( event.key.keysym.sym == SDLK_DOWN ) { // Volume down if ( volume > 0 ) { if ( event.key.keysym.mod & KMOD_SHIFT ) { volume -= 10; } else if ( event.key.keysym.mod & KMOD_CTRL ) { volume = 0; } else { volume--; } if ( volume < 0 ) volume = 0; SMPEG_setvolume(mpeg, volume); } } else if ( event.key.keysym.sym == SDLK_PAGEUP ) { // Full volume volume = 100; SMPEG_setvolume(mpeg, volume); } else if ( event.key.keysym.sym == SDLK_PAGEDOWN ) { // Volume off volume = 0; SMPEG_setvolume(mpeg, volume); } else if ( event.key.keysym.sym == SDLK_SPACE ) { // Toggle play / pause if ( SMPEG_status(mpeg) == SMPEG_PLAYING ) { SMPEG_pause(mpeg); pause = 1; } else { SMPEG_play(mpeg); pause = 0; } } else if ( event.key.keysym.sym == SDLK_RIGHT ) { // Forward if ( event.key.keysym.mod & KMOD_SHIFT ) { SMPEG_skip(mpeg, 100); } else if ( event.key.keysym.mod & KMOD_CTRL ) { SMPEG_skip(mpeg, 50); } else { SMPEG_skip(mpeg, 5); } } else if ( event.key.keysym.sym == SDLK_LEFT ) { // Reverse if ( event.key.keysym.mod & KMOD_SHIFT ) { } else if ( event.key.keysym.mod & KMOD_CTRL ) { } else { } } else if ( event.key.keysym.sym == SDLK_KP_MINUS ) { // Scale minus if ( scalesize > 1 ) { scalesize--; } } else if ( event.key.keysym.sym == SDLK_KP_PLUS ) { // Scale plus scalesize++; } else if ( event.key.keysym.sym == SDLK_f ) { // Toggle filtering on/off if ( bilinear_filtering ) { SMPEG_Filter *filter = SMPEGfilter_null(); filter = SMPEG_filter( mpeg, filter ); filter->destroy(filter); bilinear_filtering = 0; } else { SMPEG_Filter *filter = SMPEGfilter_bilinear(); filter = SMPEG_filter( mpeg, filter ); filter->destroy(filter); bilinear_filtering = 1; } } break; case SDL_QUIT: done = 1; break; default: break; } } SDL_Delay(1000/2); } SMPEG_delete(mpeg); } SDL_Quit(); #if defined(RAW_SUPPORT) || defined(HTTP_SUPPORT) || defined(FTP_SUPPORT) || \ defined(VCD_SUPPORT) if(fd) close(fd); #endif return(status); }
void PonscripterLabel::variableEditMode(SDL_KeyboardEvent* event) { switch (event->keysym.sym) { case SDLK_m: if (variable_edit_mode != EDIT_SELECT_MODE) return; variable_edit_mode = EDIT_MP3_VOLUME_MODE; variable_edit_num = music_volume; break; case SDLK_s: if (variable_edit_mode != EDIT_SELECT_MODE) return; variable_edit_mode = EDIT_SE_VOLUME_MODE; variable_edit_num = se_volume; break; case SDLK_v: if (variable_edit_mode != EDIT_SELECT_MODE) return; variable_edit_mode = EDIT_VOICE_VOLUME_MODE; variable_edit_num = voice_volume; break; case SDLK_n: if (variable_edit_mode != EDIT_SELECT_MODE) return; variable_edit_mode = EDIT_VARIABLE_INDEX_MODE; variable_edit_num = 0; break; case SDLK_9: case SDLK_KP_9: variable_edit_num = variable_edit_num * 10 + 9; break; case SDLK_8: case SDLK_KP_8: variable_edit_num = variable_edit_num * 10 + 8; break; case SDLK_7: case SDLK_KP_7: variable_edit_num = variable_edit_num * 10 + 7; break; case SDLK_6: case SDLK_KP_6: variable_edit_num = variable_edit_num * 10 + 6; break; case SDLK_5: case SDLK_KP_5: variable_edit_num = variable_edit_num * 10 + 5; break; case SDLK_4: case SDLK_KP_4: variable_edit_num = variable_edit_num * 10 + 4; break; case SDLK_3: case SDLK_KP_3: variable_edit_num = variable_edit_num * 10 + 3; break; case SDLK_2: case SDLK_KP_2: variable_edit_num = variable_edit_num * 10 + 2; break; case SDLK_1: case SDLK_KP_1: variable_edit_num = variable_edit_num * 10 + 1; break; case SDLK_0: case SDLK_KP_0: variable_edit_num = variable_edit_num * 10 + 0; break; case SDLK_MINUS: case SDLK_KP_MINUS: if (variable_edit_mode == EDIT_VARIABLE_NUM_MODE && variable_edit_num == 0) { variable_edit_sign = -1; } break; case SDLK_BACKSPACE: if (variable_edit_num) variable_edit_num /= 10; else if (variable_edit_sign == -1) variable_edit_sign = 1; break; case SDLK_RETURN: case SDLK_KP_ENTER: switch (variable_edit_mode) { case EDIT_VARIABLE_INDEX_MODE: variable_edit_index = variable_edit_num; variable_edit_num = script_h.getVariableData(variable_edit_index).get_num(); if (variable_edit_num < 0) { variable_edit_num = -variable_edit_num; variable_edit_sign = -1; } else { variable_edit_sign = 1; } break; case EDIT_VARIABLE_NUM_MODE: script_h.setNumVariable(variable_edit_index, variable_edit_sign * variable_edit_num); break; case EDIT_MP3_VOLUME_MODE: music_volume = variable_edit_num; if (mp3_sample) SMPEG_setvolume(mp3_sample, !volume_on_flag? 0 : music_volume); break; case EDIT_SE_VOLUME_MODE: se_volume = variable_edit_num; for (int i = 1; i < ONS_MIX_CHANNELS; i++) if (wave_sample[i]) Mix_Volume(i, !volume_on_flag? 0 : se_volume * 128 / 100); if (wave_sample[MIX_LOOPBGM_CHANNEL0]) Mix_Volume(MIX_LOOPBGM_CHANNEL0, !volume_on_flag? 0 : se_volume * 128 / 100); if (wave_sample[MIX_LOOPBGM_CHANNEL1]) Mix_Volume(MIX_LOOPBGM_CHANNEL1, !volume_on_flag? 0 : se_volume * 128 / 100); break; case EDIT_VOICE_VOLUME_MODE: voice_volume = variable_edit_num; if (wave_sample[0]) Mix_Volume(0, !volume_on_flag? 0 : se_volume * 128 / 100); default: break; } if (variable_edit_mode == EDIT_VARIABLE_INDEX_MODE) variable_edit_mode = EDIT_VARIABLE_NUM_MODE; else variable_edit_mode = EDIT_SELECT_MODE; break; case SDLK_ESCAPE: if (variable_edit_mode == EDIT_SELECT_MODE) { variable_edit_mode = NOT_EDIT_MODE; SDL_SetWindowTitle(screen, DEFAULT_WM_TITLE); SDL_Delay(100); SDL_SetWindowTitle(screen, wm_title_string); return; } variable_edit_mode = EDIT_SELECT_MODE; default: break; } if (variable_edit_mode == EDIT_SELECT_MODE) { wm_edit_string = EDIT_MODE_PREFIX EDIT_SELECT_STRING; } else if (variable_edit_mode == EDIT_VARIABLE_INDEX_MODE) { wm_edit_string.format(EDIT_MODE_PREFIX "Variable Index? %%%d", variable_edit_sign * variable_edit_num); } else if (variable_edit_mode >= EDIT_VARIABLE_NUM_MODE) { int p = 0; pstring var_name; switch (variable_edit_mode) { case EDIT_VARIABLE_NUM_MODE: var_name.format("%%%d", variable_edit_index); p = script_h.getVariableData(variable_edit_index).get_num(); break; case EDIT_MP3_VOLUME_MODE: var_name = "MP3 Volume"; p = music_volume; break; case EDIT_VOICE_VOLUME_MODE: var_name = "Voice Volume"; p = voice_volume; break; case EDIT_SE_VOLUME_MODE: var_name = "Sound effect Volume"; p = se_volume; break; default: var_name = ""; } wm_edit_string.format(EDIT_MODE_PREFIX "Current %s=%d New value? %d", (const char*) var_name, p, variable_edit_num * variable_edit_sign); } SDL_SetWindowTitle(screen, wm_title_string); //TODO //SDL_SetWindowIcon(screen, wm_icon_string); }
void PonscripterLabel::flushEventSub(SDL_Event &event) { if (event.type == ONS_SOUND_EVENT) { if (music_play_loop_flag) { stopBGM(true); if (music_file_name) playSound(music_file_name, SOUND_OGG_STREAMING | SOUND_MP3, true); } else { stopBGM(false); } } // The event handler for the mp3 fadeout event itself. Simply sets the volume of the mp3 being played lower and lower until it's 0, // and until the requisite mp3 fadeout time has passed. Recommend for integration. [Seung Park, 20060621] else if (event.type == ONS_FADE_EVENT) { if (skip_flag || draw_one_page_flag || ctrl_pressed_status || skip_to_wait) { mp3fadeout_duration = 0; if (mp3_sample) SMPEG_setvolume(mp3_sample, 0); } Uint32 tmp = SDL_GetTicks() - mp3fadeout_start; if (tmp < mp3fadeout_duration) { tmp = mp3fadeout_duration - tmp; tmp *= music_volume; tmp /= mp3fadeout_duration; if (mp3_sample) SMPEG_setvolume(mp3_sample, tmp); } else { SDL_RemoveTimer(timer_mp3fadeout_id); timer_mp3fadeout_id = 0; event_mode &= ~WAIT_TIMER_MODE; stopBGM(false); advancePhase(); } } else if (event.type == ONS_MIDI_EVENT) { #ifdef MACOSX if (!Mix_PlayingMusic()) { ext_music_play_once_flag = !midi_play_loop_flag; Mix_FreeMusic(midi_info); playMIDI(midi_play_loop_flag); } #else ext_music_play_once_flag = !midi_play_loop_flag; Mix_FreeMusic(midi_info); playMIDI(midi_play_loop_flag); #endif } else if (event.type == ONS_MUSIC_EVENT) { ext_music_play_once_flag = !music_play_loop_flag; Mix_FreeMusic(music_info); playExternalMusic(music_play_loop_flag); } else if (event.type == ONS_WAVE_EVENT) { // for processing btntim2 and automode correctly if (wave_sample[event.user.code]) { Mix_FreeChunk(wave_sample[event.user.code]); wave_sample[event.user.code] = NULL; if (event.user.code == MIX_LOOPBGM_CHANNEL0 && loop_bgm_name[1] && wave_sample[MIX_LOOPBGM_CHANNEL1]) Mix_PlayChannel(MIX_LOOPBGM_CHANNEL1, wave_sample[MIX_LOOPBGM_CHANNEL1], -1); } } }
// Set's the volume on a scale of 0 - 100 void CSmpeg::SetVolume( int vol ) { SMPEG_setvolume( movie, vol ); }