Replace module-level audio functions with proper OOP API: - mcrfpy.Sound: Wraps sf::SoundBuffer + sf::Sound for short effects - mcrfpy.Music: Wraps sf::Music for streaming long tracks - Both support: volume, loop, playing, duration, play/pause/stop - Music adds position property for seeking Add mcrfpy.keyboard singleton for real-time modifier state: - shift, ctrl, alt, system properties (bool, read-only) - Queries sf::Keyboard::isKeyPressed() directly Add mcrfpy.__version__ = "1.0.0" for version identity Remove old audio API entirely (no deprecation - unused in codebase): - createSoundBuffer, loadMusic, playSound - setMusicVolume, getMusicVolume, setSoundVolume, getSoundVolume closes #66, closes #160, closes #164 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
335efc5514
commit
c025cd7da3
11 changed files with 1110 additions and 201 deletions
79
src/PyMusic.h
Normal file
79
src/PyMusic.h
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
#pragma once
|
||||
#include "Common.h"
|
||||
#include "Python.h"
|
||||
|
||||
class PyMusic;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
std::shared_ptr<PyMusic> data;
|
||||
} PyMusicObject;
|
||||
|
||||
class PyMusic : public std::enable_shared_from_this<PyMusic>
|
||||
{
|
||||
private:
|
||||
sf::Music music;
|
||||
std::string source;
|
||||
bool loaded;
|
||||
|
||||
public:
|
||||
PyMusic(const std::string& filename);
|
||||
|
||||
// Playback control
|
||||
void play();
|
||||
void pause();
|
||||
void stop();
|
||||
|
||||
// Properties
|
||||
float getVolume() const;
|
||||
void setVolume(float vol);
|
||||
bool getLoop() const;
|
||||
void setLoop(bool loop);
|
||||
bool isPlaying() const;
|
||||
float getDuration() const;
|
||||
float getPosition() const;
|
||||
void setPosition(float pos);
|
||||
|
||||
// Python interface
|
||||
PyObject* pyObject();
|
||||
static PyObject* repr(PyObject* obj);
|
||||
static Py_hash_t hash(PyObject* obj);
|
||||
static int init(PyMusicObject* self, PyObject* args, PyObject* kwds);
|
||||
static PyObject* pynew(PyTypeObject* type, PyObject* args, PyObject* kwds);
|
||||
|
||||
// Python methods
|
||||
static PyObject* py_play(PyMusicObject* self, PyObject* args);
|
||||
static PyObject* py_pause(PyMusicObject* self, PyObject* args);
|
||||
static PyObject* py_stop(PyMusicObject* self, PyObject* args);
|
||||
|
||||
// Python getters/setters
|
||||
static PyObject* get_volume(PyMusicObject* self, void* closure);
|
||||
static int set_volume(PyMusicObject* self, PyObject* value, void* closure);
|
||||
static PyObject* get_loop(PyMusicObject* self, void* closure);
|
||||
static int set_loop(PyMusicObject* self, PyObject* value, void* closure);
|
||||
static PyObject* get_playing(PyMusicObject* self, void* closure);
|
||||
static PyObject* get_duration(PyMusicObject* self, void* closure);
|
||||
static PyObject* get_position(PyMusicObject* self, void* closure);
|
||||
static int set_position(PyMusicObject* self, PyObject* value, void* closure);
|
||||
static PyObject* get_source(PyMusicObject* self, void* closure);
|
||||
|
||||
static PyMethodDef methods[];
|
||||
static PyGetSetDef getsetters[];
|
||||
};
|
||||
|
||||
namespace mcrfpydef {
|
||||
static PyTypeObject PyMusicType = {
|
||||
.ob_base = {.ob_base = {.ob_refcnt = 1, .ob_type = NULL}, .ob_size = 0},
|
||||
.tp_name = "mcrfpy.Music",
|
||||
.tp_basicsize = sizeof(PyMusicObject),
|
||||
.tp_itemsize = 0,
|
||||
.tp_repr = PyMusic::repr,
|
||||
.tp_hash = PyMusic::hash,
|
||||
.tp_flags = Py_TPFLAGS_DEFAULT,
|
||||
.tp_doc = PyDoc_STR("Streaming music object for longer audio tracks"),
|
||||
.tp_methods = PyMusic::methods,
|
||||
.tp_getset = PyMusic::getsetters,
|
||||
.tp_init = (initproc)PyMusic::init,
|
||||
.tp_new = PyType_GenericNew,
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue