123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- #pragma once
- #include "openmpt/all/BuildSettings.hpp"
- #include "modcommand.h"
- #include "tuningbase.h"
- #include "Snd_defs.h"
- #include "openmpt/base/FlagSet.hpp"
- #include "../common/misc_util.h"
- #include <map>
- #include <set>
- OPENMPT_NAMESPACE_BEGIN
- struct ModChannel;
- struct EnvelopeNode
- {
- using tick_t = uint16;
- using value_t = uint8;
- tick_t tick = 0;
- value_t value = 0;
- EnvelopeNode() { }
- EnvelopeNode(tick_t tick, value_t value) : tick(tick), value(value) { }
- bool operator== (const EnvelopeNode &other) const { return tick == other.tick && value == other.value; }
- };
- struct InstrumentEnvelope : public std::vector<EnvelopeNode>
- {
- FlagSet<EnvelopeFlags> dwFlags;
- uint8 nLoopStart = 0;
- uint8 nLoopEnd = 0;
- uint8 nSustainStart = 0;
- uint8 nSustainEnd = 0;
- uint8 nReleaseNode = ENV_RELEASE_NODE_UNSET;
-
- void Convert(MODTYPE fromType, MODTYPE toType);
-
-
- int32 GetValueFromPosition(int position, int32 rangeOut, int32 rangeIn = ENVELOPE_MAX) const;
-
- void Sanitize(uint8 maxValue = ENVELOPE_MAX);
- uint32 size() const { return static_cast<uint32>(std::vector<EnvelopeNode>::size()); }
- using std::vector<EnvelopeNode>::push_back;
- void push_back(EnvelopeNode::tick_t tick, EnvelopeNode::value_t value) { emplace_back(tick, value); }
- };
- struct ModInstrument
- {
- uint32 nFadeOut = 256;
- uint32 nGlobalVol = 64;
- uint32 nPan = 32 * 4;
- uint16 nVolRampUp = 0;
- ResamplingMode resampling = SRCMODE_DEFAULT;
- FlagSet<InstrumentFlags> dwFlags;
- NewNoteAction nNNA = NewNoteAction::NoteCut;
- DuplicateCheckType nDCT = DuplicateCheckType::None;
- DuplicateNoteAction nDNA = DuplicateNoteAction::NoteCut;
- uint8 nPanSwing = 0;
- uint8 nVolSwing = 0;
- uint8 nIFC = 0;
- uint8 nIFR = 0;
- uint8 nCutSwing = 0;
- uint8 nResSwing = 0;
- FilterMode filterMode = FilterMode::Unchanged;
- int8 nPPS = 0;
- uint8 nPPC = NOTE_MIDDLEC - NOTE_MIN;
- uint16 wMidiBank = 0;
- uint8 nMidiProgram = 0;
- uint8 nMidiChannel = 0;
- uint8 nMidiDrumKey = 0;
- int8 midiPWD = 2;
- PLUGINDEX nMixPlug = 0;
- PlugVelocityHandling pluginVelocityHandling = PLUGIN_VELOCITYHANDLING_CHANNEL;
- PlugVolumeHandling pluginVolumeHandling = PLUGIN_VOLUMEHANDLING_IGNORE;
- TEMPO pitchToTempoLock;
- CTuning *pTuning = nullptr;
- InstrumentEnvelope VolEnv;
- InstrumentEnvelope PanEnv;
- InstrumentEnvelope PitchEnv;
- std::array<uint8, 128> NoteMap;
- std::array<SAMPLEINDEX, 128> Keyboard;
- mpt::charbuf<MAX_INSTRUMENTNAME> name;
- mpt::charbuf<MAX_INSTRUMENTFILENAME> filename;
- std::string GetName() const { return name; }
- std::string GetFilename() const { return filename; }
-
-
-
- ModInstrument(SAMPLEINDEX sample = 0);
-
- void AssignSample(SAMPLEINDEX sample)
- {
- Keyboard.fill(sample);
- }
-
- void ResetNoteMap()
- {
- std::iota(NoteMap.begin(), NoteMap.end(), static_cast<uint8>(NOTE_MIN));
- }
-
-
- std::map<SAMPLEINDEX, int8> CanConvertToDefaultNoteMap() const;
-
- void Transpose(int8 amount);
- bool IsCutoffEnabled() const { return (nIFC & 0x80) != 0; }
- bool IsResonanceEnabled() const { return (nIFR & 0x80) != 0; }
- uint8 GetCutoff() const { return (nIFC & 0x7F); }
- uint8 GetResonance() const { return (nIFR & 0x7F); }
- void SetCutoff(uint8 cutoff, bool enable) { nIFC = std::min(cutoff, uint8(0x7F)) | (enable ? 0x80 : 0x00); }
- void SetResonance(uint8 resonance, bool enable) { nIFR = std::min(resonance, uint8(0x7F)) | (enable ? 0x80 : 0x00); }
- bool HasValidMIDIChannel() const { return (nMidiChannel >= 1 && nMidiChannel <= 17); }
- uint8 GetMIDIChannel(const ModChannel &channel, CHANNELINDEX chn) const;
- void SetTuning(CTuning *pT)
- {
- pTuning = pT;
- }
-
- const InstrumentEnvelope &GetEnvelope(EnvelopeType envType) const
- {
- switch(envType)
- {
- case ENV_VOLUME:
- default:
- return VolEnv;
- case ENV_PANNING:
- return PanEnv;
- case ENV_PITCH:
- return PitchEnv;
- }
- }
- InstrumentEnvelope &GetEnvelope(EnvelopeType envType)
- {
- return const_cast<InstrumentEnvelope &>(static_cast<const ModInstrument &>(*this).GetEnvelope(envType));
- }
-
- std::set<SAMPLEINDEX> GetSamples() const;
-
-
- void GetSamples(std::vector<bool> &referencedSamples) const;
-
- void Convert(MODTYPE fromType, MODTYPE toType);
-
- void Sanitize(MODTYPE modType);
- };
- OPENMPT_NAMESPACE_END
|