Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[6f8185]: libkwave / KwaveConnect.cpp Maximize Restore History

Download this file

KwaveConnect.cpp    77 lines (67 with data), 2.9 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
/*************************************************************************
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.h>
#include <qstring.h>
#include "libkwave/KwaveConnect.h"
#include "libkwave/KwaveSampleSink.h"
#include "libkwave/KwaveSampleSource.h"
//***************************************************************************
namespace Kwave {
bool connect(Kwave::SampleSource &source, const QString &output,
Kwave::SampleSink &sink, const QString &input)
{
unsigned int src_tracks = source.tracks();
unsigned int dst_tracks = sink.tracks();
Q_ASSERT(src_tracks);
Q_ASSERT(dst_tracks);
if (!src_tracks || !dst_tracks)
return false;
Q_ASSERT(output.length());
Q_ASSERT(input.length());
if (!output.length() || !input.length())
return false;
if ((src_tracks == 1) && (dst_tracks == 1)) {
// 1 output -> 1 input
QObject::connect(&source, output, &sink, input);
} else if ((src_tracks == 1) && (dst_tracks > 1)) {
// 1 output -> N inputs
for (unsigned int track=0; track < dst_tracks; track++) {
Kwave::SampleSink *sink_n = sink[track];
Q_ASSERT(sink_n);
if (!sink_n) return false;
QObject::connect(&source, output, sink_n, input);
}
} else if (src_tracks == dst_tracks) {
// N outputs -> N inputs
for (unsigned int track=0; track < dst_tracks; track++) {
Kwave::SampleSource *source_n = source[track];
Kwave::SampleSink *sink_n = sink[track];
Q_ASSERT(source_n);
Q_ASSERT(sink_n);
if (!source_n) return false;
if (!sink_n) return false;
QObject::connect(source_n, output, sink_n, input);
}
} else {
qWarning("invalid source/sink combination, M:N tracks");
return false;
}
return true;
}
}
//***************************************************************************
//***************************************************************************