25 #include <QCoreApplication>    32 #include <QStringList>    35 #include <QApplication>    36 #include <QDesktopWidget>    38 #include <QKeySequence>    39 #include <QMouseEvent>    43 #include <KLocalizedString>     62 #define BUFFER_SIZE (64 * 1024)    65 #define MENU_ENTRY(cmd,txt) \    66     emitCommand(entry.arg(_(cmd)).arg(txt));    70                                 const QVariantList &args)
    84 #ifdef HAVE_DEBUG_PLUGIN    85     QString entry = 
_(
"menu(plugin:execute(debug,%1),Calculate/Debug/%2)");
    87     MENU_ENTRY(
"dc_50",             
_(I18N_NOOP(
"Generate 50% DC Level")));
    88     MENU_ENTRY(
"dc_100",            
_(I18N_NOOP(
"Generate 100% DC Level")));
    89     MENU_ENTRY(
"min_max",           
_(I18N_NOOP(
"MinMax Pattern")));
    90     MENU_ENTRY(
"sawtooth",          
_(I18N_NOOP(
"Generate Sawtooth Pattern")));
    91     MENU_ENTRY(
"sawtooth_verify",   
_(I18N_NOOP(
"Verify Sawtooth Pattern")));
    97     MENU_ENTRY(
"labels_at_stripes", 
_(I18N_NOOP(
"Labels at Stripe borders")));
    99     entry = 
_(
"menu(plugin:setup(debug,%1),Help/%2)");
   100     MENU_ENTRY(
"dump_windows",      
_(I18N_NOOP(
"Dump Window Hierarchy")));
   102     entry = 
_(
"menu(%1,Help/%2)");
   103     MENU_ENTRY(
"dump_metadata()",   
_(I18N_NOOP(
"Dump Meta Data")));
   110     if (params.count() < 1) 
return Q_NULLPTR;
   112     QString command = params.first();
   113     QString action = i18n(
"Debug (%1)", command);
   119     if (command == 
_(
"dump_windows")) {
   121     } 
