Commit aebcb1a9 authored by Yuxuan Shui's avatar Yuxuan Shui Committed by Alexandre Julliard

dmime: Better MIDI parsing interface.

MIDI tracks don't map one-to-one to segment tracks, so it doesn't make sense to use a "get_next_track()" interface.
parent 09c6f48b
...@@ -70,11 +70,8 @@ extern HRESULT create_dmtempotrack(REFIID riid, void **ret_iface); ...@@ -70,11 +70,8 @@ extern HRESULT create_dmtempotrack(REFIID riid, void **ret_iface);
extern HRESULT create_dmtimesigtrack(REFIID riid, void **ret_iface); extern HRESULT create_dmtimesigtrack(REFIID riid, void **ret_iface);
extern HRESULT create_dmwavetrack(REFIID riid, void **ret_iface); extern HRESULT create_dmwavetrack(REFIID riid, void **ret_iface);
/* Create a new MIDI file parser. Note the stream might still be modified even /* Parse a MIDI file. Note the stream might still be modified even when this function fails. */
* when this function fails. */ extern HRESULT parse_midi(IStream *stream, IDirectMusicSegment8 *segment);
extern HRESULT midi_parser_new(IStream *stream, struct midi_parser **out_parser);
extern HRESULT midi_parser_next_track(struct midi_parser *parser, IDirectMusicTrack **out_track, MUSIC_TIME *out_length);
extern void midi_parser_destroy(struct midi_parser *parser);
extern void set_audiopath_perf_pointer(IDirectMusicAudioPath*,IDirectMusicPerformance8*); extern void set_audiopath_perf_pointer(IDirectMusicAudioPath*,IDirectMusicPerformance8*);
extern void set_audiopath_dsound_buffer(IDirectMusicAudioPath*,IDirectSoundBuffer*); extern void set_audiopath_dsound_buffer(IDirectMusicAudioPath*,IDirectSoundBuffer*);
......
...@@ -125,10 +125,10 @@ static HRESULT read_midi_event(IStream *stream, BYTE *last_status, ULONG *bytes_ ...@@ -125,10 +125,10 @@ static HRESULT read_midi_event(IStream *stream, BYTE *last_status, ULONG *bytes_
return S_OK; return S_OK;
} }
HRESULT midi_parser_next_track(struct midi_parser *parser, IDirectMusicTrack **out_track, MUSIC_TIME *out_length) static HRESULT midi_parser_parse(struct midi_parser *parser, IDirectMusicSegment8 *segment)
{ {
WORD i = 0; WORD i = 0;
TRACE("(%p, %p): stub\n", parser, out_length); TRACE("(%p, %p): stub\n", parser, segment);
for (i = 0;; i++) for (i = 0;; i++)
{ {
HRESULT hr; HRESULT hr;
...@@ -159,7 +159,13 @@ HRESULT midi_parser_next_track(struct midi_parser *parser, IDirectMusicTrack **o ...@@ -159,7 +159,13 @@ HRESULT midi_parser_next_track(struct midi_parser *parser, IDirectMusicTrack **o
return S_FALSE; return S_FALSE;
} }
HRESULT midi_parser_new(IStream *stream, struct midi_parser **out_parser) static void midi_parser_destroy(struct midi_parser *parser)
{
IStream_Release(parser->stream);
free(parser);
}
static HRESULT midi_parser_new(IStream *stream, struct midi_parser **out_parser)
{ {
LARGE_INTEGER offset; LARGE_INTEGER offset;
DWORD length; DWORD length;
...@@ -202,8 +208,13 @@ HRESULT midi_parser_new(IStream *stream, struct midi_parser **out_parser) ...@@ -202,8 +208,13 @@ HRESULT midi_parser_new(IStream *stream, struct midi_parser **out_parser)
return hr; return hr;
} }
void midi_parser_destroy(struct midi_parser *parser) HRESULT parse_midi(IStream *stream, IDirectMusicSegment8 *segment)
{ {
IStream_Release(parser->stream); struct midi_parser *parser;
free(parser); HRESULT hr;
if (FAILED(hr = midi_parser_new(stream, &parser))) return hr;
hr = midi_parser_parse(parser, segment);
midi_parser_destroy(parser);
return hr;
} }
...@@ -791,10 +791,7 @@ static inline struct segment *impl_from_IPersistStream(IPersistStream *iface) ...@@ -791,10 +791,7 @@ static inline struct segment *impl_from_IPersistStream(IPersistStream *iface)
static HRESULT WINAPI segment_persist_stream_Load(IPersistStream *iface, IStream *stream) static HRESULT WINAPI segment_persist_stream_Load(IPersistStream *iface, IStream *stream)
{ {
struct segment *This = impl_from_IPersistStream(iface); struct segment *This = impl_from_IPersistStream(iface);
IDirectMusicTrack *track;
MUSIC_TIME length;
struct chunk_entry chunk = {0}; struct chunk_entry chunk = {0};
struct midi_parser *midi_parser;
HRESULT hr; HRESULT hr;
TRACE("(%p, %p): Loading\n", This, stream); TRACE("(%p, %p): Loading\n", This, stream);
...@@ -810,18 +807,7 @@ static HRESULT WINAPI segment_persist_stream_Load(IPersistStream *iface, IStream ...@@ -810,18 +807,7 @@ static HRESULT WINAPI segment_persist_stream_Load(IPersistStream *iface, IStream
break; break;
case mmioFOURCC('M','T','h','d'): case mmioFOURCC('M','T','h','d'):
hr = midi_parser_new(stream, &midi_parser); hr = parse_midi(stream, &This->IDirectMusicSegment8_iface);
if (FAILED(hr)) break;
This->header.mtLength = 0;
while ((hr = midi_parser_next_track(midi_parser, &track, &length)) == S_OK)
{
hr = segment_append_track(This, track, 1, 0);
IDirectMusicTrack_Release(track);
if (FAILED(hr)) break;
if (length > This->header.mtLength)
This->header.mtLength = length;
}
midi_parser_destroy(midi_parser);
break; break;
case MAKE_IDTYPE(FOURCC_RIFF, mmioFOURCC('W','A','V','E')): case MAKE_IDTYPE(FOURCC_RIFF, mmioFOURCC('W','A','V','E')):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment