| 1 | /* |
| 2 | * OpenTyrian: A modern cross-platform port of Tyrian |
| 3 | * Copyright (C) 2007-2009 The OpenTyrian Development Team |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | #include "jukebox.h"cxx . . $ `<file>/src/jukebox.h`/ |
| 20 | |
| 21 | #include "font.h"cxx . . $ `<file>/src/font.h`/ |
| 22 | #include "joystick.h"cxx . . $ `<file>/src/joystick.h`/ |
| 23 | #include "keyboard.h"cxx . . $ `<file>/src/keyboard.h`/ |
| 24 | #include "lds_play.h"cxx . . $ `<file>/src/lds_play.h`/ |
| 25 | #include "loudness.h"cxx . . $ `<file>/src/loudness.h`/ |
| 26 | #include "mtrand.h"cxx . . $ `<file>/src/mtrand.h`/ |
| 27 | #include "nortsong.h"cxx . . $ `<file>/src/nortsong.h`/ |
| 28 | #include "opentyr.h"cxx . . $ `<file>/src/opentyr.h`/ |
| 29 | #include "palette.h"cxx . . $ `<file>/src/palette.h`/ |
| 30 | #include "sprite.h"cxx . . $ `<file>/src/sprite.h`/ |
| 31 | #include "starlib.h"cxx . . $ `<file>/src/starlib.h`/ |
| 32 | #include "vga_palette.h"cxx . . $ `<file>/src/vga_palette.h`/ |
| 33 | #include "video.h"cxx . . $ `<file>/src/video.h`/ |
| 34 | |
| 35 | #include <stdio.h> |
| 36 | |
| 37 | void jukeboxcxx . . $ jukebox(49f6e7a06ebc5aa8).(void) // FKA Setup.jukeboxGo |
| 38 | { |
| 39 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! trigger_quit = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, // true when user wants to quit |
| 40 | quitting = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 41 | |
| 42 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! hide_text = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 43 | |
| 44 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! fade_looped_songs = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, fading_song = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 45 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! stopped = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 46 | |
| 47 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! fx = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 48 | int fx_num = 0; |
| 49 | |
| 50 | int palette_fade_steps = 15; |
| 51 | |
| 52 | int diff[256][3]; |
| 53 | init_step_fade_palettecxx . . $ init_step_fade_palette(78767d3cf152c690).(diff, vga_palettecxx . . $ vga_palette., 0, 255); |
| 54 | |
| 55 | JE_starlib_initcxx . . $ JE_starlib_init(49f6e7a06ebc5aa8).(); |
| 56 | |
| 57 | int fade_volume = tyrMusicVolumecxx . . $ tyrMusicVolume.; |
| 58 | |
| 59 | for (; ; ) |
| 60 | { |
| 61 | if (!stopped && !audio_disabledcxx . . $ audio_disabled.) |
| 62 | { |
| 63 | if (songloopedcxx . . $ songlooped. && fade_looped_songs) |
| 64 | fading_song = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 65 | |
| 66 | if (fading_song) |
| 67 | { |
| 68 | if (fade_volume > 5) |
| 69 | { |
| 70 | fade_volume -= 2; |
| 71 | } |
| 72 | else |
| 73 | { |
| 74 | fade_volume = tyrMusicVolumecxx . . $ tyrMusicVolume.; |
| 75 | |
| 76 | fading_song = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 77 | } |
| 78 | |
| 79 | set_volumecxx . . $ set_volume(8fbe6856f5410d23).(fade_volume, fxVolumecxx . . $ fxVolume.); |
| 80 | } |
| 81 | |
| 82 | if (!playingcxx . . $ playing. || (songloopedcxx . . $ songlooped. && fade_looped_songs && !fading_song)) |
| 83 | play_songcxx . . $ play_song(cb2f890c2fdad230).(mt_randcxx . . $ mt_rand(f708dce9a8856c70).() % MUSIC_NUMcxx . . $ `src/musmast.h:32:9`!); |
| 84 | } |
| 85 | |
| 86 | setDelaycxx . . $ setDelay(d4f767463ce0a6b3).(1); |
| 87 | |
| 88 | SDL_FillRectcxx . . $ SDL_FillRect(3ec95406e4bae91).(VGAScreenSegcxx . . $ VGAScreenSeg., NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!, 0); |
| 89 | |
| 90 | // starlib input needs to be rewritten |
| 91 | JE_starlib_maincxx . . $ JE_starlib_main(49f6e7a06ebc5aa8).(); |
| 92 | |
| 93 | push_joysticks_as_keyboardcxx . . $ push_joysticks_as_keyboard(49f6e7a06ebc5aa8).(); |
| 94 | service_SDL_eventscxx . . $ service_SDL_events(b45ddcbc8423892c).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!); |
| 95 | |
| 96 | if (!hide_text) |
| 97 | { |
| 98 | char buffer[60]; |
| 99 | |
| 100 | if (fx) |
| 101 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(buffer, sizeof(buffer), "%d %s", fx_num + 1, soundTitlecxx . . $ soundTitle.[fx_num]); |
| 102 | else |
| 103 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(buffer, sizeof(buffer), "%d %s", song_playingcxx . . $ song_playing. + 1, musicTitlecxx . . $ musicTitle.[song_playingcxx . . $ song_playing.]); |
| 104 | |
| 105 | const int x = VGAScreencxx . . $ VGAScreen.->wcxx . . $ SDL_Surface#w. / 2; |
| 106 | |
| 107 | draw_font_hvcxx . . $ draw_font_hv(3eb897592553ef61).(VGAScreencxx . . $ VGAScreen., x, 170, "Press ESC to quit the jukebox.", small_fontcxx . . $ small_font., centeredcxx . . $ centered., 1, 0); |
| 108 | draw_font_hvcxx . . $ draw_font_hv(3eb897592553ef61).(VGAScreencxx . . $ VGAScreen., x, 180, "Arrow keys change the song being played.", small_fontcxx . . $ small_font., centeredcxx . . $ centered., 1, 0); |
| 109 | draw_font_hvcxx . . $ draw_font_hv(3eb897592553ef61).(VGAScreencxx . . $ VGAScreen., x, 190, buffer, small_fontcxx . . $ small_font., centeredcxx . . $ centered., 1, 4); |
| 110 | } |
| 111 | |
| 112 | if (palette_fade_steps > 0) |
| 113 | step_fade_palettecxx . . $ step_fade_palette(ccf0b4adc1b21d7).(diff, palette_fade_steps--, 0, 255); |
| 114 | |
| 115 | JE_showVGAcxx . . $ JE_showVGA(49f6e7a06ebc5aa8).(); |
| 116 | |
| 117 | wait_delaycxx . . $ wait_delay(49f6e7a06ebc5aa8).(); |
| 118 | |
| 119 | // quit on mouse click |
| 120 | Uint16cxx . . $ Uint16# x, y; |
| 121 | if (JE_mousePositioncxx . . $ JE_mousePosition(2aa6fbd8d75b91c).(&x, &y) > 0) |
| 122 | trigger_quit = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 123 | |
| 124 | if (newkeycxx . . $ newkey.) |
| 125 | { |
| 126 | switch (lastkey_scancxx . . $ lastkey_scan.) |
| 127 | { |
| 128 | case SDL_SCANCODE_ESCAPEcxx . . $ SDL_SCANCODE_ESCAPE.: // quit jukebox |
| 129 | case SDL_SCANCODE_Qcxx . . $ SDL_SCANCODE_Q.: |
| 130 | trigger_quit = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 131 | break; |
| 132 | |
| 133 | case SDL_SCANCODE_SPACEcxx . . $ SDL_SCANCODE_SPACE.: |
| 134 | hide_text = !hide_text; |
| 135 | break; |
| 136 | |
| 137 | case SDL_SCANCODE_Fcxx . . $ SDL_SCANCODE_F.: |
| 138 | fading_song = !fading_song; |
| 139 | break; |
| 140 | case SDL_SCANCODE_Ncxx . . $ SDL_SCANCODE_N.: |
| 141 | fade_looped_songs = !fade_looped_songs; |
| 142 | break; |
| 143 | |
| 144 | case SDL_SCANCODE_SLASHcxx . . $ SDL_SCANCODE_SLASH.: // switch to sfx mode |
| 145 | fx = !fx; |
| 146 | break; |
| 147 | case SDL_SCANCODE_COMMAcxx . . $ SDL_SCANCODE_COMMA.: |
| 148 | if (fx && --fx_num < 0) |
| 149 | fx_num = SOUND_COUNTcxx . . $ `src/sndmast.h:26:9`! - 1; |
| 150 | break; |
| 151 | case SDL_SCANCODE_PERIODcxx . . $ SDL_SCANCODE_PERIOD.: |
| 152 | if (fx && ++fx_num >= SOUND_COUNTcxx . . $ `src/sndmast.h:26:9`!) |
| 153 | fx_num = 0; |
| 154 | break; |
| 155 | case SDL_SCANCODE_SEMICOLONcxx . . $ SDL_SCANCODE_SEMICOLON.: |
| 156 | if (fx) |
| 157 | JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(fx_num + 1); |
| 158 | break; |
| 159 | |
| 160 | case SDL_SCANCODE_LEFTcxx . . $ SDL_SCANCODE_LEFT.: |
| 161 | case SDL_SCANCODE_UPcxx . . $ SDL_SCANCODE_UP.: |
| 162 | play_songcxx . . $ play_song(cb2f890c2fdad230).((song_playingcxx . . $ song_playing. > 0 ? song_playingcxx . . $ song_playing. : MUSIC_NUMcxx . . $ `src/musmast.h:32:9`!) - 1); |
| 163 | stopped = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 164 | break; |
| 165 | case SDL_SCANCODE_RETURNcxx . . $ SDL_SCANCODE_RETURN.: |
| 166 | case SDL_SCANCODE_RIGHTcxx . . $ SDL_SCANCODE_RIGHT.: |
| 167 | case SDL_SCANCODE_DOWNcxx . . $ SDL_SCANCODE_DOWN.: |
| 168 | play_songcxx . . $ play_song(cb2f890c2fdad230).((song_playingcxx . . $ song_playing. + 1) % MUSIC_NUMcxx . . $ `src/musmast.h:32:9`!); |
| 169 | stopped = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 170 | break; |
| 171 | case SDL_SCANCODE_Scxx . . $ SDL_SCANCODE_S.: // stop song |
| 172 | stop_songcxx . . $ stop_song(49f6e7a06ebc5aa8).(); |
| 173 | stopped = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 174 | break; |
| 175 | case SDL_SCANCODE_Rcxx . . $ SDL_SCANCODE_R.: // restart song |
| 176 | restart_songcxx . . $ restart_song(49f6e7a06ebc5aa8).(); |
| 177 | stopped = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 178 | break; |
| 179 | |
| 180 | default: |
| 181 | break; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | // user wants to quit, start fade-out |
| 186 | if (trigger_quit && !quitting) |
| 187 | { |
| 188 | palette_fade_steps = 15; |
| 189 | |
| 190 | SDL_Colorcxx . . $ SDL_Color# black = { 0, 0, 0 }; |
| 191 | init_step_fade_solidcxx . . $ init_step_fade_solid(2c3657619c5a01cf).(diff, black, 0, 255); |
| 192 | |
| 193 | quitting = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 194 | } |
| 195 | |
| 196 | // if fade-out finished, we can finally quit |
| 197 | if (quitting && palette_fade_steps == 0) |
| 198 | break; |
| 199 | } |
| 200 | |
| 201 | set_volumecxx . . $ set_volume(8fbe6856f5410d23).(tyrMusicVolumecxx . . $ tyrMusicVolume., fxVolumecxx . . $ fxVolume.); |
| 202 | } |