[DEV] add basic input viewer widget

This commit is contained in:
Edouard DUPIN 2015-06-30 21:29:08 +02:00
parent f791cb3613
commit 0692b6f8bc
11 changed files with 537 additions and 0 deletions

View File

@ -0,0 +1,71 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#include <ewol/ewol.h>
#include <appl/debug.h>
#include <appl/Windows.h>
#include <ewol/widget/Label.h>
#include <ewol/widget/Button.h>
#include <audio/river/widget/TemporalViewer.h>
#include <etk/tool.h>
#undef __class__
#define __class__ "Windows"
static const char* const g_eventChangeValues = "appl-change-value";
static const char* const g_eventAutoMode = "appl-change-auto";
appl::Windows::Windows() :
m_composer(NULL) {
addObjectType("appl::Windows");
}
void appl::Windows::init() {
ewol::widget::Windows::init();
setTitle("example 001_HelloWord");
std::string composition = std::string("");
composition += "<sizer mode='vert'>\n";
composition += " <sizer mode='hori'>\n";
composition += " <button name='bt-record'>\n";
composition += " <label>\n";
composition += " Start/Stop record\n";
composition += " </label>\n";
composition += " </button>\n";
composition += " <button name='bt-generate'>\n";
composition += " <label>\n";
composition += " Start/Stop Generate\n";
composition += " </label>\n";
composition += " </button>\n";
composition += " </sizer>\n";
composition += " <TemporalViewer name='displayer' expand='true' fill='true'/>\n";
composition += "</sizer>\n";
m_composer = ewol::widget::Composer::create(ewol::widget::Composer::String, composition);
if (m_composer == NULL) {
APPL_CRITICAL(" An error occured ... in the windows creatrion ...");
return;
}
setSubWidget(m_composer);
subBind(ewol::widget::Button, "bt-record", signalPressed, shared_from_this(), &appl::Windows::onCallbackRecord);
subBind(ewol::widget::Button, "bt-generate", signalPressed, shared_from_this(), &appl::Windows::onCallbackGenerate);
}
void appl::Windows::onCallbackRecord() {
std::shared_ptr<audio::river::widget::TemporalViewer> tmpDisp = std::dynamic_pointer_cast<audio::river::widget::TemporalViewer>(getSubObjectNamed("displayer"));
if (tmpDisp != NULL) {
tmpDisp->recordToggle();
}
}
void appl::Windows::onCallbackGenerate() {
std::shared_ptr<audio::river::widget::TemporalViewer> tmpDisp = std::dynamic_pointer_cast<audio::river::widget::TemporalViewer>(getSubObjectNamed("displayer"));
if (tmpDisp != NULL) {
tmpDisp->generateToggle();
}
}

View File

@ -0,0 +1,31 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#ifndef __APPL_WINDOWS_H__
#define __APPL_WINDOWS_H__
#include <ewol/widget/Windows.h>
#include <ewol/widget/Composer.h>
namespace appl {
class Windows : public ewol::widget::Windows {
private:
std::shared_ptr<ewol::widget::Composer> m_composer;
protected:
Windows();
void init();
public:
DECLARE_FACTORY(Windows);
public: // callback functions
void onCallbackRecord();
void onCallbackGenerate();
};
};
#endif

View File

@ -0,0 +1,13 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <appl/debug.h>
int32_t appl::getLogId() {
static int32_t g_val = etk::log::registerInstance("ioViewer");
return g_val;
}

View File

