summaryrefslogtreecommitdiff
path: root/drumgizmo/input/test.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-06-15 07:53:25 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-06-15 07:54:08 +0200
commit9a0abf4a45c516b15d74ab41f8dab8348d6b00c9 (patch)
tree1e915664db627f2dd124ee08a0cebe3d6c306b3c /drumgizmo/input/test.cc
parent149d86611985b7a382994ac684d555660927e8d2 (diff)
Make sure we abide the samplerate in all input/output engines.
Diffstat (limited to 'drumgizmo/input/test.cc')
-rw-r--r--drumgizmo/input/test.cc21
1 files changed, 13 insertions, 8 deletions
diff --git a/drumgizmo/input/test.cc b/drumgizmo/input/test.cc
index 4789119..6767769 100644
--- a/drumgizmo/input/test.cc
+++ b/drumgizmo/input/test.cc
@@ -35,6 +35,7 @@ TestInputEngine::TestInputEngine()
, probability{0.1}
, instrument{-1}
, length{-1}
+ , sample_rate{44100.0}
{
}
@@ -44,14 +45,14 @@ TestInputEngine::~TestInputEngine()
bool TestInputEngine::init(const Instruments& instruments)
{
- return true;
+ return true;
}
void TestInputEngine::setParm(const std::string& parm, const std::string& value)
{
if(parm == "p")
{
- probability = atof(value.c_str());
+ probability = atof(value.c_str());
}
if(parm == "instr")
{
@@ -65,7 +66,7 @@ void TestInputEngine::setParm(const std::string& parm, const std::string& value)
bool TestInputEngine::start()
{
- return true;
+ return true;
}
void TestInputEngine::stop()
@@ -78,7 +79,7 @@ void TestInputEngine::pre()
void TestInputEngine::run(size_t pos, size_t len, std::vector<event_t>& events)
{
- if((float)rand() / (float)RAND_MAX > probability)
+ if((float)rand() / (float)RAND_MAX > probability)
{
return;
}
@@ -87,17 +88,16 @@ void TestInputEngine::run(size_t pos, size_t len, std::vector<event_t>& events)
auto& event = events.back();
event.type = TYPE_ONSET;
- if(length != -1 && (int)pos > length * 44100)
+ if((length != -1) && (pos > std::llround(length * sample_rate)))
{
event.type = TYPE_STOP;
}
- else
+ else
{
event.type = TYPE_ONSET;
}
-
- if(instrument != -1)
+ if(instrument != -1)
{
event.instrument = instrument;
}
@@ -113,3 +113,8 @@ void TestInputEngine::run(size_t pos, size_t len, std::vector<event_t>& events)
void TestInputEngine::post()
{
}
+
+void TestInputEngine::setSampleRate(double sample_rate)
+{
+ this->sample_rate = sample_rate;
+}