# Amuse: include/amuse/Sequencer.hpp Source File

Sequencer.hpp
#ifndef __AMUSE_SEQUENCER_HPP__
#define __AMUSE_SEQUENCER_HPP__
#include "Entity.hpp"
#include "AudioGroupProject.hpp"
#include "SongState.hpp"
#include "optional.hpp"
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <list>
namespace amuse
{
class Submix;
class Voice;
enum class SequencerState
{
Playing,
Interactive,
Dead
};
class Sequencer : public Entity
{
friend class Engine;
const SongGroupIndex& m_songGroup;
const SongGroupIndex::MIDISetup* m_midiSetup = nullptr;
Submix* m_submix = nullptr;
std::list<std::shared_ptr<Sequencer>>::iterator m_engineIt;
const unsigned char* m_arrData = nullptr;
SongState m_songState;
double m_ticksPerSec = 1000.0;
SequencerState m_state = SequencerState::Interactive;
bool m_dieOnEnd = false;
float m_curVol = 1.f;
struct ChannelState
{
Sequencer& m_parent;
uint8_t m_chanId;
const SongGroupIndex::MIDISetup& m_setup;
const SongGroupIndex::PageEntry* m_page = nullptr;
Submix* m_submix = nullptr;
~ChannelState();
ChannelState(Sequencer& parent, uint8_t chanId);
std::unordered_map<uint8_t, std::shared_ptr<Voice>> m_chanVoxs;
std::unordered_set<std::shared_ptr<Voice>> m_keyoffVoxs;
int8_t m_ctrlVals[128];
float m_curPitchWheel = 0.f;
int8_t m_curProgram = 0;
float m_curVol = 1.f;
float m_curPan = 0.f;
void _bringOutYourDead();
size_t getVoiceCount() const;
std::shared_ptr<Voice> keyOn(uint8_t note, uint8_t velocity);
void keyOff(uint8_t note, uint8_t velocity);
void setCtrlValue(uint8_t ctrl, int8_t val);
bool programChange(int8_t prog);
void nextProgram();
void prevProgram();
void setPitchWheel(float pitchWheel);
void setVolume(float vol);
void setPan(float pan);
void allOff();
void killKeygroup(uint8_t kg, bool now);
std::shared_ptr<Voice> findVoice(int vid);
void sendMacroMessage(ObjectId macroId, int32_t val);
};
std::array<std::experimental::optional<ChannelState>, 16> m_chanStates;
void _bringOutYourDead();
void _destroy();
public:
~Sequencer();
Sequencer(Engine& engine, const AudioGroup& group, int groupId,
const SongGroupIndex& songGroup, int setupId, Submix* smx);
void advance(double dt);
Submix* getSubmix() {return m_submix;}
SequencerState state() const {return m_state;}
size_t getVoiceCount() const;
std::shared_ptr<Voice> keyOn(uint8_t chan, uint8_t note, uint8_t velocity);
void keyOff(uint8_t chan, uint8_t note, uint8_t velocity);
void setCtrlValue(uint8_t chan, uint8_t ctrl, int8_t val);
void setPitchWheel(uint8_t chan, float pitchWheel);
void allOff(bool now=false);
void killKeygroup(uint8_t kg, bool now);
std::shared_ptr<Voice> findVoice(int vid);
void sendMacroMessage(ObjectId macroId, int32_t val);
void setTempo(double ticksPerSec);
void playSong(const unsigned char* arrData, bool dieOnEnd=true);
void setVolume(float vol);
int8_t getChanProgram(int8_t chanId) const;
bool setChanProgram(int8_t chanId, int8_t prog);
void nextChanProgram(int8_t chanId);
void prevChanProgram(int8_t chanId);
void kill() {m_state = SequencerState::Dead;}
};
}
#endif // __AMUSE_SEQUENCER_HPP__
amuse::SongState
Definition: SongState.hpp:21
amuse::Sequencer::getSubmix
Submix * getSubmix()
Definition: Sequencer.hpp:92
amuse::SongGroupIndex::MIDISetup
Definition: AudioGroupProject.hpp:37
amuse::AudioGroup
Definition: AudioGroup.hpp:16
amuse::SongGroupIndex
Definition: AudioGroupProject.hpp:22
amuse
Definition: AudioGroup.hpp:8
amuse::Submix
Definition: Submix.hpp:20
amuse::SongGroupIndex::PageEntry
Definition: AudioGroupProject.hpp:25
amuse::Engine
Definition: Engine.hpp:23
amuse::Entity
Definition: Entity.hpp:18
amuse::Sequencer::kill
void kill()
Definition: Sequencer.hpp:146
amuse::Sequencer::state
SequencerState state() const
Definition: Sequencer.hpp:95
amuse::Sequencer
Definition: Sequencer.hpp:27