@ -0,0 +1,43 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __APPL_DEBUG_H__
#define __APPL_DEBUG_H__
#include <etk/log.h>
namespace appl {
int32_t getLogId();
}
#define APPL_BASE(info,data) TK_LOG_BASE(appl::getLogId(),info,data)
#define APPL_PRINT(data) APPL_BASE(-1, data)
#define APPL_CRITICAL(data) APPL_BASE(1, data)
#define APPL_ERROR(data) APPL_BASE(2, data)
#define APPL_WARNING(data) APPL_BASE(3, data)
#ifdef DEBUG
#define APPL_INFO(data) APPL_BASE(4, data)
#define APPL_DEBUG(data) APPL_BASE(5, data)
#define APPL_VERBOSE(data) APPL_BASE(6, data)
#define APPL_TODO(data) APPL_BASE(4, "TODO : " << data)
#else
#define APPL_INFO(data) do { } while(false)
#define APPL_DEBUG(data) do { } while(false)
#define APPL_VERBOSE(data) do { } while(false)
#define APPL_TODO(data) do { } while(false)
#endif
#define APPL_ASSERT(cond,data) \
do { \
if (!(cond)) { \
APPL_CRITICAL(data); \
assert(!#cond); \
} \
} while (0)
#endif

View File

@ -0,0 +1,74 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#include <etk/types.h>
#include <ewol/ewol.h>
#include <ewol/context/commandLine.h>
#include <appl/debug.h>
#include <appl/Windows.h>
#include <ewol/object/Object.h>
#include <ewol/widget/Manager.h>
#include <ewol/context/Context.h>
#include <audio/river/widget/TemporalViewer.h>
static const std::string configurationRiver =
"{\n"
" microphone:{\n"
" io:'input',\n"
" map-on:{\n"
" interface:'auto',\n"
" name:'default',\n"
" },\n"
" frequency:0,\n"
" channel-map:['front-left', 'front-right'],\n"
" type:'auto',\n"
" nb-chunk:1024\n"
" }\n"
"}\n";
class MainApplication : public ewol::context::Application {
public:
bool init(ewol::Context& _context, size_t _initId) {
APPL_INFO("==> Init APPL (START) [" << ewol::getBoardType() << "] (" << ewol::getCompilationMode() << ")");
audio::river::initString(configurationRiver);
// TODO : Remove this : Move if in the windows properties
_context.setSize(vec2(800, 600));
// select internal data for font ...
_context.getFontDefault().setUseExternal(true);
_context.getFontDefault().set("FreeSerif;DejaVuSansMono", 19);
audio::river::widget::TemporalViewer::createManagerWidget(_context.getWidgetManager());
std::shared_ptr<ewol::widget::Windows> basicWindows = appl::Windows::create();
// create the specific windows
_context.setWindows(basicWindows);
APPL_INFO("==> Init APPL (END)");
return true;
}
void unInit(ewol::Context& _context) {
APPL_INFO("==> Un-Init APPL (START)");
// nothing to do...
APPL_INFO("==> Un-Init APPL (END)");
}
};
/**
* @brief Main of the program (This can be set in every case, but it is not used in Andoid...).
* @param std IO
* @return std IO
*/
int main(int _argc, const char *_argv[]) {
// second possibility
return ewol::run(new MainApplication(), _argc, _argv);
}

View File

@ -0,0 +1,30 @@
#!/usr/bin/python
import lutin.module as module
import lutin.tools as tools
import datetime
def get_desc():
return "Simpleaudio IO viewer and test ..."
def create(target):
myModule = module.Module(__file__, 'ioViewer', 'PACKAGE')
myModule.add_extra_compile_flags()
myModule.add_src_file([
'appl/debug.cpp',
'appl/main.cpp',
'appl/Windows.cpp'])
myModule.add_module_depend(['ewol', 'audio-river', 'audio-river-widget'])
myModule.add_path(tools.get_current_path(__file__))
# set the package properties :
myModule.pkg_set("VERSION", "1.0.0")
myModule.pkg_set("VERSION_CODE", "1")
myModule.pkg_set("COMPAGNY_TYPE", "org")
myModule.pkg_set("COMPAGNY_NAME", "Edouard DUPIN")
myModule.pkg_set("MAINTAINER", ["Mr DUPIN Edouard <yui.heero@gmail.com>"])
myModule.pkg_set("SECTION", ["Development"])
myModule.pkg_set("PRIORITY", "optional")
myModule.pkg_set("DESCRIPTION", "Simple wiewer")
myModule.pkg_set("NAME", "audio-io-viewer")
return myModule

View File

@ -0,0 +1,130 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/river/widget/debug.h>
#include <audio/river/widget/TemporalViewer.h>
#include <etk/tool.h>
#undef __class__
#define __class__ "TemporalViewer"
audio::river::widget::TemporalViewer::TemporalViewer() :
m_minVal(-1.0f),
m_maxVal(1.0f) {
addObjectType("audio::river::widget::TemporalViewer");
}
void audio::river::widget::TemporalViewer::init() {
ewol::Widget::init();
m_manager = audio::river::Manager::create("audio::river::widget::TemporalViewer");
markToRedraw();
}
audio::river::widget::TemporalViewer::~TemporalViewer() {
}
void audio::river::widget::TemporalViewer::onDataReceived(const void* _data,
const audio::Time& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map) {
std11::unique_lock<std11::mutex> lock(m_mutex);
if (_format != audio::format_float) {
std::cout << "[ERROR] call wrong type ... (need int16_t)" << std::endl;
}
// get the curent power of the signal.
const float* data = static_cast<const float*>(_data);
for (size_t iii=0; iii<_nbChunk*_map.size(); ++iii) {
m_data.push_back(data[iii]);
}
const int32_t nbSecond = 3;
if (m_data.size()>_frequency*nbSecond) {
m_data.erase(m_data.begin(), m_data.begin()+(m_data.size()-_frequency*nbSecond));
}
//markToRedraw();
}
void audio::river::widget::TemporalViewer::recordToggle() {
std11::unique_lock<std11::mutex> lock(m_mutex);
if (m_interface == nullptr) {
//Get the generic input:
std::vector<audio::channel> channel;
channel.push_back(audio::channel_frontLeft);
m_interface = m_manager->createInput(48000,
channel,
audio::format_float,
"microphone");
if(m_interface == nullptr) {
ARW_ERROR("nullptr interface");
return;
}
// set callback mode ...
m_interface->setInputCallback(std11::bind(&audio::river::widget::TemporalViewer::onDataReceived,
this,
std11::placeholders::_1,
std11::placeholders::_2,
std11::placeholders::_3,
std11::placeholders::_4,
std11::placeholders::_5,
std11::placeholders::_6));
// start the stream
m_interface->start();
periodicCallEnable();
} else {
m_interface->stop();
m_interface.reset();
periodicCallDisable();
}
}
void audio::river::widget::TemporalViewer::onDraw() {
m_draw.draw();
}
void audio::river::widget::TemporalViewer::onRegenerateDisplay() {
//!< Check if we really need to redraw the display, if not needed, we redraw the previous data ...
if (needRedraw() == false) {
return;
}
// remove previous data
m_draw.clear();
// set background
m_draw.setColor(etk::color::black);
m_draw.setPos(vec2(0,0));
m_draw.rectangleWidth(m_size);
std11::unique_lock<std11::mutex> lock(m_mutex);
if (m_data.size() == 0) {
return;
}
// set all the line:
m_draw.setColor(etk::color::white);
m_draw.setThickness(1);
float origin = m_size.y()*0.5f;
float ratioY = m_size.y() / (m_maxVal - m_minVal);
float stepX = m_size.x() / float(m_data.size());
m_draw.setPos(vec2(0, origin + ratioY*m_data[0]));
float baseX = 0;
for (size_t iii=1; iii<m_data.size(); ++iii) {
m_draw.lineTo(vec2(float(iii)*stepX, origin + ratioY*m_data[iii]));
}
}
void audio::river::widget::TemporalViewer::periodicCall(const ewol::event::Time& _event) {
markToRedraw();
}

View File

@ -0,0 +1,62 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __ARW_TEMPORAL_VIEWER_H__
#define __ARW_TEMPORAL_VIEWER_H__
#include <audio/river/widget/debug.h>
#include <ewol/widget/Widget.h>
#include <ewol/compositing/Drawing.h>
#include <audio/river/river.h>
#include <audio/river/Manager.h>
#include <audio/river/Interface.h>
#include <mutex>
namespace audio {
namespace river {
namespace widget {
class TemporalViewer : public ewol::Widget {
private:
mutable std11::mutex m_mutex;
private:
ewol::compositing::Drawing m_draw; //!< drawing instance
protected:
//! @brief constructor
TemporalViewer();
void init();
public:
DECLARE_WIDGET_FACTORY(TemporalViewer, "TemporalViewer");
//! @brief destructor
virtual ~TemporalViewer();
void recordToggle();
void generateToggle() {
// ...
}
private:
std::vector<float> m_data;
private:
float m_minVal; //!< display minimum value
float m_maxVal; //!< display maximum value
public: // herited function
virtual void onDraw();
virtual void onRegenerateDisplay();
virtual void periodicCall(const ewol::event::Time& _event);
private:
std11::shared_ptr<audio::river::Manager> m_manager;
std11::shared_ptr<audio::river::Interface> m_interface;
void onDataReceived(const void* _data,
const audio::Time& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map);
};
}
}
}
#endif

View File

@ -0,0 +1,13 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/river/widget/debug.h>
int32_t audio::river::widget::getLogId() {
static int32_t g_val = etk::log::registerInstance("audio-river-widget");
return g_val;
}

View File

@ -0,0 +1,47 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __ARW_DEBUG_H__
#define __ARW_DEBUG_H__
#include <etk/log.h>
namespace audio {
namespace river {
namespace widget {
int32_t getLogId();
}
}
}
#define ARW_BASE(info,data) TK_LOG_BASE(audio::river::widget::getLogId(),info,data)
#define ARW_PRINT(data) ARW_BASE(-1, data)
#define ARW_CRITICAL(data) ARW_BASE(1, data)
#define ARW_ERROR(data) ARW_BASE(2, data)
#define ARW_WARNING(data) ARW_BASE(3, data)
#ifdef DEBUG
#define ARW_INFO(data) ARW_BASE(4, data)
#define ARW_DEBUG(data) ARW_BASE(5, data)
#define ARW_VERBOSE(data) ARW_BASE(6, data)
#define ARW_TODO(data) ARW_BASE(4, "TODO : " << data)
#else
#define ARW_INFO(data) do { } while(false)
#define ARW_DEBUG(data) do { } while(false)
#define ARW_VERBOSE(data) do { } while(false)
#define ARW_TODO(data) do { } while(false)
#endif
#define ARW_ASSERT(cond,data) \
do { \
if (!(cond)) { \
ARW_CRITICAL(data); \
assert(!#cond); \
} \
} while (0)
#endif

View File

@ -0,0 +1,23 @@
#!/usr/bin/python
import lutin.module as module
import lutin.tools as tools
import lutin.debug as debug
import os
def get_desc():
return "audio specific widget"
def get_license():
return "APACHE v2.0"
def create(target):
myModule = module.Module(__file__, 'audio-river-widget', 'LIBRARY')
myModule.add_src_file([
'audio/river/widget/TemporalViewer.cpp',
'audio/river/widget/debug.cpp'
])
myModule.add_module_depend(['ewol', 'audio-river'])
myModule.add_export_path(tools.get_current_path(__file__))
return myModule