Subversion Repositories eduke32

Rev

Rev 8390 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8390 Rev 8782
1
//-------------------------------------------------------------------------
1
//-------------------------------------------------------------------------
2
/*
2
/*
3
Copyright (C) 2010-2019 EDuke32 developers and contributors
3
Copyright (C) 2010-2019 EDuke32 developers and contributors
4
Copyright (C) 2019 Nuke.YKT
4
Copyright (C) 2019 Nuke.YKT
5

5

6
This file is part of NBlood.
6
This file is part of NBlood.
7

7

8
NBlood is free software; you can redistribute it and/or
8
NBlood is free software; you can redistribute it and/or
9
modify it under the terms of the GNU General Public License version 2
9
modify it under the terms of the GNU General Public License version 2
10
as published by the Free Software Foundation.
10
as published by the Free Software Foundation.
11

11

12
This program is distributed in the hope that it will be useful,
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15

15

16
See the GNU General Public License for more details.
16
See the GNU General Public License for more details.
17

17

18
You should have received a copy of the GNU General Public License
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
*/
21
*/
22
//-------------------------------------------------------------------------
22
//-------------------------------------------------------------------------
23
23
24
#include "music.h"
24
#include "music.h"
25
25
26
#include "compat.h"
26
#include "compat.h"
27
#include "drivers.h"
27
#include "drivers.h"
28
#include "midi.h"
28
#include "midi.h"
29
#include "multivoc.h"
29
#include "multivoc.h"
30
#include "sndcards.h"
30
#include "sndcards.h"
31
31
32
int MUSIC_ErrorCode = MUSIC_Ok;
32
int MUSIC_ErrorCode = MUSIC_Ok;
33
33
34
static midifuncs MUSIC_MidiFunctions;
34
static midifuncs MUSIC_MidiFunctions;
35
35
36
#define MUSIC_SetErrorCode(status) MUSIC_ErrorCode = (status);
36
#define MUSIC_SetErrorCode(status) MUSIC_ErrorCode = (status);
37
37
38
const char *MUSIC_ErrorString(int ErrorNumber)
38
const char *MUSIC_ErrorString(int const ErrorNumber)
39
{
39
{
40
    const char *ErrorString;
-
 
41
-
 
42
    switch (ErrorNumber)
40
    switch (ErrorNumber)
43
    {
41
    {
44
        case MUSIC_Warning:
42
        case MUSIC_Warning:
45
        case MUSIC_Error:       ErrorString = MUSIC_ErrorString(MUSIC_ErrorCode); break;
43
        case MUSIC_Error:       return MUSIC_ErrorString(MUSIC_ErrorCode);
46
        case MUSIC_Ok:          ErrorString = "Music ok."; break;
44
        case MUSIC_Ok:          return "Music ok.";
47
        case MUSIC_MidiError:   ErrorString = "Error playing MIDI file."; break;
45
        case MUSIC_MidiError:   return "Error playing MIDI file.";
48
        default:                ErrorString = "Unknown Music error code."; break;
46
        default:                return "Unknown Music error code.";
49
    }
47
    }
50
-
 
51
    return ErrorString;
-
 
52
}
48
}
53
49
54
50
55
int MUSIC_Init(int SoundCard)
51
int MUSIC_Init(int SoundCard)
56
{
52
{
57
    int detected = 0;
53
    int detected = 0;
58
54
59
    if (SoundCard == ASS_AutoDetect)
55
    if (SoundCard == ASS_AutoDetect)
60
    {
56
    {
61
redetect:
57
redetect:
62
        detected++;
58
        detected++;
63
        SoundCard = ASS_OPL3;
59
        SoundCard = ASS_OPL3;
64
    }
60
    }
65
61
66
    MV_Printf("Initializing MIDI driver: ");
62
    MV_Printf("Initializing MIDI driver: ");
67
63
68
    if (SoundCard < 0 || SoundCard >= ASS_NumSoundCards)
64
    if (SoundCard < 0 || SoundCard >= ASS_NumSoundCards)
69
    {
65
    {
70
failed:
66
failed:
71
        MV_Printf("failed!\n");
67
        MV_Printf("failed!\n");
72
        MUSIC_ErrorCode = MUSIC_MidiError;
68
        MUSIC_ErrorCode = MUSIC_MidiError;
73
        return MUSIC_Error;
69
        return MUSIC_Error;
74
    }
70
    }
75
71
76
    if (!SoundDriver_IsMIDISupported(SoundCard))
72
    if (!SoundDriver_IsMIDISupported(SoundCard))
77
    {
73
    {
78
        MV_Printf("%s MIDI output not supported!\n", SoundDriver_GetName(SoundCard));
74
        MV_Printf("%s MIDI output not supported!\n", SoundDriver_GetName(SoundCard));
79
75
80
        if (detected < 2)
76
        if (detected < 2)
81
            goto redetect;
77
            goto redetect;
82
78
83
        goto failed;
79
        goto failed;
84
    }
80
    }
85
81
86
    ASS_MIDISoundDriver = SoundCard;
82
    ASS_MIDISoundDriver = SoundCard;
87
83
88
    MV_Printf("%s", SoundDriver_GetName(SoundCard));
84
    MV_Printf("%s", SoundDriver_GetName(SoundCard));
89
85
90
    // SoundDriver_MIDI_Init() prints to the same line in the log for the MME driver
86
    // SoundDriver_MIDI_Init() prints to the same line in the log for the MME driver
91
    int status = SoundDriver_MIDI_Init(&MUSIC_MidiFunctions);
87
    int status = SoundDriver_MIDI_Init(&MUSIC_MidiFunctions);
92
88
93
    if (status != MUSIC_Ok)
89
    if (status != MUSIC_Ok)
94
    {
90
    {
95
        if (detected < 2)
91
        if (detected < 2)
96
            goto redetect;
92
            goto redetect;
97
93
98
        goto failed;
94
        goto failed;
99
    }
95
    }
100
96
101
    MV_Printf("\n");
97
    MV_Printf("\n");
102
    MIDI_SetMidiFuncs(&MUSIC_MidiFunctions);
98
    MIDI_SetMidiFuncs(&MUSIC_MidiFunctions);
103
99
104
    return MUSIC_Ok;
100
    return MUSIC_Ok;
105
}
101
}
106
102
107
103
108
int MUSIC_Shutdown(void)
104
int MUSIC_Shutdown(void)
109
{
105
{
110
    MIDI_StopSong();
106
    MIDI_StopSong();
111
-
 
112
    return MUSIC_Ok;
107
    return MUSIC_Ok;
113
}
108
}
114
109
115
110
116
void MUSIC_SetVolume(int volume) { MIDI_SetVolume(min(max(0, volume), 255)); }
111
void MUSIC_SetVolume(int volume) { MIDI_SetVolume(clamp(volume, 0, 255)); }
117
-
 
