Implement midi player using Windows API
This commit is contained in:
38
src/midiPlayer.h
Normal file
38
src/midiPlayer.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "pitches/pitches.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
#include <windows.h>
|
||||
|
||||
// Include the Windows Multimedia API header for MIDI functions
|
||||
#include <mmsystem.h>
|
||||
|
||||
//--------------------------------------------------------------
|
||||
class MidiPlayer
|
||||
{
|
||||
public:
|
||||
MidiPlayer(); // Default constructor
|
||||
virtual ~MidiPlayer(); // Default destructor
|
||||
MidiPlayer(const MidiPlayer &obj) = delete; // Copy constructor
|
||||
MidiPlayer(MidiPlayer &&obj) noexcept = delete; // Move constructor
|
||||
MidiPlayer &operator=(const MidiPlayer &obj) = delete; // Copy assignment operator
|
||||
MidiPlayer &operator=(MidiPlayer &&obj) noexcept = delete; // Move assignment operator
|
||||
|
||||
explicit MidiPlayer(std::span<const pitches::Note> notes); // Constructor
|
||||
|
||||
void setInstrument(uint8_t instrument) const; // Set MIDI instrument
|
||||
void playBuffer(std::span<const pitches::Note> notes) const; // Play a MIDI buffer
|
||||
|
||||
protected:
|
||||
HMIDIOUT m_midiOut = nullptr;
|
||||
uint16_t m_velocity = 127; // MIDI velocity (0-127)
|
||||
|
||||
private:
|
||||
void init(); // Initialize MIDI output
|
||||
void release(); // Release MIDI output
|
||||
|
||||
[[nodiscard]] int frequencyToMidiNote(uint16_t frequency) const; // Convert frequency to MIDI note number
|
||||
};
|
||||
//--------------------------------------------------------------
|
||||
Reference in New Issue
Block a user