Skip to content

Commit

Permalink
move all the oshu_* symbols under oshu::
Browse files Browse the repository at this point in the history
It bothered me to leave oshu after a half-assed C++ migrations. Some
things were inside the namespace and other had the oshu_ C prefix. Now
the naming scheme is at least consistent.

This refactoring was mostly automated, which is why oshu:: is explicit
in most instances. It doesn’t have to be that way in the future.
  • Loading branch information
fmang committed Mar 28, 2020
1 parent 33bb85e commit ce26e0b
Show file tree
Hide file tree
Showing 64 changed files with 1,354 additions and 1,262 deletions.
96 changes: 50 additions & 46 deletions include/audio/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Definition of the highest-level audio module.
*
* \todo
* Rename this file to engine.h after renaming #oshu_audio.
* Rename this file to engine.h after renaming #oshu::audio.
*/

#pragma once
Expand All @@ -17,6 +17,8 @@

#include <SDL2/SDL.h>

namespace oshu {

/** \defgroup audio Audio
*
* \brief
Expand Down Expand Up @@ -84,45 +86,45 @@
* rankdir=LR
* node [shape=rect]
*
* track1 [label="oshu_track"]
* track2 [label="oshu_track"]
* track3 [label="oshu_track"]
* sample1 [label="oshu_sample"]
* sample2 [label="oshu_sample"]
* track1 [label="oshu::track"]
* track2 [label="oshu::track"]
* track3 [label="oshu::track"]
* sample1 [label="oshu::sample"]
* sample2 [label="oshu::sample"]
* "float*" [shape=none]
* "music.mp3" [shape=none]
* "hit.wav" [shape=none]
* "clap.wav" [shape=none]
*
* "music.mp3" -> "oshu_stream" [label="oshu_open_stream"]
* "oshu_stream" -> "float*" [label="oshu_read_stream"]
* "hit.wav" -> sample1 [label="oshu_load_sample"]
* "clap.wav" -> sample2 [label="oshu_load_sample"]
* sample1 -> track1 [label="oshu_start_track"]
* sample1 -> track2 [label="oshu_start_track"]
* sample2 -> track3 [label="oshu_start_track"]
* track1 -> "float*" [label="oshu_mix_track"]
* track2 -> "float*" [label="oshu_mix_track"]
* track3 -> "float*" [label="oshu_mix_track"]
* "music.mp3" -> "oshu::stream" [label="oshu::open_stream"]
* "oshu::stream" -> "float*" [label="oshu::read_stream"]
* "hit.wav" -> sample1 [label="oshu::load_sample"]
* "clap.wav" -> sample2 [label="oshu::load_sample"]
* sample1 -> track1 [label="oshu::start_track"]
* sample1 -> track2 [label="oshu::start_track"]
* sample2 -> track3 [label="oshu::start_track"]
* track1 -> "float*" [label="oshu::mix_track"]
* track2 -> "float*" [label="oshu::mix_track"]
* track3 -> "float*" [label="oshu::mix_track"]
* "float*" -> "SDL"
* }
* \enddot
*
* ## Use
*
* To use this module, open streams using #oshu_open_audio, and play them using
* #oshu_play_audio. When you're done, close your streams with
* #oshu_pause_audio. Also make sure you initialized SDL with the audio
* To use this module, open streams using #oshu::open_audio, and play them using
* #oshu::play_audio. When you're done, close your streams with
* #oshu::pause_audio. Also make sure you initialized SDL with the audio
* sub-module.
*
* ```c
* SDL_Init(SDL_AUDIO|...);
* struct oshu_audio audio;
* struct oshu::audio audio;
* memset(&audio, 0, sizeof(audio));
* oshu_open_audio("file.ogg", &audio);
* oshu_play_audio(&audio);
* oshu::open_audio("file.ogg", &audio);
* oshu::play_audio(&audio);
* do_things();
* oshu_close_audio(&audio);
* oshu::close_audio(&audio);
* ```
*
* ## Limitations
Expand Down Expand Up @@ -156,11 +158,11 @@
* \todo
* Rename this to oshu::audio::engine.
*/
struct oshu_audio {
struct audio {
/**
* The background music.
*/
struct oshu_stream music;
struct oshu::stream music;
/**
* Tracks for playing sound effects on top of the music.
*
Expand All @@ -169,17 +171,17 @@ struct oshu_audio {
* When the need for looping samples arise, it would be smart to
* dedicate a track for them.
*
* \sa oshu_play_sample
* \sa oshu::play_sample
*/
struct oshu_track effects[16];
struct oshu::track effects[16];
/**
* Special track for the looping sample.
*
* As you can see, only one loop is supported.
*
* \sa oshu_play_loop
* \sa oshu::play_loop
*/
struct oshu_track looping;
struct oshu::track looping;
/**
* A device ID returned by SDL, and required by most SDL audio
* functions.
Expand All @@ -189,7 +191,7 @@ struct oshu_audio {
* Contains the sample rate, format, and channel layout of the audio
* output device.
*
* This is useful for loading samples with #oshu_load_sample.
* This is useful for loading samples with #oshu::load_sample.
*/
SDL_AudioSpec device_spec;
};
Expand All @@ -198,31 +200,31 @@ struct oshu_audio {
* Open a file and initialize everything needed to play it.
*
* \param url Path or URL to the audio file to play.
* \param audio Null-initialized #oshu_audio object.
* \param audio Null-initialized #oshu::audio object.
*
* \return 0 on success. On error, -1 is returned and everything is freed.
*
* \sa oshu_audio_close
*/
int oshu_open_audio(const char *url, struct oshu_audio *audio);
int open_audio(const char *url, struct oshu::audio *audio);

/**
* Start playing!
*
* The SDL plays audio in a separate thread, so you need not worry about
* calling this function regularily or anything. Don't bother, it's magic!
*
* \sa oshu_pause_audio
* \sa oshu::pause_audio
*/
void oshu_play_audio(struct oshu_audio *audio);
void play_audio(struct oshu::audio *audio);

/**
* Pause the stream.
*
* Calling #oshu_play_audio will resume the audio playback where it was
* Calling #oshu::play_audio will resume the audio playback where it was
* left playing.
*/
void oshu_pause_audio(struct oshu_audio *audio);
void pause_audio(struct oshu::audio *audio);

/**
* Play a sample on top of the background music.
Expand All @@ -232,29 +234,29 @@ void oshu_pause_audio(struct oshu_audio *audio);
* reached because all the effects tracks are used, the playback of one of
* the samples is stopped to play the new sample.
*/
void oshu_play_sample(struct oshu_audio *audio, struct oshu_sample *sample, float volume);
void play_sample(struct oshu::audio *audio, struct oshu::sample *sample, float volume);

/**
* Play a looping sample.
*
* Currently, only one looping sample may be played at a time. Calling this
* function cancels any other looping sample.
*
* \sa oshu_play_sample
* \sa oshu_stop_loop
* \sa oshu::play_sample
* \sa oshu::stop_loop
*/
void oshu_play_loop(struct oshu_audio *audio, struct oshu_sample *sample, float volume);
void play_loop(struct oshu::audio *audio, struct oshu::sample *sample, float volume);

/**
* Seek the music stream to the specifed target position in seconds.
*
* See #oshu_seek_stream for details.
* See #oshu::seek_stream for details.
*
* It is similar to #oshu_seek_stream, with the different that this function
* It is similar to #oshu::seek_stream, with the different that this function
* locks the audio thread, and stops all the currently playing sound effects,
* which is definitely what you want.
*/
int oshu_seek_music(struct oshu_audio *audio, double target);
int seek_music(struct oshu::audio *audio, double target);

/**
* Stop the looping sample.
Expand All @@ -263,13 +265,15 @@ int oshu_seek_music(struct oshu_audio *audio, double target);
* future, if more looping samples are supported, this function's prototype
* would change.
*
* \sa oshu_play_loop
* \sa oshu::play_loop
*/
void oshu_stop_loop(struct oshu_audio *audio);
void stop_loop(struct oshu::audio *audio);

/**
* Close the audio stream and free everything associated to it.
*/
void oshu_close_audio(struct oshu_audio *audio);
void close_audio(struct oshu::audio *audio);

/** \} */

}
68 changes: 36 additions & 32 deletions include/audio/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

#include <string>

struct oshu_audio;
struct oshu_sample;

struct SDL_AudioSpec;

namespace oshu {

struct audio;
struct sample;

/**
* \defgroup audio_library Library
* \ingroup audio
Expand Down Expand Up @@ -56,29 +58,29 @@ struct SDL_AudioSpec;
* \{
*/

enum oshu_sound_shelf_index {
enum sound_shelf_index {
/**
* Fallback shelf when a sample is missing from a custom shelf.
*
* The default shelf is built from the default resources, or ideally
* the skin. It is different from shelf 1 which uses the sample files
* in the beatmap directory.
*/
OSHU_DEFAULT_SHELF = 0,
DEFAULT_SHELF = 0,
};

/**
* Each sample in a shelf is a pointer to a sample.
*
* These pointers are NULL when no sample is available.
*/
struct oshu_sound_shelf {
struct oshu_sample *hit_normal;
struct oshu_sample *hit_whistle;
struct oshu_sample *hit_finish;
struct oshu_sample *hit_clap;
struct oshu_sample *slider_slide;
struct oshu_sample *slider_whistle;
struct sound_shelf {
struct oshu::sample *hit_normal;
struct oshu::sample *hit_whistle;
struct oshu::sample *hit_finish;
struct oshu::sample *hit_clap;
struct oshu::sample *slider_slide;
struct oshu::sample *slider_whistle;
};

/**
Expand All @@ -89,7 +91,7 @@ struct oshu_sound_shelf {
*
* More concretely, a room is a dynamically-sized array of shelves.
*/
struct oshu_sound_room {
struct sound_room {
/**
* Location of the shelves.
*
Expand All @@ -98,7 +100,7 @@ struct oshu_sound_room {
*
* \sa size
*/
struct oshu_sound_shelf *shelves;
struct oshu::sound_shelf *shelves;
/**
* Indices of the shelves.
*
Expand Down Expand Up @@ -133,9 +135,9 @@ struct oshu_sound_room {
*
* The library is composed of 3 rooms, one per sample set family.
*
* \sa oshu_sample_set_family
* \sa oshu::sample_set_family
*/
struct oshu_sound_library {
struct sound_library {
/**
* Path to the skin directory, containing the samples.
*
Expand All @@ -155,9 +157,9 @@ struct oshu_sound_library {
* Format of the samples in the library.
*/
struct SDL_AudioSpec *format;
struct oshu_sound_room normal;
struct oshu_sound_room soft;
struct oshu_sound_room drum;
struct oshu::sound_room normal;
struct oshu::sound_room soft;
struct oshu::sound_room drum;
};

/**
Expand All @@ -169,48 +171,50 @@ struct oshu_sound_library {
*
* The library object must be zero-initalized.
*
* \sa oshu_close_sound_library
* \sa oshu::close_sound_library
*/
void oshu_open_sound_library(struct oshu_sound_library *library, struct SDL_AudioSpec *format);
void open_sound_library(struct oshu::sound_library *library, struct SDL_AudioSpec *format);

/**
* Delete all the loaded samples from the library.
*/
void oshu_close_sound_library(struct oshu_sound_library *library);
void close_sound_library(struct oshu::sound_library *library);

/**
* Locate a sample on the filesystem and insert it into the library.
*
* *type* is an OR'd combination of #oshu_sound_type.
* *type* is an OR'd combination of #oshu::sound_type.
*
* \sa oshu_register_sounds
* \sa oshu::register_sound
*/
int oshu_register_sample(struct oshu_sound_library *library, enum oshu_sample_set_family set, int index, int type);
int register_sample(struct oshu::sound_library *library, enum oshu::sample_set_family set, int index, int type);

/**
* Load every sample required to play a hit sound effect.
*
* \sa oshu_register_sample
* \sa oshu_populate_library
* \sa oshu::register_sample
* \sa oshu::populate_library
*/
void oshu_register_sound(struct oshu_sound_library *library, struct oshu_hit_sound *sound);
void register_sound(struct oshu::sound_library *library, struct oshu::hit_sound *sound);

/**
* Find every sample reference into a beatmap and load them into the library.
*
* \sa oshu_register_sounds
* \sa oshu::register_sound
*/
void oshu_populate_library(struct oshu_sound_library *library, struct oshu_beatmap *beatmap);
void populate_library(struct oshu::sound_library *library, struct oshu::beatmap *beatmap);

/**
* Play all the samples associated to the hit sound.
*
* If one of the required samples wasn't found, it is ignored.
*
* If the sound is for a slider, its sample is looped until you call #oshu_stop_loop.
* If the sound is for a slider, its sample is looped until you call #oshu::stop_loop.
*
* \sa oshu_find_sample
*/
void oshu_play_sound(struct oshu_sound_library *library, struct oshu_hit_sound *sound, struct oshu_audio *audio);
void play_sound(struct oshu::sound_library *library, struct oshu::hit_sound *sound, struct oshu::audio *audio);

/** \} */

}
Loading

0 comments on commit ce26e0b

Please sign in to comment.