2#include "trkn/tracktion.hh"
22 te::LevelMeasurer::Client meter_client_;
27 float dbspl0 = -100.0f;
28 float dbspl1 = -100.0f;
31 asetrack_ (asetrack), track_state_ (asetrack_.track_->state),
32 telemetry_block_ (SERVER->telemem_allocate (sizeof (
Telemetry))),
33 telemetry (*new (telemetry_block_.block_start)
Telemetry{})
36 if (
auto t = asetrack_.track_.get()) {
38 if (
auto lmp = at->getLevelMeterPlugin()) {
39 measurer_ = &lmp->measurer;
40 measurer_->addClient (meter_client_);
42 if (
auto vol = at->getVolumePlugin()) {
43 volume_plugin_state_ = vol->state;
49 ~TrackStateListener()
override
51 if (volume_plugin_state_.
isValid())
54 measurer_->removeClient (meter_client_);
56 SERVER->telemem_release (telemetry_block_);
62 return { -100.0f, -100.0f };
70 if (tree == track_state_) {
71 if (property == tracktion::engine::IDs::name)
73 if (property == tracktion::engine::IDs::mute)
75 if (property == tracktion::engine::IDs::solo)
78 if (tree == volume_plugin_state_) {
79 if (property == tracktion::engine::IDs::volume)
81 if (property == tracktion::engine::IDs::pan)
84 asetrack_.update_telemetry();
89 void valueTreeChildOrderChanged (
juce::ValueTree&,
int,
int)
override {}
94trkn_track_type (tracktion::Track &track)
100 if (track.isTempoTrack())
102 if (track.isMarkerTrack())
104 if (track.isChordTrack())
106 if (track.isArrangerTrack())
108 if (track.isMasterTrack())
114TrackImpl::from_trkn (tracktion::Track &t)
116 TrackImpl *track = SelectableHandle::find_selectable_handle<TrackImpl> (t);
118 return shared_ptr_cast<TrackImpl> (track);
119 TrackImplP trackp = TrackImpl::make_shared (t);
123TrackImpl::TrackImpl (tracktion::Track &track) :
124 project_ (SelectableHandle::find_selectable_handle<ProjectImpl> (track.edit)),
125 track_ (&track), te_type_ (trkn_track_type (track))
131TrackImpl::TrackImpl (ProjectImpl &project,
bool masterflag) :
134 gadget_flags (masterflag ? MASTER_TRACK : 0);
137TrackImpl::~TrackImpl()
139 state_listener_ =
nullptr;
144TrackImpl::name()
const
146 if (
auto trackp = track_.get())
147 return trackp->getName().toStdString();
154 if (
auto trackp = track_.get())
159TrackImpl::project ()
const
161 return static_cast<ProjectImpl*
> (
_parent());
165TrackImpl::fallback_name()
const
169 if (
auto project_ = project()) {
170 ssize_t i = project_->track_index (*
this);
173 return DeviceImpl::fallback_name();
198 midichannel =
CLAMP (midichannel, 0, 16);
200 midi_channel_ = midichannel;
207 if (
auto t = track_.get())
208 return t->isMuted (
false);
215 if (
auto t = track_.get())
222 if (
auto t = track_.get())
223 return t->isSolo (
false);
230 if (
auto t = track_.get())
237 if (
auto t = track_.get())
238 return t->isMasterTrack();
245 if (
auto t = track_.get())
247 if (
auto vol = at->getVolumePlugin())
248 return vol->getVolumeDb();
255 if (
auto t = track_.get())
257 if (
auto vol = at->getVolumePlugin())
258 vol->setVolumeDb (db);
264 if (
auto t = track_.get())
266 if (
auto vol = at->getVolumePlugin())
267 return vol->getPan();
274 if (
auto t = track_.get())
276 if (
auto vol = at->getVolumePlugin())
284 if (
auto t = track_.get())
286 for (
auto *clip : ct->getClips())
287 if (
auto clipimpl = ClipImpl::from_trkn (*clip))
288 clips.push_back (clipimpl);
293TrackImpl::clip_index (
const ClipImpl &clip)
const
295 if (
auto t = track_.get())
297 auto &clips = ct->getClips();
298 for (
int i = 0; i < clips.size(); i++)
299 if (clips[i] == clip.clip_.get())
306TrackImpl::clip_succession (
const ClipImpl &clip)
const
308 ssize_t idx = clip_index (clip);
311 if (
auto t = track_.get())
313 auto &clips = ct->getClips();
314 if (idx + 1 < clips.size())
327TrackImpl::create_monitor (
int32 ochannel)
337 auto &t = state_listener_->telemetry;
338 v.push_back (telemetry_field (
"dbspl0", &t.dbspl0));
339 v.push_back (telemetry_field (
"dbspl1", &t.dbspl1));
344TrackImpl::update_telemetry()
347 auto &t = state_listener_->telemetry;
348 auto [left, right] = state_listener_->get_levels();
360TrackImpl::ClipScout::ClipScout() noexcept
376 if (previous >= 0 && previous < indices_.size()) {
378 return indices_[last_];
394 indices_ = other.indices_;
398TrackImpl::create_midi_clip (
const String &name,
double start,
double length)
400 if (
auto t = track_.get()) {
401 if (
auto at =
dynamic_cast<tracktion::AudioTrack *
> (t)) {
402 const tracktion::TimeRange range (tracktion::TimePosition::fromSeconds (start), tracktion::TimeDuration::fromSeconds (length));
403 auto clip = at->insertMIDIClip (
juce::String (name), range,
nullptr);
405 return ClipImpl::from_trkn (*clip);
407 warning (
"insertMIDIClip returned null");
410 warning (
"dynamic_cast<AudioTrack*> failed for track type: %s", trkn_track_type (*t).c_str());
413 warning (
"track_.get() returned null");
418TrackImpl::create_audio_clip (
const String &name,
double start,
double length)
420 if (
auto t = track_.get()) {
421 if (
auto ct =
dynamic_cast<tracktion::ClipTrack *
> (t)) {
422 const tracktion::TimeRange range (tracktion::TimePosition::fromSeconds (start), tracktion::TimeDuration::fromSeconds (length));
423 auto clip = ct->insertNewClip (tracktion::TrackItem::Type::wave,
juce::String (name), range,
nullptr);
425 return ClipImpl::from_trkn (*clip);
427 warning (
"insertNewClip returned null");
430 warning (
"dynamic_cast<ClipTrack*> failed for track type: %s", trkn_track_type (*t).c_str());
433 warning (
"track_.get() returned null");
bool is_active() override
Check whether this is the active synthesis engine project.
void _deactivate() override
Stop processing the corresponding AudioProcessor.
void _activate() override
Add AudioProcessor to the Engine and start processing.
void emit_notify(const String &detail) override
Emit notify:detail, multiple notifications maybe coalesced if a CoalesceNotifies instance exists.
GadgetImpl * _parent() const override
Retrieve parent container.
MIDI clip playback succession generator.
int advance(int previous)
Determine clip succession.
void reset()
Reset state (history), preserves succession order.
void setup(const std::vector< int > &indices)
Setup clip succession order.
void update(const ClipScout &other)
Assign new succession order, preserves history.
Ase::Track implementation.
double volume() const override
Get track volume in dB.
double pan() const override
Get track pan (-1.0 to 1.0).
ClipS launcher_clips() override
Retrieve the list of clips that can be directly played.
bool is_muted() const override
Check if track is muted.
void _activate() override
Add AudioProcessor to the Engine and start processing.
void serialize(WritNode &xs) override
Serialize members and childern.
void set_muted(bool muted) override
Set track muted state.
void _deactivate() override
Stop processing the corresponding AudioProcessor.
bool is_master() const override
Flag set on the main output track.
DeviceP access_device() override
Retrieve Device handle for this track.
DeviceInfo device_info() override
Describe this Device type.
TelemetryFieldS telemetry() const override
Create signal monitor for an output channel.
bool is_solo() const override
Check if track is soloed.
int32 midi_channel() const override
Midi channel assigned to this track, 0 uses internal per-track channel.
void set_solo(bool solo) override
Set track solo state.
One entry in a Writ serialization document.
bool isValid() const noexcept
void addListener(Listener *listener)
void removeListener(Listener *listener)
#define assert_return(expr,...)
Return from the current function if expr is unmet and issue an assertion warning.
#define return_unless(cond,...)
Return silently if cond does not evaluate to true with return value ...
#define CLAMP(v, mi, ma)
Yield v clamped to [mi … ma].
The Anklang C++ API namespace.
std::string string_format(const char *format, const Args &...args) __attribute__((__format__(__printf__
Format a string similar to sprintf(3) with support for std::string and std::ostringstream convertible...
int32_t int32
A 32-bit signed integer.
std::string String
Convenience alias for std::string.
RangeType< TimePosition > TimeRange
Reference for an allocated memory block.