else if (command == 
_(
"window:click")) {
   122         if (params.count() != 4) 
return Q_NULLPTR;
   123         QString    class_name = params[1];
   124         QWidget   *widget     = 
findWidget(class_name.toUtf8().constData());
   125         unsigned int x        = params[2].toUInt();
   126         unsigned int y        = params[3].toUInt();
   127         if (!widget) 
return Q_NULLPTR;
   129         QMouseEvent *press_event =
   130             new QMouseEvent(QEvent::MouseButtonPress,
   132                 widget->mapToGlobal(QPoint(x,y)),
   133                 Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
   134         QCoreApplication::postEvent(widget, press_event);
   136         QMouseEvent *release_event =
   137             new QMouseEvent(QEvent::MouseButtonRelease,
   139                 widget->mapToGlobal(QPoint(x,y)),
   140                 Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
   141         QCoreApplication::postEvent(widget, release_event);
   142     } 
else if (command == 
_(
"window:close")) {
   143         if (params.count() != 2) 
return Q_NULLPTR;
   144         QString    class_name = params[1];
   145         QWidget   *widget     = 
findWidget(class_name.toUtf8().constData());
   147         qDebug(
"close window '%s' [%p]",
   148             DBG(class_name), static_cast<void *>(widget));
   149         if (!widget) 
return Q_NULLPTR;
   151     } 
else if (command == 
_(
"window:mousemove")) {
   152         if (params.count() != 4) 
return Q_NULLPTR;
   153         QString    class_name = params[1];
   154         QWidget   *widget     = 
findWidget(class_name.toUtf8().constData());
   155         unsigned int x        = params[2].toUInt();
   156         unsigned int y        = params[3].toUInt();
   157         if (!widget) 
return Q_NULLPTR;
   159         QMouseEvent *move_event =
   160             new QMouseEvent(QEvent::MouseMove,
   162                 widget->mapToGlobal(QPoint(x,y)),
   163                 Qt::NoButton, Qt::NoButton, Qt::NoModifier);
   164         QCoreApplication::postEvent(widget, move_event);
   165     } 
else if (command == 
_(
"window:resize")) {
   166         if (params.count() != 4) 
return Q_NULLPTR;
   167         QString    class_name = params[1];
   168         QWidget   *widget     = 
findWidget(class_name.toUtf8().constData());
   169         unsigned int width    = params[2].toUInt();
   170         unsigned int height   = params[3].toUInt();
   171         if (!widget) 
return Q_NULLPTR;
   172         widget->resize(width, height);
   173     } 
else if (command == 
_(
"window:screenshot")) {
   174         if (params.count() != 3) 
return Q_NULLPTR;
   176     } 
else if (command == 
_(
"window:sendkey")) {
   177         if (params.count() != 3) 
return Q_NULLPTR;
   178         QString    class_name = params[1];
   179         QString    key_name   = params[2];
   180         QWidget   *widget     = 
findWidget(class_name.toUtf8().constData());
   182         unsigned int          shortcut = QKeySequence::fromString(key_name)[0];
   183         int                   key_code = shortcut & Qt::Key_unknown;
   184         Qt::KeyboardModifiers key_modifiers(shortcut & ~Qt::Key_unknown);
   186         qDebug(
"send key '%s' [0x%08X:0x%08X] to '%s' [%p]",
   187                DBG(key_name), static_cast<int>(key_modifiers), key_code,
   188                DBG(class_name), static_cast<void *>(widget));
   189         if (!widget) 
return Q_NULLPTR;
   192         widget->activateWindow();
   194         widget->setFocus(Qt::OtherFocusReason);
   196         QKeyEvent *press_event =
   197             new QKeyEvent(QEvent::KeyPress, key_code, key_modifiers);
   198         QCoreApplication::postEvent(widget, press_event);
   200         QKeyEvent *release_event =
   201             new QKeyEvent(QEvent::KeyRelease, key_code, key_modifiers);
   202         QCoreApplication::postEvent(widget, release_event);
   206     return new QStringList;
   217     if (params.count() < 1) 
return;
   219     QString command = params.first();
   220     QString action = i18n(
"Debug (%1)", command);
   231     bool make_new_track = (
   232         (command == 
_(
"stripe_index")) ||
   233         (command == 
_(
"offset_in_stripe")) ||
   234         (command == 
_(
"stripe_borders"))
   237     if (command == 
_(
"min_max")) {
   243     if (command == 
_(
"labels_at_stripes")) {
   245         if (all_stripes.isEmpty()) 
return;
   248         unsigned int index = 0;
   251             text = text.sprintf(
"stripe #%d [%llu .. %llu]",
   252                 index++, stripe.
start(), stripe.
end());
   256     } 
else if (command == 
_(
"dump_metadata")) {
   259     } 
else if (command == 
_(
"sawtooth_verify")) {
   263         if (!readers) 
return;
   267         while (ok && (first <= last) && (!
shouldStop())) {
   275             unsigned int count = readers->
tracks();
   276             for (
unsigned int r = 0; ok && (r < count); ++r) {
   278                 for (
unsigned int ofs = 0; ofs < 
m_buffer.
size(); ++ofs) {
   282                     if (value_is != value_should) {
   283                         qWarning(
"ERROR: mismatch detected at offset %llu: "   284                                  "value=%d, expected=%d", pos + ofs,
   285                                  value_is, value_should);
   298             qDebug(
"test pattern successfully detected, no errors :-)");
   305     if (make_new_track) {
   311         QList<unsigned int> track_list;
   312         track_list.append(sig.
tracks() - 1);
   321     if (!writers) 
return; 
   324     if (!writers->
tracks()) 
return;
   326     first = (*writers)[0]->first();
   327     last  = (*writers)[0]->last();
   328     unsigned int count = writers->
tracks();
   331     connect(writers, SIGNAL(progress(qreal)),
   333              Qt::BlockingQueuedConnection);
   349         if (command == 
_(
"fm_sweep")) {
   350             const double f_max = rate / 2.0;
   351             const double f_min = 1;
   352             for (
unsigned int i = 0; i < 
m_buffer.
size(); ++i, ++pos) {
   353                 double t = 
static_cast<double>((pos - left) / rate);
   354                 double f = f_min + (((f_max - f_min) *
   355                     static_cast<double>(pos - left)) /
   356                     static_cast<double>(length));
   357                 double y = 0.707 * sin(M_PI * f * t);
   360         } 
else if (command == 
_(
"sawtooth")) {
   361             for (
unsigned int i = 0; i < 
m_buffer.
size(); ++i, ++pos) {
   365         } 
else if (command == 
_(
"dc_50")) {
   370         } 
else if (command == 
_(
"dc_100")) {
   378         for (
unsigned int w = 0; w < count; ++w) {
   390                                        const QString &indent)
 const   393     const char *classname = obj->metaObject()->className();
   394     qDebug(
"%s - %p [%s]",
   396         static_cast<const void *>(obj),
   400     foreach (QObject *o, obj->children()) {
   409     if (!obj) 
return Q_NULLPTR;
   410     return qobject_cast<QWidget *>(obj);
   415                                         const char *class_name)
 const   417     if (!obj) 
return Q_NULLPTR;
   418     const char *obj_class_name = obj->metaObject()->className();
   419     if (strcmp(class_name, obj_class_name) == 0)
   422     foreach (QObject *o, obj->children()) {
   424         if (result) 
return result; 
   432                                     const QString &filename)
   435     QWidget *widget = 
findWidget(class_name.constData());
   436     qDebug(
"screenshot of '%s' [%p] -> '%s'",
   437         class_name.constData(),
   438         static_cast<void *
>(widget),
   444     const QRect 
rect = widget->windowHandle()->frameGeometry();
   445     QScreen *screen = QGuiApplication::primaryScreen();
   448     QPixmap pixmap = screen->grabWindow(
   449         QApplication::desktop()->winId(),
   451         rect.width(), rect.height()
   455     str = str.sprintf(
"screenshot of %s - [%p] %d/%d %dx%d",
   456         DBG(filename), static_cast<void*>(widget),
   457         rect.x(), rect.y(), rect.width(), rect.height()
   462     QFileInfo file(filename);
   463     QDir dir = file.absoluteDir();
   464     if (!dir.exists()) dir.mkpath(dir.absolutePath());
   467     pixmap.save(filename, 
"PNG", 90);
   471 #include "DebugPlugin.moc" virtual unsigned int tracks() const Q_DECL_OVERRIDE
Kwave::SampleArray m_buffer
void dump_children(const QObject *obj, const QString &indent) const
QWidget * parentWidget() const
virtual unsigned int tracks() const Q_DECL_OVERRIDE
Kwave::MetaDataList & metaData()
Kwave::SignalManager & signalManager()
DebugPlugin(QObject *parent, const QVariantList &args)
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
sample_index_t start() const
virtual void run(QStringList params) Q_DECL_OVERRIDE
virtual QStringList * setup(QStringList ¶ms) Q_DECL_OVERRIDE
sample_index_t end() const
virtual sample_index_t signalLength()
const QList< unsigned int > allTracks()
QWidget * findWidget(const char *class_name) const
Kwave::Label addLabel(sample_index_t pos, const QString &name)
virtual double signalRate()
static sample_t double2sample(const double f)
#define KWAVE_PLUGIN(name, class)
void screenshot(const QByteArray &class_name, const QString &filename)
void fill(sample_t value)
#define MENU_ENTRY(cmd, txt)
virtual void load(QStringList ¶ms) Q_DECL_OVERRIDE
unsigned int size() const
virtual void updateProgress(qreal progress)
const QList< unsigned int > selectedTracks()
static void Q_DECL_EXPORT log(const QObject *sender, LogLevel level, const QString &msg)
QObject * findObject(QObject *obj, const char *class_name) const
static sample_t float2sample(const float f)
virtual ~DebugPlugin() Q_DECL_OVERRIDE
bool resize(unsigned int size) Q_REQUIRED_RESULT
static double rect(double param)
QList< Kwave::Stripe::List > stripes(const QList< unsigned int > &track_list, sample_index_t left=0, sample_index_t right=SAMPLE_INDEX_MAX)