Freeciv-3.1
Loading...
Searching...
No Matches
music.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2005 - The Freeciv Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21
22/* utility */
23#include "connection.h"
24#include "log.h"
25
26/* client */
27#include "audio.h"
28#include "client_main.h"
29#include "options.h"
30
31#include "music.h"
32
33/**********************************************************************/
37{
38 if (client_state() != C_S_RUNNING) {
39 /* Style music plays in running game only */
40 return;
41 }
42
43 if (client.conn.playing == NULL) {
44 /* Detached connections and global observers currently not
45 * supported */
46 return;
47 }
48
50 struct music_style *pms;
51
53
55
56 if (pms != NULL) {
57 const char *tag = NULL;
58
59 switch (client.conn.playing->client.mood) {
60 case MOOD_COUNT:
61 fc_assert(client.conn.playing->client.mood != MOOD_COUNT);
62 fc__fallthrough; /* No break but use default tag */
63 case MOOD_PEACEFUL:
64 tag = pms->music_peaceful;
65 break;
66 case MOOD_COMBAT:
67 tag = pms->music_combat;
68 break;
69 }
70
71 if (tag != NULL && tag[0] != '\0') {
72 log_debug("Play %s", tag);
73 audio_play_music(tag, NULL, MU_INGAME);
74 }
75 }
76 }
77}
78
79/**********************************************************************/
83{
85}
86
87/**********************************************************************/
90void start_menu_music(const char *const tag, char *const alt_tag)
91{
93 audio_play_music(tag, alt_tag, MU_MENU);
94 }
95}
96
97/**********************************************************************/
101{
103}
104
105/**********************************************************************/
108void play_single_track(const char *const tag)
109{
110 if (client_state() != C_S_RUNNING) {
111 /* Only in running game */
112 return;
113 }
114
115 audio_play_track(tag, NULL);
116}
117
118/**********************************************************************/
122{
123 const char *musicset_name = option_str_get(poption);
124
125 audio_restart(sound_set_name, musicset_name);
126
127 /* Start suitable music from the new set */
128 if (client_state() != C_S_RUNNING) {
129 start_menu_music("music_menu", NULL);
130 } else {
132 }
133}
void audio_restart(const char *soundset_name, const char *musicset_name)
Definition audio.c:369
void audio_play_track(const char *const tag, char *const alt_tag)
Definition audio.c:577
void audio_play_music(const char *const tag, char *const alt_tag, enum music_usage usage)
Definition audio.c:566
void audio_stop_usage(void)
Definition audio.c:602
@ MU_INGAME
Definition audio.h:43
@ MU_MENU
Definition audio.h:43
struct civclient client
enum client_states client_state(void)
char sound_set_name[512]
@ C_S_RUNNING
Definition client_main.h:47
#define fc_assert(condition)
Definition log.h:176
#define log_debug(message,...)
Definition log.h:115
void play_single_track(const char *const tag)
Definition music.c:108
void musicspec_reread_callback(struct option *poption)
Definition music.c:121
void start_menu_music(const char *const tag, char *const alt_tag)
Definition music.c:90
void stop_menu_music(void)
Definition music.c:100
void start_style_music(void)
Definition music.c:36
void stop_style_music(void)
Definition music.c:82
const char * option_str_get(const struct option *poption)
Definition options.c:868
struct client_options gui_options
Definition options.c:71
struct connection conn
Definition client_main.h:96
bool sound_enable_menu_music
Definition options.h:181
bool sound_enable_game_music
Definition options.h:182
struct player * playing
Definition connection.h:156
char music_peaceful[MAX_LEN_NAME]
Definition style.h:31
char music_combat[MAX_LEN_NAME]
Definition style.h:32
struct player::@69::@72 client
enum mood_type mood
Definition player.h:361
int music_style
Definition player.h:280
struct music_style * music_style_by_number(int id)
Definition style.c:171
#define fc__fallthrough
Definition support.h:109