[c5c04b]: plugins / amptolabel / module.cpp Maximize Restore History

Download this file

module.cpp    144 lines (119 with data), 4.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <stdio.h>
#include <stdlib.h>
#include <qpushbutton.h>
#include <qtooltip.h>
#include <qcombobox.h>
#include <qkeycode.h>
#include "libkwave/Label.h"
#include "libkwave/Global.h"
#include "module.h"
#include <kapp.h>
const char *version = "1.0";
const char *author = "Martin Wilz";
const char *name = "amptolabel";
//**********************************************************
Dialog *getDialog (DialogOperation *operation)
{
return new MarkSignalDialog(operation->getGlobals(),
operation->getRate(), operation->isModal());
}
//**********************************************************
MarkSignalDialog::MarkSignalDialog(Global *globals, int rate,
bool modal)
:Dialog(modal)
{
comstr = 0;
setCaption (i18n("Choose labeling criteria"));
tflag = false;
ok = new QPushButton (OK, this);
cancel = new QPushButton (CANCEL, this);
mark1 = new QLabel (i18n("Start label:"), this);
mark2 = new QLabel (i18n("Stop label:"), this);
timelabel = new QLabel (i18n("Length of silence:"), this);
time = new TimeLine (this, rate);
QToolTip::add( time, i18n("this is the timespan below the defined sound level\nthat is assumed to separate two signals ..."));
time->setMs (400);
ampllabel = new QLabel (i18n("Max. silence level in %"), this);
amplslider = new Slider (1, 1000, 1, 100, Slider::Horizontal, this);
ampl = new FloatLine (this);
ampl->setText ("10.0");
marktype1 = new QComboBox (false, this);
marktype2 = new QComboBox (false, this);
const LabelType *act;
int cnt = 0;
for (act = (globals->markertypes).first(); act; act = (globals->markertypes).next()) {
marktype1->insertItem (act->name);
marktype2->insertItem (act->name);
//just for convenience check for these to label names
if (strcasecmp("start", act->name) == 0) marktype1->setCurrentItem (cnt);
if (strcasecmp("stop", act->name) == 0) marktype2->setCurrentItem (cnt);
cnt++;
}
int bsize = ok->sizeHint().height();
setMinimumSize (320, bsize*10);
ok->setAccel (Key_Return);
cancel->setAccel(Key_Escape);
ok->setFocus ();
connect (ok , SIGNAL(clicked()), SLOT (accept()));
connect (cancel, SIGNAL(clicked()), SLOT (reject()));
connect (amplslider, SIGNAL(valueChanged(int)), SLOT(setAmpl(int)));
connect (ampl, SIGNAL(textChanged(const char *)), SLOT(setAmpl(const char *)));
}
//**********************************************************
const char *MarkSignalDialog::getCommand()
{
deleteString (comstr);
char *tmpstr = catString ("amptolabel (",
ampl->text(),
",", //level
marktype1->currentText(),
",",
marktype2->currentText(),
",");
if (tmpstr) {
comstr = catString (tmpstr,
time->getMsStr(),
")");
deleteString (tmpstr);
}
return comstr;
};
//**********************************************************
void MarkSignalDialog::setAmpl(int val)
{
if (!tflag) {
char buf[128];
snprintf (buf, sizeof(buf), "%d.%d %% ", val / 10, val % 10);
ampl->setText (buf);
}
}
//**********************************************************
void MarkSignalDialog::setAmpl(const char *str)
{
int val = (int)(strtod(str, 0) * 10);
tflag = true;
amplslider->setValue (val);
tflag = false;
}
//**********************************************************
void MarkSignalDialog::resizeEvent(QResizeEvent *)
{
int bsize = ok->sizeHint().height();
timelabel->setGeometry (width() / 10, bsize / 2, width()*4 / 10, bsize);
time->setGeometry (width() / 2 , bsize / 2, width()*4 / 10, bsize);
ampllabel->setGeometry (width() / 10, bsize*2, width()*4 / 10, bsize);
ampl->setGeometry (width() / 2, bsize*2, width()*3 / 20, bsize);
amplslider->setGeometry (width()*7 / 10, bsize*2, width()*2 / 10, bsize);
mark1->setGeometry (width() / 10 , bsize*7 / 2, width()*4 / 10, bsize);
mark2->setGeometry (width() / 10 , bsize*5, width()*4 / 10, bsize);
marktype1->setGeometry (width() / 2 , bsize*7 / 2, width()*4 / 10, bsize);
marktype2->setGeometry (width() / 2 , bsize*5, width()*4 / 10, bsize);
ok->setGeometry (width() / 10, height() - bsize*3 / 2, width()*3 / 10, bsize);
cancel->setGeometry (width()*6 / 10, height() - bsize*3 / 2, width()*3 / 10, bsize);
}
//**********************************************************
MarkSignalDialog::~MarkSignalDialog()
{
deleteString (comstr);
}
//**********************************************************