Skip to content

Commit

Permalink
Add m_author field to SoundFile (SuperTux#2617)
Browse files Browse the repository at this point in the history
This field will be later used to display the author of music files
in the level editor.
  • Loading branch information
James De Ricco committed Nov 23, 2023
1 parent 83c9b7d commit 6d77e5d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/audio/ogg_sound_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
#include <assert.h>
#include <physfs.h>

OggSoundFile::OggSoundFile(PHYSFS_File* file_, double loop_begin_, double loop_at_) :
OggSoundFile::OggSoundFile(PHYSFS_File* file_, double loop_begin_, double loop_at_, std::string author) :
SoundFile(author),
m_file(file_),
m_vorbis_file(),
m_loop_begin(),
Expand Down
2 changes: 1 addition & 1 deletion src/audio/ogg_sound_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class OggSoundFile final : public SoundFile
static long cb_tell(void* source);

public:
OggSoundFile(PHYSFS_File* file, double loop_begin, double loop_at);
OggSoundFile(PHYSFS_File* file, double loop_begin, double loop_at, std::string m_author = "");
~OggSoundFile() override;

virtual size_t read(void* buffer, size_t buffer_size) override;
Expand Down
6 changes: 4 additions & 2 deletions src/audio/sound_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ std::unique_ptr<SoundFile> load_music_file(const std::string& filename_original)
auto music = root.get_mapping();

std::string raw_music_file;
std::string author;
float loop_begin = 0;
float loop_at = -1;

music.get("file", raw_music_file);
music.get("author", author);
music.get("loop-begin", loop_begin);
music.get("loop-at", loop_at);

Expand All @@ -85,11 +87,11 @@ std::unique_ptr<SoundFile> load_music_file(const std::string& filename_original)
auto format = SoundFile::get_file_format(file, raw_music_file);
if (format == SoundFile::FORMAT_WAV)
{
return std::make_unique<WavSoundFile>(file);
return std::make_unique<WavSoundFile>(file, author);
}
else
{
return std::make_unique<OggSoundFile>(file, loop_begin, loop_at);
return std::make_unique<OggSoundFile>(file, loop_begin, loop_at, author);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/audio/sound_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ class SoundFile
static FileFormat get_file_format(PHYSFS_File* file, const std::string& filename);

public:
SoundFile() :
SoundFile(std::string author = "") :
m_channels(),
m_rate(),
m_bits_per_sample(),
m_size()
m_size(),
m_author(author)
{}

virtual ~SoundFile() {}
Expand All @@ -52,6 +53,7 @@ class SoundFile
int m_bits_per_sample;
/// size in bytes
size_t m_size;
std::string m_author;

private:
SoundFile(const SoundFile&) = delete;
Expand Down
3 changes: 2 additions & 1 deletion src/audio/wav_sound_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ static inline uint16_t read16LE(PHYSFS_file* file)
return result;
}

WavSoundFile::WavSoundFile(PHYSFS_file* file_) :
WavSoundFile::WavSoundFile(PHYSFS_file* file_, std::string author) :
SoundFile(author),
m_file(file_),
m_datastart()
{
Expand Down
2 changes: 1 addition & 1 deletion src/audio/wav_sound_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class WavSoundFile final : public SoundFile
{
public:
WavSoundFile(PHYSFS_file* file);
WavSoundFile(PHYSFS_file* file, std::string author = "");
~WavSoundFile() override;

virtual size_t read(void* buffer, size_t buffer_size) override;
Expand Down

0 comments on commit 6d77e5d

Please sign in to comment.