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
|
/*************************************************************************
KwaveConnect.cpp - function for connecting Kwave streaming objects
-------------------
begin : Sat Oct 27 2007
copyright : (C) 2007 by Thomas Eschenbacher
email : Thomas.Eschenbacher@gmx.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "config.h"
#include <QObject>
#include "libkwave/Connect.h"
#include "libkwave/SampleSink.h"
#include "libkwave/SampleSource.h"
//***************************************************************************
namespace Kwave {
//***********************************************************************
static bool _connect_one_by_one(
Kwave::StreamObject &src, const char *output, unsigned int src_idx,
Kwave::StreamObject &dst, const char *input, unsigned int dst_idx)
{
Kwave::StreamObject *s = src.port(output, src_idx);
Kwave::StreamObject *d = dst.port(input, dst_idx);
Q_ASSERT(s);
Q_ASSERT(d);
Q_ASSERT(input);
Q_ASSERT(output);
if (!s || !d || !input || !output) return false;
QObject::connect(s, output, d, input, Qt::DirectConnection);
QObject::connect(s, SIGNAL(sigCancel()), d, SLOT(cancel()),
Qt::DirectConnection);
return true;
}
//***********************************************************************
bool connect(Kwave::StreamObject &source, const char *output,
Kwave::StreamObject &sink, const char *input)
{
unsigned int src_tracks = source.tracksOfPort(output);
unsigned int dst_tracks = sink.tracksOfPort(input);
Q_ASSERT(output);
Q_ASSERT(input);
if (!src_tracks || !dst_tracks || !output || !input)
return false;
if ((src_tracks == 1) && (dst_tracks > 1)) {
// 1 output -> N inputs
for (unsigned int track = 0; track < dst_tracks; track++) {
if (!_connect_one_by_one(
source, output, 0,
sink, input, track)) return false;
}
} else if (src_tracks == dst_tracks) {
// N outputs -> N inputs
for (unsigned int track=0; track < dst_tracks; track++) {
if (!_connect_one_by_one(
source, output, track,
sink, input, track)) return false;
}
} else {
qWarning("invalid source/sink combination, %u:%u tracks",
src_tracks, dst_tracks);
return false;
}
return true;
}
}
//***************************************************************************
//***************************************************************************
|