diff options
-rw-r--r-- | dgedit/canvastoollisten.cc | 18 | ||||
-rw-r--r-- | dgedit/canvastoollisten.h | 2 | ||||
-rw-r--r-- | dgedit/mainwindow.cc | 36 | ||||
-rw-r--r-- | dgedit/mainwindow.h | 2 | ||||
-rw-r--r-- | drumgizmo/output/jackaudio/jackaudio.cc | 6 | ||||
-rw-r--r-- | src/drumgizmo.cc | 2 |
6 files changed, 60 insertions, 6 deletions
diff --git a/dgedit/canvastoollisten.cc b/dgedit/canvastoollisten.cc index f638f93..35b619b 100644 --- a/dgedit/canvastoollisten.cc +++ b/dgedit/canvastoollisten.cc @@ -26,6 +26,8 @@ */ #include "canvastoollisten.h" +#include <QApplication> + #define BUFSZ 1024 * 2 Player::Player(Canvas *c) @@ -140,3 +142,19 @@ void CanvasToolListen::setVolume(int v) { player.setVolume(v); } + +#include <unistd.h> +void CanvasToolListen::playRange(unsigned int from, unsigned int to) +{ + player.pos = from; + player.playing = true; + canvas->update(); + timer.start(50); + printf("start\n"); + while(player.pos < to) { + qApp->processEvents(); + usleep(10000); + } + player.playing = false; + printf("stop\n"); +} diff --git a/dgedit/canvastoollisten.h b/dgedit/canvastoollisten.h index 090d83b..dccc3f9 100644 --- a/dgedit/canvastoollisten.h +++ b/dgedit/canvastoollisten.h @@ -64,6 +64,8 @@ public: bool mouseReleaseEvent(QMouseEvent *event); void paintEvent(QPaintEvent *event, QPainter &painter); + void playRange(unsigned int from, unsigned int to); + public slots: void update(); void setVolume(int v); diff --git a/dgedit/mainwindow.cc b/dgedit/mainwindow.cc index 3436c25..dfc150c 100644 --- a/dgedit/mainwindow.cc +++ b/dgedit/mainwindow.cc @@ -57,6 +57,7 @@ static void addTool(QToolBar *toolbar, Canvas *canvas, CanvasTool *tool) canvas->tools.push_back(tool); } +static CanvasToolListen *g_listen; MainWindow::MainWindow() { QWidget *central = new QWidget(); @@ -69,7 +70,8 @@ MainWindow::MainWindow() canvas = new Canvas(this); QToolBar *toolbar = addToolBar("Tools"); - CanvasTool *listen = new CanvasToolListen(canvas); + g_listen = new CanvasToolListen(canvas); + CanvasTool *listen = g_listen; addTool(toolbar, canvas, listen); CanvasTool *threshold = new CanvasToolThreshold(canvas); addTool(toolbar, canvas, threshold); @@ -117,6 +119,13 @@ MainWindow::MainWindow() connect(sorter, SIGNAL(activeSelectionChanged(Selection)), selections, SLOT(setActiveSelection(Selection))); + QPushButton *btn_playsamples = new QPushButton("Play samples"); + connect(btn_playsamples, SIGNAL(clicked()), this, SLOT(playSamples())); + + sb_playsamples = new QScrollBar(Qt::Horizontal); + sb_playsamples->setRange(100, 4000); // ms + + lh->addWidget(canvas); lh->addWidget(yscale); lh->addWidget(yoffset); @@ -124,7 +133,8 @@ MainWindow::MainWindow() lv->addWidget(xscale, 100); lv->addWidget(xoffset, 100); lv->addWidget(sorter, 15); - + lv->addWidget(btn_playsamples); + lv->addWidget(sb_playsamples); QHBoxLayout *btns = new QHBoxLayout(); @@ -248,6 +258,28 @@ MainWindow::MainWindow() statusBar()->showMessage("Ready"); } +void MainWindow::playSamples() +{ + // unsigned int length = 44100 / 4; // 0.25 seconds in 44k1Hz + + Selections sels = sorter->selections(); + Selections::iterator i = sels.begin(); + while(i != sels.end()) { + unsigned int length = sb_playsamples->value() * 44100 / 1000; + + unsigned int sample_length = i->to - i->from; + + unsigned int to = i->to; + unsigned int sleep = 0; + + if(sample_length > length) to = i->from + length; + else sleep = length - sample_length; + g_listen->playRange(i->from, to); + usleep(1000000 * sleep / 44100); + i++; + } +} + void MainWindow::closeEvent(QCloseEvent *) { saveSettings(); diff --git a/dgedit/mainwindow.h b/dgedit/mainwindow.h index fd4af57..c7ce3fb 100644 --- a/dgedit/mainwindow.h +++ b/dgedit/mainwindow.h @@ -60,6 +60,7 @@ public slots: void setYOffset(int); void doExport(); void loadFile(QString filename); + void playSamples(); void setPreset(int); protected: @@ -78,6 +79,7 @@ private: QScrollBar *yscale; QScrollBar *xscale; QScrollBar *xoffset; + QScrollBar *sb_playsamples; QComboBox *presets; QSlider *slider_attacklength; QSlider *slider_falloff; diff --git a/drumgizmo/output/jackaudio/jackaudio.cc b/drumgizmo/output/jackaudio/jackaudio.cc index 385eb48..0fd985e 100644 --- a/drumgizmo/output/jackaudio/jackaudio.cc +++ b/drumgizmo/output/jackaudio/jackaudio.cc @@ -85,7 +85,7 @@ bool JackAudio::init(int nchannels, char *cnames[]) name.c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); - channels[i] = (sample_t*)malloc(1024 * sizeof(sample_t)); + channels[i] = (sample_t*)malloc(16 * sizeof(sample_t)); } return true; } @@ -127,9 +127,9 @@ void JackAudio::post(size_t size) void JackAudio::jack_process(jack_nframes_t nframes) { - if(nframes != 1024) { + if(nframes != 128) { fprintf(stderr, "jackaudio output module currently only works with a" - " bufferszie of 1024 samples!\n"); + " buffersize of 64 samples!\n"); exit(1); } diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index fa26640..4bd6a77 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -288,7 +288,7 @@ void DrumGizmo::run(int endpos) oe->start(); size_t pos = 0; - size_t nsamples = 1024; + size_t nsamples = 128;//1024; sample_t samples[nsamples]; while(run(pos, samples, nsamples) == true) { |