Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Win32] Low-level DirectMusic MIDI driver #6787

Merged
merged 4 commits into from May 26, 2018
Merged

Conversation

michicc
Copy link
Member

@michicc michicc commented May 20, 2018

This is a re-write of the DirectMusic driver to only rely on low-level functionality that is still present, even on 64-bit Windows systems. It only uses header files that are still present in the current Windows SDK and does not need any of the files from OTTD useful.

It would be an alternative to #6774 and makes #6779 obsolete. The DirectMusic software synth is different from the normal system one, but I'm not sure this is reason enough to keep DirectMusic around.

@michicc michicc added the OS: Windows This issue is related to a MS Windows problem label May 20, 2018
@michicc michicc force-pushed the dmusic_win64 branch 3 times, most recently from aa1eb24 to 7294d76 Compare May 20, 2018 09:11
Copy link
Contributor

@nielsmh nielsmh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd strip any support for the "port" parameter and only ever use the default port = MS softsynth. It'll simplify the initialization code a bit, and probably avoid a bunch of edge cases.


/* Some songs change the "Pitch bend range" registered parameter. If
* this doesn't get reset, everything else will start sounding wrong. */
for (int ch = 0; ch < 16; ch++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to simply move this loop into TransmitNotesOff as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, could do.

clock->GetTime(&current_time);

/* Check for volume change. */
static int volume_throttle = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variable?


/* If we couldn't load the file from the registry, try again at the default install path of the GM DLS file. */
if (dls_file.instruments.size() == 0) {
static const TCHAR *DLS_GM_FILE = _T("%windir%\\drivers\\gm.dls");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong in both Windows 10 and Windows Me, and presumably also everything in between. %WINDIR%\System32\drivers\GM.DLS should be correct, also on 64 bit systems.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I think I had that right and then made some last-minute changes.

return "Failed to activate port";
}
}
const char *dls = LoadDefaultDLSFile(GetDriverParam(parm, "dls"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will likely fail on hardware synths, or really any time not using the default port. Should probably be guarded with pIdx < 0. (Haven't actually tested this yet.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoadDefaultDLSFile is specifically checking for DLS support in the synth.

@michicc
Copy link
Member Author

michicc commented May 20, 2018

Update pushed.

@nielsmh
Copy link
Contributor

nielsmh commented May 20, 2018

Smoke testing is positive, can also confirm it works with hardware synth.

@michicc
Copy link
Member Author

michicc commented May 20, 2018

Updated to solve some delay issues at music start.

@nielsmh nielsmh mentioned this pull request May 21, 2018
_fputts(OTTD2FS(buffer, true), stderr);
TCHAR system_buf[512];
convert_to_fs(buffer, system_buf, lengthof(system_buf), true);
_fputts(system_buf, stderr);
#else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this change do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sure that if you call DEBUG from a thread, it doesn't trash the global string buffer that is used by OTTD2FS.


/** Auto-close a file upon scope exit. */
class FileCloser {
FILE *_f;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our naming convention reserves the _ prefix for globals. I know that's wrong but should we maintain consistency?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably yes.

/** The buffer object collects the data to sent. */
static IDirectMusicBuffer *_buffer = NULL;
/** List of downloaded DLS instruments. */
static std::vector<IDirectMusicDownload *> _dls_downloads;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these globals need to be separate from the _playback variable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do they need to? No. The DMusic interfaces are global in the current driver, so I just went with that.

…th a low-level driver that directly works with MIDI data.

This allows using different music sources besides standard MIDI files on disk.
@michicc michicc merged commit a6300fe into OpenTTD:master May 26, 2018
@michicc michicc deleted the dmusic_win64 branch May 26, 2018 20:28
@nielsmh nielsmh mentioned this pull request May 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS: Windows This issue is related to a MS Windows problem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants