Subversion Repositories eduke32

Rev

Rev 8390 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8215 terminx 1
//-------------------------------------------------------------------------
2
/*
3
Copyright (C) 2010-2019 EDuke32 developers and contributors
4
Copyright (C) 2019 Nuke.YKT
5
 
6
This file is part of NBlood.
7
 
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
10
as published by the Free Software Foundation.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 
16
See the GNU General Public License for more details.
17
 
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
20
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
*/
22
//-------------------------------------------------------------------------
23
 
24
#include "music.h"
25
 
26
#include "compat.h"
27
#include "drivers.h"
28
#include "midi.h"
29
#include "multivoc.h"
30
#include "sndcards.h"
31
 
32
int MUSIC_ErrorCode = MUSIC_Ok;
33
 
34
static midifuncs MUSIC_MidiFunctions;
35
 
36
#define MUSIC_SetErrorCode(status) MUSIC_ErrorCode = (status);
37
 
8782 terminx 38
const char *MUSIC_ErrorString(int const ErrorNumber)
8215 terminx 39
{
40
    switch (ErrorNumber)
41
    {
42
        case MUSIC_Warning:
8782 terminx 43
        case MUSIC_Error:       return MUSIC_ErrorString(MUSIC_ErrorCode);
44
        case MUSIC_Ok:          return "Music ok.";
45
        case MUSIC_MidiError:   return "Error playing MIDI file.";
46
        default:                return "Unknown Music error code.";
8215 terminx 47
    }
48
}
49
 
50
 
8257 hendricks2 51
int MUSIC_Init(int SoundCard)
8215 terminx 52
{
8218 terminx 53
    int detected = 0;
54
 
55
    if (SoundCard == ASS_AutoDetect)
56
    {
57
redetect:
58
        detected++;
8219 terminx 59
        SoundCard = ASS_OPL3;
8215 terminx 60
    }
61
 
8390 terminx 62
    MV_Printf("Initializing MIDI driver: ");
8381 terminx 63
 
8218 terminx 64
    if (SoundCard < 0 || SoundCard >= ASS_NumSoundCards)
65
    {
66
failed:
67
        MV_Printf("failed!\n");
8215 terminx 68
        MUSIC_ErrorCode = MUSIC_MidiError;
69
        return MUSIC_Error;
70
    }
71
 
72
    if (!SoundDriver_IsMIDISupported(SoundCard))
73
    {
8381 terminx 74
        MV_Printf("%s MIDI output not supported!\n", SoundDriver_GetName(SoundCard));
8218 terminx 75
 
76
        if (detected < 2)
77
            goto redetect;
78
 
79
        goto failed;
8215 terminx 80
    }
81
 
8218 terminx 82
    ASS_MIDISoundDriver = SoundCard;
8215 terminx 83
 
8381 terminx 84
    MV_Printf("%s", SoundDriver_GetName(SoundCard));
85
 
86
    // SoundDriver_MIDI_Init() prints to the same line in the log for the MME driver
8218 terminx 87
    int status = SoundDriver_MIDI_Init(&MUSIC_MidiFunctions);
8215 terminx 88
 
8218 terminx 89
    if (status != MUSIC_Ok)
90
    {
91
        if (detected < 2)
92
            goto redetect;
93
 
94
        goto failed;
95
    }
96
 
8381 terminx 97
    MV_Printf("\n");
8218 terminx 98
    MIDI_SetMidiFuncs(&MUSIC_MidiFunctions);
99
 
100
    return MUSIC_Ok;
8215 terminx 101
}
102
 
103
 
104
int MUSIC_Shutdown(void)
105
{
106
    MIDI_StopSong();
107
    return MUSIC_Ok;
108
}
109
 
110
 
8782 terminx 111
void MUSIC_SetVolume(int volume) { MIDI_SetVolume(clamp(volume, 0, 255)); }
112
int  MUSIC_GetVolume(void)       { return MIDI_GetVolume(); }
113
void MUSIC_SetLoopFlag(int loop) { MIDI_SetLoopFlag(loop); }
114
void MUSIC_Continue(void)        { MIDI_ContinueSong(); }
115
void MUSIC_Pause(void)           { MIDI_PauseSong(); }
8215 terminx 116
 
117
int MUSIC_StopSong(void)
118
{
119
    MIDI_StopSong();
120
    MUSIC_SetErrorCode(MUSIC_Ok);
121
    return MUSIC_Ok;
122
}
123
 
124
 
125
int MUSIC_PlaySong(char *song, int songsize, int loopflag, const char *fn /*= nullptr*/)
126
{
127
    UNREFERENCED_PARAMETER(songsize);
128
    UNREFERENCED_PARAMETER(fn);
129
 
130
    MUSIC_SetErrorCode(MUSIC_Ok)
131
 
132
    if (MIDI_PlaySong(song, loopflag) != MIDI_Ok)
133
    {
134
        MUSIC_SetErrorCode(MUSIC_MidiError);
135
        return MUSIC_Warning;
136
    }
137
 
138
    return MUSIC_Ok;
139
}
140
 
141
 
8782 terminx 142
void MUSIC_Update(void) {}