Skip to content

Commit

Permalink
add talcs::Dspx
Browse files Browse the repository at this point in the history
  • Loading branch information
CrSjimo committed Jul 20, 2024
1 parent 1454fb2 commit 9a032f9
Show file tree
Hide file tree
Showing 13 changed files with 891 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ option(TALCS_FORMAT "Build talcs::Format library" ON)
option(TALCS_MIDI "Build talcs::Midi library" ON)
option(TALCS_REMOTE "Build talcs::Remote library" ON)
option(TALCS_JUCE_ADAPTER "Build talcs::JuceAdapter library" OFF)
option(TALCS_DSPX "Build talcs::Dspx library" OFF)


# ----------------------------------
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ if(TALCS_JUCE_ADAPTER)
add_subdirectory(juceadapter)
endif()

if(TALCS_DSPX)
add_subdirectory(dspx)
endif()

if(TALCS_INSTALL)
# Add install target
set(_install_dir ${CMAKE_INSTALL_LIBDIR}/cmake/${TALCS_INSTALL_NAME})
Expand Down
9 changes: 9 additions & 0 deletions src/dspx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
project(TalcsDspx VERSION ${TALCS_VERSION} LANGUAGES CXX)

file(GLOB_RECURSE _src *.h *.cpp)

talcs_add_library(${PROJECT_NAME} AUTOGEN
SOURCES ${_src}
LINKS talcs::Core talcs::Format
QT_INCLUDE_PRIVATE Core
)
178 changes: 178 additions & 0 deletions src/dspx/DspxAudioClipContext.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/******************************************************************************
* Copyright (c) 2024 CrSjimo *
* *
* This file is part of TALCS. *
* *
* TALCS is free software: you can redistribute it and/or modify it under the *
* terms of the GNU Lesser General Public License as published by the Free *
* Software Foundation, either version 3 of the License, or (at your option) *
* any later version. *
* *
* TALCS is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for *
* more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with TALCS. If not, see <https://www.gnu.org/licenses/>. *
******************************************************************************/

#include "DspxAudioClipContext.h"
#include "DspxAudioClipContext_p.h"

#include <TalcsCore/PositionableMixerAudioSource.h>
#include <TalcsCore/BufferingAudioSource.h>

#include <TalcsFormat/FormatManager.h>
#include <TalcsFormat/FormatEntry.h>
#include <TalcsFormat/AudioFormatInputSource.h>

#include <TalcsDspx/DspxTrackContext.h>
#include <TalcsDspx/DspxProjectContext.h>

namespace talcs {

DspxAudioClipContext::DspxAudioClipContext(DspxTrackContext *trackContext) : QObject(trackContext), d_ptr(new DspxAudioClipContextPrivate) {
Q_D(DspxAudioClipContext);
d->q_ptr = this;

d->controlMixer = std::make_unique<PositionableMixerAudioSource>();
d->clipMixer = std::make_unique<PositionableMixerAudioSource>();

d->controlMixer->addSource(d->clipMixer.get());

d->trackContext = trackContext;
}

DspxAudioClipContext::~DspxAudioClipContext() {

}

PositionableMixerAudioSource *DspxAudioClipContext::controlMixer() const {
Q_D(const DspxAudioClipContext);
return d->controlMixer.get();
}

PositionableMixerAudioSource *DspxAudioClipContext::clipMixer() const {
Q_D(const DspxAudioClipContext);
return d->clipMixer.get();
}

BufferingAudioSource *DspxAudioClipContext::contentSource() const {
Q_D(const DspxAudioClipContext);
return d->contentSource.get();
}

DspxTrackContext *DspxAudioClipContext::trackContext() const {
Q_D(const DspxAudioClipContext);
return d->trackContext;
}

void DspxAudioClipContext::setStart(int tick) {
Q_D(DspxAudioClipContext);
if (d->startTick != tick) {
d->startTick = tick;
updatePosition();
}
}

int DspxAudioClipContext::start() const {
Q_D(const DspxAudioClipContext);
return d->startTick;
}

void DspxAudioClipContext::setClipStart(int tick) {
Q_D(DspxAudioClipContext);
if (d->clipStartTick != tick) {
d->clipStartTick = tick;
updatePosition();
}
}

int DspxAudioClipContext::clipStart() const {
Q_D(const DspxAudioClipContext);
return d->clipStartTick;
}

void DspxAudioClipContext::setClipLen(int tick) {
Q_D(DspxAudioClipContext);
if (d->clipLenTick != tick) {
d->clipLenTick = tick;
updatePosition();
}
}

int DspxAudioClipContext::clipLen() const {
Q_D(const DspxAudioClipContext);
return d->clipLenTick;
}

void DspxAudioClipContextPrivate::handleIO(AbstractAudioFormatIO *io) {
auto rawSource_ = std::make_unique<AudioFormatInputSource>(io, true);
if (contentSource)
clipMixer->removeSource(contentSource.get());
contentSource.reset(trackContext->projectContext()->makeBufferable(rawSource_.get(), 2));
rawSource = std::move(rawSource_);
clipMixer->prependSource(contentSource.get());
}

bool DspxAudioClipContext::setPathLoad(const QString &path, const QVariant &data) {
Q_D(DspxAudioClipContext);
auto formatManager = d->trackContext->projectContext()->formatManager();
if (!formatManager)
return false;
auto io = formatManager->getFormatLoad(path, data);
if (!io)
return false;
d->handleIO(io);
d->path = path;
return true;
}

bool DspxAudioClipContext::setPathOpen(const QString &path, const QString &filter, QVariant &data) {
Q_D(DspxAudioClipContext);
auto formatManager = d->trackContext->projectContext()->formatManager();
if (!formatManager)
return false;
AbstractAudioFormatIO *io = nullptr;
for (auto entry : formatManager->entries()) {
if (filter.isEmpty() || entry->filters().contains(filter)) {
io = entry->getFormatLoad(path, data);
if (io)
break;
}
}
if (!io)
return false;
d->handleIO(io);
d->path = path;
return true;
}

QString DspxAudioClipContext::path() const {
Q_D(const DspxAudioClipContext);
return d->path;
}

void DspxAudioClipContext::updatePosition() {
Q_D(DspxAudioClipContext);
auto clipSeries = d->trackContext->clipSeries();
auto convertTime = d->trackContext->projectContext()->timeConverter();
auto startSample = convertTime(d->clipStartTick);
clipSeries->setClipStartPos(d->clipView, startSample);
auto firstSample = convertTime(d->startTick + d->clipStartTick);
auto lastSample = convertTime(d->startTick + d->clipStartTick + d->clipLenTick);
clipSeries->setClipRange(d->clipView, firstSample, qMax(qint64(1), lastSample - firstSample));
}

void DspxAudioClipContext::setData(const QVariant &data) {
Q_D(DspxAudioClipContext);
d->data = data;
}

QVariant DspxAudioClipContext::data() const {
Q_D(const DspxAudioClipContext);
return d->data;
}

} // talcs
76 changes: 76 additions & 0 deletions src/dspx/DspxAudioClipContext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/******************************************************************************
* Copyright (c) 2024 CrSjimo *
* *
* This file is part of TALCS. *
* *
* TALCS is free software: you can redistribute it and/or modify it under the *
* terms of the GNU Lesser General Public License as published by the Free *
* Software Foundation, either version 3 of the License, or (at your option) *
* any later version. *
* *
* TALCS is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for *
* more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with TALCS. If not, see <https://www.gnu.org/licenses/>. *
******************************************************************************/