118
-
 
119
int MUSIC_GetVolume(void) { return MIDI_GetVolume(); }
112
int  MUSIC_GetVolume(void)       { return MIDI_GetVolume(); }
120
void MUSIC_SetLoopFlag(int loopflag) { MIDI_SetLoopFlag(loopflag); }
113
void MUSIC_SetLoopFlag(int loop) { MIDI_SetLoopFlag(loop); }
121
void MUSIC_Continue(void) { MIDI_ContinueSong(); }
114
void MUSIC_Continue(void)        { MIDI_ContinueSong(); }
122
void MUSIC_Pause(void) { MIDI_PauseSong(); }
115
void MUSIC_Pause(void)           { MIDI_PauseSong(); }
123
116
124
int MUSIC_StopSong(void)
117
int MUSIC_StopSong(void)
125
{
118
{
126
    MIDI_StopSong();
119
    MIDI_StopSong();
127
    MUSIC_SetErrorCode(MUSIC_Ok);
120
    MUSIC_SetErrorCode(MUSIC_Ok);
128
    return MUSIC_Ok;
121
    return MUSIC_Ok;
129
}
122
}
130
123
131
124
132
int MUSIC_PlaySong(char *song, int songsize, int loopflag, const char *fn /*= nullptr*/)
125
int MUSIC_PlaySong(char *song, int songsize, int loopflag, const char *fn /*= nullptr*/)
133
{
126
{
134
    UNREFERENCED_PARAMETER(songsize);
127
    UNREFERENCED_PARAMETER(songsize);
135
    UNREFERENCED_PARAMETER(fn);
128
    UNREFERENCED_PARAMETER(fn);
136
129
137
    MUSIC_SetErrorCode(MUSIC_Ok)
130
    MUSIC_SetErrorCode(MUSIC_Ok)
138
131
139
    if (MIDI_PlaySong(song, loopflag) != MIDI_Ok)
132
    if (MIDI_PlaySong(song, loopflag) != MIDI_Ok)
140
    {
133
    {
141
        MUSIC_SetErrorCode(MUSIC_MidiError);
134
        MUSIC_SetErrorCode(MUSIC_MidiError);
142
        return MUSIC_Warning;
135
        return MUSIC_Warning;
143
    }
136
    }
144
137
145
    return MUSIC_Ok;
138
    return MUSIC_Ok;
146
}
139
}
147
140
148
141
149
void MUSIC_Update(void)
142
void MUSIC_Update(void) {}
150
{
-
 
151
}
-
 
152
 
143