LV2 Toolkit  1.2.0
workhorse.cpp
#include <unistd.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <cstdlib>
#include <lvtk/plugin.hpp>
/* This is a ttl2c generated header */
#include "workhorse.h"
using namespace lvtk;
using std::vector;
class Workhorse;
Log<false>, Worker<true> > PluginType;
class Workhorse : public PluginType
{
public:
Workhorse (double rate)
: PluginType (p_n_ports),
m_sleeping (false),
log_Entry (map (LV2_LOG__Entry)),
log_Trace (map (LV2_LOG__Trace)),
bufsize (0)
{ }
void
activate()
{
// query for buffer information.
const BufferInfo& info (get_buffer_info());
std::stringstream ss;
ss << "Workhorse Buffer Information:\n";
ss << "\tBuffer Bounded: " << info.bounded << std::endl
<< "\tBuffer Fixed: " << info.fixed << std::endl
<< "\tBuffer Pow of 2: " << info.power_of_two << std::endl
<< "\tBuffer Min: " << info.min << std::endl
<< "\tBuffer Max: " << info.max << std::endl
<< "\tSequence Size: " << info.sequence_size << std::endl;
printf (log_Entry, ss.str().c_str());
}
void
run(uint32_t nframes)
{
static const char* msg = "go to sleep";
if (! m_sleeping)
{
WorkerStatus status (schedule_work (strlen(msg) + 1, (void*)msg));
switch (status)
{
printf (log_Trace, "[workhorse] scheduled a job\n");
m_sleeping = true;
break;
default:
printf (log_Trace, "[workhorse] unknown scheduling error\n");
break;
}
}
}
/* ============================= Worker ============================ */
work_response (uint32_t size, const void* body)
{
printf (log_Trace, "[workhorse] woke up. message: %s\n", (char*)body);
m_sleeping = false;
}
work (WorkerRespond &respond, uint32_t size, const void* data)
{
printf (log_Entry, "[workhorse] taking a nap now\n");
sleep (10);
respond (size, data);
}
uint32_t
get_options (Option*)
{
// Don't have a host for this yet
}
uint32_t
set_options (const Option*)
{
// Don't have a host for this yet
}
private:
bool m_sleeping;
LV2_URID log_Entry;
LV2_URID log_Trace;
uint32_t bufsize;
};
static int _ = Workhorse::register_class (p_uri);