Skip to content

Commit

Permalink
Change OpenTTD#6684: Looping/cutting points for music base sets
Browse files Browse the repository at this point in the history
This fixes bad looping of title screen song from Windows TTD, and fixes
a long silence at the end of "Can't get there from here" from Windows TTD.
  • Loading branch information
nielsmh committed Apr 27, 2018
1 parent 63caaaa commit 299dc30
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
12 changes: 12 additions & 0 deletions bin/baseset/orig_win.obm
Expand Up @@ -142,5 +142,17 @@ GM_TT19.GM = Funk Central
GM_TT20.GM = Jammit
GM_TT21.GM = Movin' On

; MIDI timecodes where the playback should attemp to start and stop short.
; This is to allow fixing undesired silences in original MIDI files.
; However not all music drivers may support this.
[timingtrim]
; Theme has two beats silence at the beginning which prevents clean looping.
GM_TT00.GM = 768:53760
; Can't Get There From Here from the Windows version has a long silence at the end,
; followed by a solo repeat. This isn't in the original DOS version music and is likely
; unintentional from the people who converted the music from the DOS version.
; Actual song ends after measure 152.
GM_TT10.GM = 0:235008

[origin]
default = You can find it on your Transport Tycoon Deluxe CD-ROM.
12 changes: 12 additions & 0 deletions media/baseset/orig_win.obm
Expand Up @@ -90,5 +90,17 @@ GM_TT19.GM = Funk Central
GM_TT20.GM = Jammit
GM_TT21.GM = Movin' On

; MIDI timecodes where the playback should attemp to start and stop short.
; This is to allow fixing undesired silences in original MIDI files.
; However not all music drivers may support this.
[timingtrim]
; Theme has two beats silence at the beginning which prevents clean looping.
GM_TT00.GM = 768:53760
; Can't Get There From Here from the Windows version has a long silence at the end,
; followed by a solo repeat. This isn't in the original DOS version music and is likely
; unintentional from the people who converted the music from the DOS version.
; Actual song ends after measure 152.
GM_TT10.GM = 0:235008

[origin]
default = You can find it on your Transport Tycoon Deluxe CD-ROM.
2 changes: 2 additions & 0 deletions src/base_media_base.h
Expand Up @@ -301,6 +301,8 @@ struct MusicSongInfo {
const char *filename;
MusicTrackType filetype;
int cat_index;
int override_start;
int override_end;
};

/** All data of a music set. */
Expand Down
18 changes: 15 additions & 3 deletions src/music.cpp
Expand Up @@ -129,6 +129,7 @@ bool MusicSet::FillSetDetails(IniFile *ini, const char *path, const char *full_f

IniGroup *names = ini->GetGroup("names");
IniGroup *catindex = ini->GetGroup("catindex");
IniGroup *timingtrim = ini->GetGroup("timingtrim");
for (uint i = 0; i < lengthof(this->songinfo); i++) {
const char *filename = this->files[i].filename;
if (names == NULL || StrEmpty(filename)) {
Expand All @@ -154,15 +155,16 @@ bool MusicSet::FillSetDetails(IniFile *ini, const char *path, const char *full_f
this->songinfo[i].filetype = MTT_STANDARDMIDI;
}

const char *trimmed_filename = filename;
/* As we possibly add a path to the filename and we compare
* on the filename with the path as in the .obm, we need to
* keep stripping path elements until we find a match. */
for (const char *p = filename; p != NULL; p = strchr(p, PATHSEPCHAR)) {
for (; trimmed_filename != NULL; trimmed_filename = strchr(trimmed_filename, PATHSEPCHAR)) {
/* Remove possible double path separator characters from
* the beginning, so we don't start reading e.g. root. */
while (*p == PATHSEPCHAR) p++;
while (*trimmed_filename == PATHSEPCHAR) trimmed_filename++;

item = names->GetItem(p, false);
item = names->GetItem(trimmed_filename, false);
if (item != NULL && !StrEmpty(item->value)) break;
}

Expand All @@ -176,7 +178,17 @@ bool MusicSet::FillSetDetails(IniFile *ini, const char *path, const char *full_f
}
this->num_available++;

/* if there is a theme song, number that one zero */
this->songinfo[i].tracknr = (i==0 && this->has_theme) ? 0 : next_track_nr++;

item = timingtrim->GetItem(trimmed_filename, false);
if (item != NULL && !StrEmpty(item->value)) {
const char *endpos = strchr(item->value, ':');
if (endpos != NULL) {
this->songinfo[i].override_start = atoi(item->value);
this->songinfo[i].override_end = atoi(endpos + 1);
}
}
}
}
return ret;
Expand Down
2 changes: 0 additions & 2 deletions src/music/win32_m.cpp
Expand Up @@ -286,8 +286,6 @@ void CALLBACK TimerCallback(UINT uTimerID, UINT, DWORD_PTR dwUser, DWORD_PTR, DW

void MusicDriver_Win32::PlaySong(const MusicSongInfo &song)
{
if (song.filetype != MTT_STANDARDMIDI) return;

DEBUG(driver, 2, "Win32-MIDI: PlaySong: entry");
EnterCriticalSection(&_midi.lock);

Expand Down

0 comments on commit 299dc30

Please sign in to comment.