39 lines
1.4 KiB
C++
39 lines
1.4 KiB
C++
#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
|
|
};
|
|
//--------------------------------------------------------------
|