#ifndef TALCS_DSPXAUDIOCLIPCONTEXT_H
#define TALCS_DSPXAUDIOCLIPCONTEXT_H

#include <QObject>
#include <QVariant>

#include <TalcsDspx/TalcsDspxGlobal.h>

namespace talcs {

class PositionableMixerAudioSource;
class BufferingAudioSource;

class DspxTrackContext;

class DspxAudioClipContextPrivate;

class TALCSDSPX_EXPORT DspxAudioClipContext : public QObject {
Q_OBJECT
Q_DECLARE_PRIVATE(DspxAudioClipContext)
friend class DspxTrackContext;
public:
explicit DspxAudioClipContext(DspxTrackContext *trackContext);
~DspxAudioClipContext() override;

PositionableMixerAudioSource *controlMixer() const;
PositionableMixerAudioSource *clipMixer() const;
BufferingAudioSource *contentSource() const;

DspxTrackContext *trackContext() const;

void setStart(int tick);
int start() const;

void setClipStart(int tick);
int clipStart() const;

void setClipLen(int tick);
int clipLen() const;

bool setPathLoad(const QString &path, const QVariant &data = {});
bool setPathOpen(const QString &path, const QString &selectedFilter, QVariant &data);
QString path() const;

void updatePosition();

void setData(const QVariant &data);
QVariant data() const;

private:
QScopedPointer<DspxAudioClipContextPrivate> d_ptr;

};

} // talcs

#endif //TALCS_DSPXAUDIOCLIPCONTEXT_H
59 changes: 59 additions & 0 deletions src/dspx/DspxAudioClipContext_p.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/******************************************************************************
* Copyright (c) 2024 CrSjimo *
* *
* This file is part of TALCS. *
* *
* TALCS is free software: you can redistribute it and/or modify it under the *
* terms of the GNU Lesser General Public License as published by the Free *
* Software Foundation, either version 3 of the License, or (at your option) *
* any later version. *
* *
* TALCS is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for *
* more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with TALCS. If not, see <https://www.gnu.org/licenses/>. *
******************************************************************************/

#ifndef TALCS_DSPXAUDIOCLIPCONTEXT_P_H
#define TALCS_DSPXAUDIOCLIPCONTEXT_P_H

#include <memory>

#include <TalcsCore/AudioSourceClipSeries.h>

#include <TalcsDspx/DspxAudioClipContext.h>

namespace talcs {

class AbstractAudioFormatIO;

class DspxAudioClipContextPrivate {
Q_DECLARE_PUBLIC(DspxAudioClipContext);
public:
DspxAudioClipContext *q_ptr;

std::unique_ptr<PositionableAudioSource> rawSource;
std::unique_ptr<BufferingAudioSource> contentSource;
std::unique_ptr<PositionableMixerAudioSource> clipMixer;
std::unique_ptr<PositionableMixerAudioSource> controlMixer;

DspxTrackContext *trackContext;

AudioSourceClipSeries::ClipView clipView;

int startTick = 0;
int clipStartTick = 0;
int clipLenTick = 0;
QString path;

QVariant data;

void handleIO(AbstractAudioFormatIO *io);

};
}

#endif //TALCS_DSPXAUDIOCLIPCONTEXT_P_H
Loading

0 comments on commit 9a032f9

Please sign in to comment.