void DigiStopCurrentSong() { if (digi_midi_song_playing) { int h = midi_volume; // preserve it for another song being started DigiSetMidiVolume(0); midi_volume = h; #if USE_SDL_MIXER if (gameOpts->sound.bUseSDLMixer) { Mix_HaltMusic (); Mix_FreeMusic (mixMusic); mixMusic = NULL; } #endif #if defined (_WIN32) # if USE_SDL_MIXER else # endif { hmp_close (hmp); hmp = NULL; digi_midi_song_playing = 0; } #endif } }
void digi_stop_current_song() { if ( digi_midi_song_playing ) { hmp_close(hmp); hmp = NULL; digi_midi_song_playing = 0; } }
void digi_win32_stop_midi_song() { if (!digi_win32_midi_song_playing) return; hmp_close(cur_hmp); cur_hmp = NULL; digi_win32_midi_song_playing = 0; hmp_reset(); }
void hmp2mid(char *hmp_name, unsigned char **midbuf, unsigned int *midlen) { int mi, i; short ms, time_div = 0xC0; hmp_file *hmp=NULL; hmp = hmp_open(hmp_name); if (hmp == NULL) return; *midlen = 0; time_div = hmp->tempo*1.6; // write MIDI-header *midbuf = (unsigned char *) d_realloc(*midbuf, *midlen + 4); memcpy(&(*midbuf)[*midlen], "MThd", 4); *midlen += 4; mi = MIDIINT(6); *midbuf = (unsigned char *) d_realloc(*midbuf, *midlen + sizeof(mi)); memcpy(&(*midbuf)[*midlen], &mi, sizeof(mi)); *midlen += sizeof(mi); ms = MIDISHORT(1); *midbuf = (unsigned char *) d_realloc(*midbuf, *midlen + sizeof(ms)); memcpy(&(*midbuf)[*midlen], &ms, sizeof(ms)); *midlen += sizeof(ms); ms = MIDISHORT(hmp->num_trks); *midbuf = (unsigned char *) d_realloc(*midbuf, *midlen + sizeof(ms)); memcpy(&(*midbuf)[*midlen], &ms, sizeof(ms)); *midlen += sizeof(ms); ms = MIDISHORT(time_div); *midbuf = (unsigned char *) d_realloc(*midbuf, *midlen + sizeof(ms)); memcpy(&(*midbuf)[*midlen], &ms, sizeof(ms)); *midlen += sizeof(ms); *midbuf = (unsigned char *) d_realloc(*midbuf, *midlen + sizeof(tempo)); memcpy(&(*midbuf)[*midlen], &tempo, sizeof(tempo)); *midlen += sizeof(tempo); // tracks for (i = 1; i < hmp->num_trks; i++) { int midtrklenpos = 0; *midbuf = (unsigned char *) d_realloc(*midbuf, *midlen + 4); memcpy(&(*midbuf)[*midlen], "MTrk", 4); *midlen += 4; midtrklenpos = *midlen; mi = 0; *midbuf = (unsigned char *) d_realloc(*midbuf, *midlen + sizeof(mi)); *midlen += sizeof(mi); mi = hmptrk2mid(hmp->trks[i].data, hmp->trks[i].len, midbuf, midlen); mi = MIDIINT(mi); memcpy(&(*midbuf)[midtrklenpos], &mi, 4); } hmp_close(hmp); }
void CMidi::Shutdown (void) { #if (defined (_WIN32) || USE_SDL_MIXER) if (m_hmp) { hmp_close (m_hmp); m_hmp = NULL; songManager.SetPlaying (0); } #endif Fadeout (); }
void digi_mixer_stop_current_song() { #ifdef _WIN32 if (digi_midi_song_playing) { hmp_close(hmp); hmp = NULL; digi_midi_song_playing = 0; } #endif jukebox_stop(); //mix_stop_music(); oplmus_play(NULL, NULL, NULL, 0); }
void digi_audio_stop_current_song() { #ifdef HMIPLAY char buf[10]; sprintf(buf,"s"); send_ipc(buf); #endif #ifdef _WIN32 if (digi_midi_song_playing) { hmp_close(hmp); hmp = NULL; digi_midi_song_playing = 0; } #endif }
void DigiStopCurrentSong () { int h; if (gameData.songs.bPlaying) { DigiFadeoutMusic (); h = midiVolume; // preserve it for another song being started DigiSetMidiVolume (0); midiVolume = h; #if defined (_WIN32) # if USE_SDL_MIXER if (!gameOpts->sound.bUseSDLMixer) # endif { hmp_close (hmp); hmp = NULL; gameData.songs.bPlaying = 0; } #endif } }
hmp_file *hmp_open(const char *filename, int bUseD1Hog) { int i; char buf [256]; long data = 0; CFile cf; hmp_file *hmp; int num_tracks, midi_div; ubyte *p; if (!cf.Open (filename, gameFolders.szDataDir, "rb", bUseD1Hog)) return NULL; hmp = new hmp_file; if (!hmp) { cf.Close(); return NULL; } memset(hmp, 0, sizeof(*hmp)); if ((cf.Read (buf, 1, 8) != 8) || (memcmp(buf, "HMIMIDIP", 8))) goto err; if (cf.Seek (0x30, SEEK_SET)) goto err; if (cf.Read (&num_tracks, 4, 1) != 1) goto err; if (cf.Seek (0x38, SEEK_SET)) goto err; if (cf.Read (&midi_div, 4, 1) != 1) goto err; if ((num_tracks < 1) || (num_tracks > HMP_TRACKS)) goto err; hmp->num_trks = num_tracks; hmp->midi_division = midi_div; hmp->tempo = 120; if (cf.Seek(0x308, SEEK_SET)) goto err; for (i = 0; i < num_tracks; i++) { if ((cf.Seek(4, SEEK_CUR)) || (cf.Read(&data, 4, 1) != 1)) goto err; data -= 12; #if 0 if (i == 0) /* track 0: reserve length for tempo */ data += sizeof(hmp_tempo); #endif hmp->trks [i].len = data; if (!(p = hmp->trks [i].data = new ubyte [data])) goto err; #if 0 if (i == 0) { /* track 0: add tempo */ memcpy(p, hmp_tempo, sizeof(hmp_tempo)); p += sizeof(hmp_tempo); data -= sizeof(hmp_tempo); } #endif /* finally, read track data */ if ((cf.Seek(4, SEEK_CUR)) || (cf.Read(p, data, 1) != 1)) goto err; } cf.Close(); return hmp; err: cf.Close(); hmp_close(hmp); return NULL; }
hmp_file *hmp_open(const char *filename, int bUseD1Hog) { int i; char buf [256]; long data = 0; CFILE *fp; hmp_file *hmp; int num_tracks, midi_div; unsigned char *p; if (!(fp = CFOpen((char *)filename, gameFolders.szDataDir, "rb", bUseD1Hog))) return NULL; hmp = d_malloc(sizeof(hmp_file)); if (!hmp) { CFClose(fp); return NULL; } memset(hmp, 0, sizeof(*hmp)); if ((CFRead (buf, 1, 8, fp) != 8) || (memcmp(buf, "HMIMIDIP", 8))) goto err; if (CFSeek (fp, 0x30, SEEK_SET)) goto err; if (CFRead (&num_tracks, 4, 1, fp) != 1) goto err; if (CFSeek (fp, 0x38, SEEK_SET)) goto err; if (CFRead (&midi_div, 4, 1, fp) != 1) goto err; if ((num_tracks < 1) || (num_tracks > HMP_TRACKS)) goto err; hmp->num_trks = num_tracks; hmp->midi_division = midi_div; hmp->tempo = 120; if (CFSeek(fp, 0x308, SEEK_SET)) goto err; for (i = 0; i < num_tracks; i++) { if ((CFSeek(fp, 4, SEEK_CUR)) || (CFRead(&data, 4, 1, fp) != 1)) goto err; data -= 12; #if 0 if (i == 0) /* track 0: reserve length for tempo */ data += sizeof(hmp_tempo); #endif hmp->trks [i].len = data; if (!(p = hmp->trks [i].data = d_malloc(data))) goto err; #if 0 if (i == 0) { /* track 0: add tempo */ memcpy(p, hmp_tempo, sizeof(hmp_tempo)); p += sizeof(hmp_tempo); data -= sizeof(hmp_tempo); } #endif /* finally, read track data */ if ((CFSeek(fp, 4, SEEK_CUR)) || (CFRead(p, data, 1, fp) != 1)) goto err; } CFClose(fp); return hmp; err: CFClose(fp); hmp_close(hmp); return NULL; }
hmp_file *hmp_open(const char *filename) { int i; char buf[256]; int32_t data; CFILE *fp; hmp_file *hmp; int num_tracks; unsigned char *p; if (!(fp = cfopen((char *)filename, "rb"))) return NULL; hmp = malloc(sizeof(hmp_file)); if (!hmp) { cfclose(fp); return NULL; } memset(hmp, 0, sizeof(*hmp)); if ((cfread(buf, 1, 8, fp) != 8) || (memcmp(buf, "HMIMIDIP", 8))) goto err; if (cfseek(fp, 0x30, SEEK_SET)) goto err; if (cfread(&num_tracks, 4, 1, fp) != 1) goto err; if ((num_tracks < 1) || (num_tracks > HMP_TRACKS)) goto err; hmp->num_trks = num_tracks; hmp->tempo = 120; if (cfseek(fp, 0x308, SEEK_SET)) goto err; for (i = 0; i < num_tracks; i++) { if ((cfseek(fp, 4, SEEK_CUR)) || (cfread(&data, 4, 1, fp) != 1)) goto err; data -= 12; #if 0 if (i == 0) /* track 0: reserve length for tempo */ data += sizeof(hmp_tempo); #endif hmp->trks[i].len = data; if (!(p = hmp->trks[i].data = malloc(data))) goto err; #if 0 if (i == 0) { /* track 0: add tempo */ memcpy(p, hmp_tempo, sizeof(hmp_tempo)); p += sizeof(hmp_tempo); data -= sizeof(hmp_tempo); } #endif /* finally, read track data */ if ((cfseek(fp, 4, SEEK_CUR)) || (cfread(p, data, 1, fp) != 1)) goto err; } cfclose(fp); return hmp; err: cfclose(fp); hmp_close(hmp); return NULL; }
hmp_file *hmp_open(const char *filename) { int i, data, num_tracks, tempo; char buf[256]; CFILE *fp; hmp_file *hmp; unsigned char *p; if (!(fp = cfopen((char *)filename, "rb"))) return NULL; MALLOC(hmp, hmp_file, 1); if (!hmp) { cfclose(fp); return NULL; } memset(hmp, 0, sizeof(*hmp)); if ((cfread(buf, 1, 8, fp) != 8) || (memcmp(buf, "HMIMIDIP", 8))) { cfclose(fp); hmp_close(hmp); return NULL; } if (cfseek(fp, 0x30, SEEK_SET)) { cfclose(fp); hmp_close(hmp); return NULL; } if (cfread(&num_tracks, 4, 1, fp) != 1) { cfclose(fp); hmp_close(hmp); return NULL; } if ((num_tracks < 1) || (num_tracks > HMP_TRACKS)) { cfclose(fp); hmp_close(hmp); return NULL; } hmp->num_trks = num_tracks; if (cfseek(fp, 0x38, SEEK_SET)) { cfclose(fp); hmp_close(hmp); return NULL; } if (cfread(&tempo, 4, 1, fp) != 1) { cfclose(fp); hmp_close(hmp); return NULL; } hmp->tempo = INTEL_INT(tempo); if (cfseek(fp, 0x308, SEEK_SET)) { cfclose(fp); hmp_close(hmp); return NULL; } for (i = 0; i < num_tracks; i++) { if ((cfseek(fp, 4, SEEK_CUR)) || (cfread(&data, 4, 1, fp) != 1)) { cfclose(fp); hmp_close(hmp); return NULL; } data -= 12; hmp->trks[i].len = data; MALLOC(p, unsigned char, data); if (!(hmp->trks[i].data = p)) { cfclose(fp); hmp_close(hmp); return NULL; } /* finally, read track data */ if ((cfseek(fp, 4, SEEK_CUR)) || (cfread(p, data, 1, fp) != 1)) { cfclose(fp); hmp_close(hmp); return NULL; } } cfclose(fp); return hmp; }
int mus_thread(void *thread_arg) { struct hmp_file *hf; hmpopl *h; char buf[32]; snd = oplsnd_init(); if (oplsnd_open(snd)) { fprintf(stderr, "mus: %s\n", oplsnd_errmsg(snd)); return 0; } for (;;) { while (!mus_switch || !mus_filename) SDL_Delay(1); mus_switch = 0; if (!(h = hmpopl_new())) { fprintf(stderr, "create hmpopl failed\n"); continue; } if (loadbankfile(h, mus_melodic_file, 0)) { fprintf(stderr, "load bnk %s failed\n", mus_melodic_file); continue; } if (loadbankfile(h, mus_drum_file, 1)) { fprintf(stderr, "load bnk %s failed\n", mus_drum_file); continue; } int song_size; void *song_data; if (strlen(mus_filename) < sizeof(buf)) { strcpy(buf, mus_filename); buf[strlen(buf) - 1] = 'q'; song_data = (void *)loadfile(buf, &song_size); } else song_data = NULL; if (!song_data && !(song_data = (void *)loadfile(mus_filename, &song_size))) { fprintf(stderr, "open %s failed\n", mus_filename); continue; } if (!(hf = hmp_open(song_data, song_size, 0xa009))) { fprintf(stderr, "read %s failed\n", mus_filename); continue; } free(song_data); hmpopl_set_write_callback(h, writereg, NULL); hmpopl_start(h); hmpopl_set_write_callback(h, writereg, NULL); hmpopl_start(h); int rc; do { hmp_event ev; hmp_reset_tracks(hf); hmpopl_reset(h); while (!(rc = hmp_get_event(hf, &ev)) && !mus_switch) { if (ev.datalen) continue; if ((ev.msg[0] & 0xf0) == 0xb0 && ev.msg[1] == 7) { int vol = ev.msg[2]; vol = (vol * 127) >> 7; vol = (vol * 127) >> 7; ev.msg[2] = vol; } if (ev.delta) { if (snd) oplsnd_generate_samples(snd, (oplsnd_getfreq(snd) / 120) * ev.delta); } hmpopl_play_midi(h, ev.msg[0] >> 4, ev.msg[0] & 0x0f, ev.msg[1], ev.msg[2]); } } while (!mus_switch && mus_loop); hmpopl_done(h); hmp_close(hf); } return 0; }