add constructor parameter controlling reservation of number of voices
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include "ivoice.h"
|
#include "ivoice.h"
|
||||||
#include "midi_event.h"
|
#include "midi_event.h"
|
||||||
#include "voice_allocator.h"
|
#include "voice_allocator.h"
|
||||||
|
#include <cstddef>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -13,9 +14,12 @@ namespace trnr {
|
|||||||
template <typename t_voice, typename t_sample>
|
template <typename t_voice, typename t_sample>
|
||||||
class midi_synth : public voice_allocator<t_voice, t_sample> {
|
class midi_synth : public voice_allocator<t_voice, t_sample> {
|
||||||
public:
|
public:
|
||||||
midi_synth()
|
midi_synth(size_t voice_reserve = 1)
|
||||||
: m_voices_active {false}
|
: m_voices_active {false}
|
||||||
{
|
{
|
||||||
|
// call base constructor with a reserve of 1 voice
|
||||||
|
voice_allocator<t_voice, t_sample>::set_voice_count(voice_reserve);
|
||||||
|
|
||||||
// checks whether template derives from ivoice
|
// checks whether template derives from ivoice
|
||||||
typedef t_voice assert_at_compile_time[is_convertible<t_voice, t_sample>::value ? 1 : -1];
|
typedef t_voice assert_at_compile_time[is_convertible<t_voice, t_sample>::value ? 1 : -1];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "ivoice.h"
|
#include "ivoice.h"
|
||||||
#include "midi_event.h"
|
#include "midi_event.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cassert>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -14,12 +15,14 @@ class voice_allocator {
|
|||||||
public:
|
public:
|
||||||
std::vector<std::shared_ptr<t_voice>> voice_ptrs;
|
std::vector<std::shared_ptr<t_voice>> voice_ptrs;
|
||||||
|
|
||||||
voice_allocator()
|
voice_allocator(size_t voice_reserve = 1)
|
||||||
{
|
{
|
||||||
// checks whether template derives from ivoice
|
// checks whether template derives from ivoice
|
||||||
typedef t_voice assert_at_compile_time[is_convertible<t_voice, t_sample>::value ? 1 : -1];
|
typedef t_voice assert_at_compile_time[is_convertible<t_voice, t_sample>::value ? 1 : -1];
|
||||||
|
|
||||||
voice_ptrs.reserve(8);
|
assert(voice_reserve > 0 && "voice_reserve must be greater than 0");
|
||||||
|
|
||||||
|
voice_ptrs.reserve(voice_reserve);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_voice_count(const int& voice_count)
|
void set_voice_count(const int& voice_count)
|
||||||
|
|||||||
Reference in New Issue
Block a user