• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ossia / libossia / 45061331480

22 Nov 2026 07:32PM UTC coverage: 56.861% (+2.9%) from 54.011%
45061331480

Pull #988

github

web-flow
Merge 200fd19ef into 3ad59e1db
Pull Request #988: ossia-max: ossia.v8connector, parameters declared by a v8 script

2254 of 2484 new or added lines in 8 files covered. (90.74%)

780 existing lines in 17 files now uncovered.

37613 of 66149 relevant lines covered (56.86%)

189595.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.27
/src/ossia/dataflow/graph_node.cpp
1
// This is an open source non-commercial project. Dear PVS-Studio, please check
2
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
3
#include <ossia/dataflow/dataflow.hpp>
4
#include <ossia/dataflow/execution_state.hpp>
5
#include <ossia/dataflow/for_each_port.hpp>
6
#include <ossia/dataflow/fx_node.hpp>
7
#include <ossia/dataflow/graph/graph_interface.hpp>
8
#include <ossia/dataflow/graph_edge.hpp>
9
#include <ossia/dataflow/graph_node.hpp>
10
#include <ossia/dataflow/node_process.hpp>
11
#include <ossia/detail/algorithms.hpp>
12
#include <ossia/detail/logger.hpp>
13

14
namespace ossia
15
{
16
audio_buffer_pool::audio_buffer_pool() = default;
11 ✔
17
audio_buffer_pool::~audio_buffer_pool() = default;
11 ✔
18

19
audio_buffer_pool& audio_buffer_pool::instance() noexcept
248,724 ✔
20
{
21
  static audio_buffer_pool p;
248,724 ✔
22
  return p;
248,724 ✔
23
}
24

25
#if defined(OSSIA_SCENARIO_DATAFLOW)
26
node_process::node_process(node_ptr n)
1,068 ✔
27
{
28
  assert(n);
1,068 ✔
29
  node = std::move(n);
1,068 ✔
30
}
1,068 ✔
31

32
void node_process::offset_impl(time_value date) { }
1 ✔
33

34
void node_process::transport_impl(time_value date) { }
321 ✔
35

36
void node_process::start()
1,487 ✔
37
{
38
  // TODO reset all delay buffer positions
39
}
1,487 ✔
40

41
void node_process::stop()
2,185 ✔
42
{
43
  if(node)
2,185 ✔
44
    node->all_notes_off();
2,185 ✔
45
}
2,185 ✔
46

UNCOV
47
void node_process::pause() { }
×
48

UNCOV
49
void node_process::resume() { }
×
50

51
void node_process::mute_impl(bool) { }
3 ✔
52

53
node_process::~node_process() = default;
1,068 ✔
54
#endif
55
/*
56
graph_edge::graph_edge(
57
    connection c, std::size_t pout, std::size_t pin, node_ptr pout_node,
58
    node_ptr pin_node) noexcept
59
    : graph_edge{c, pout_node->outputs()[pout], pin_node->inputs()[pin],
60
                 std::move(pout_node), std::move(pin_node)}
61
{
62
}
63
*/
64
graph_edge::graph_edge(
10,060 ✔
65
    connection c, outlet_ptr pout, inlet_ptr pin, node_ptr pout_node,
66
    node_ptr pin_node) noexcept
10,060 ✔
67
    : con{c}
10,060 ✔
68
    , out{std::move(pout)}
10,060 ✔
69
    , in{std::move(pin)}
10,060 ✔
70
    , out_node{std::move(pout_node)}
10,060 ✔
71
    , in_node{std::move(pin_node)}
10,060 ✔
72
{
73
  assert(out_node);
10,060 ✔
74
  assert(in_node);
10,060 ✔
75
}
10,060 ✔
76

77
template <typename T>
78
struct alloc_observer
79
{
80
  std::allocator<T> alloc;
81
  std::size_t& request;
82
  template <typename U>
83
  using rebind = alloc_observer<U>;
84
  using value_type = T;
85

86
  alloc_observer(std::size_t& request) noexcept
76 ✔
87
      : request(request)
76 ✔
88
  {
89
    // Tricky note: std::make/allocate_shared store the allocator. Thus the allocated size depend on alloc_observer / edge_pool_alloc size.
90
    // To get the correct size, we have to make sure that sizeof(alloc_observer) == sizeof(edge_pool_alloc) (which is just a shared_ptr)
91

92
    static_assert(sizeof(alloc_observer<T>) == sizeof(std::shared_ptr<int>));
93
  }
76 ✔
94

95
  template <typename U>
96
  alloc_observer(alloc_observer<U> const& other) noexcept
152 ✔
97
      : request(other.request)
152 ✔
98
  {
99
    static_assert(sizeof(alloc_observer<T>) == sizeof(std::shared_ptr<int>));
100
    static_assert(sizeof(alloc_observer<U>) == sizeof(std::shared_ptr<int>));
101
  }
152 ✔
102

103
  T* allocate(const std::size_t n) noexcept
76 ✔
104
  {
105
    request = sizeof(T);
76 ✔
106
    return alloc.allocate(n);
152 ✔
107
  }
108
  void deallocate(T* ptr, const size_t n) noexcept { return alloc.deallocate(ptr, n); }
152 ✔
109
};
110

111
std::size_t graph_edge::size_of_allocated_memory_by_make_shared() noexcept
76 ✔
112
{
113
  struct private_bypass : graph_edge
114
  {
115
  public:
116
    private_bypass() = default;
76 ✔
117
  };
118
  std::size_t request{};
76 ✔
119
  alloc_observer<private_bypass> alloc{request};
76 ✔
120

121
  std::allocate_shared<private_bypass, alloc_observer<private_bypass>>(alloc);
76 ✔
122

123
  return request;
152 ✔
124
}
76 ✔
125

126
void graph_edge::init() noexcept
48 ✔
127
{
128
  if(in && out && in_node && out_node)
48 ✔
129
  {
130
    bool found_in = false;
47 ✔
131
    bool found_out = false;
47 ✔
132
    ossia::for_each_inlet(*in_node, [&](ossia::inlet& e) { found_in |= &e == in; });
47 ✔
133
    ossia::for_each_outlet(*out_node, [&](ossia::outlet& e) { found_out |= &e == out; });
47 ✔
134
    if(!found_in || !found_out)
47 ✔
135
    {
136
      ossia::logger().error("Trying to connect missing inlets / outlets");
×
UNCOV
137
      return;
×
138
    }
139
    out->connect(this);
47 ✔
140
    in->connect(this);
47 ✔
141

142
    if(auto delay = con.target<delayed_glutton_connection>())
94 ✔
143
    {
144
      out->visit(init_delay_line{delay->buffer});
2 ✔
145
    }
146
    else if(auto sdelay = con.target<delayed_strict_connection>())
90 ✔
147
    {
148
      out->visit(init_delay_line{sdelay->buffer});
1 ✔
149
    }
150
  }
151
  else
152
  {
153
    ossia::logger().error("Missing in_node / out_node");
1 ✔
154
  }
155
}
156

157
graph_edge::~graph_edge()
10,136 ✔
158
{
159
  clear();
10,136 ✔
160
}
10,136 ✔
161

162
void graph_edge::clear() noexcept
10,184 ✔
163
{
164
  if(in && out && in_node && out_node)
10,184 ✔
165
  {
166
    bool found_in = false;
10,052 ✔
167
    bool found_out = false;
10,052 ✔
168
    ossia::for_each_inlet(*in_node, [&](ossia::inlet& e) { found_in |= &e == in; });
10,052 ✔
169
    ossia::for_each_outlet(*out_node, [&](ossia::outlet& e) { found_out |= &e == out; });
10,052 ✔
170
    if(found_in && found_out)
10,052 ✔
171
    {
172
      // Whatever the source left sounding through this cable would never be
173
      // stopped: the sink finds the note offs in its inlet the next time it
174
      // runs.
175
      if(out->which() == midi_port::which && in->which() == midi_port::which)
10,052 ✔
176
      {
177
        static_cast<const midi_outlet*>(out)->held.release(
21 ✔
178
            static_cast<midi_inlet*>(in)->data.messages);
21 ✔
179
      }
180

181
      out->disconnect(this);
10,052 ✔
182
      in->disconnect(this);
10,052 ✔
183
    }
184
    else
185
    {
UNCOV
186
      ossia::logger().error("Trying to disconnect missing inlets / outlets");
×
187
    }
188
  }
189

190
  con = connection{};
10,184 ✔
191
  out = {};
10,184 ✔
192
  in = {};
10,184 ✔
193
  out_node.reset();
10,184 ✔
194
  in_node.reset();
10,184 ✔
195
}
10,184 ✔
196

197
graph_node::~graph_node()
12,477 ✔
198
{
199
  for(auto inl : m_inlets)
45,910 ✔
200
    delete inl;
10,478 ✔
201
  for(auto outl : m_outlets)
45,910 ✔
202
    delete outl;
10,478 ✔
203
}
12,477 ✔
204

205
void graph_node::prepare(const execution_state& st) noexcept
×
206
{
207
  struct
208
  {
209
    std::size_t buffer_size{};
210
    void operator()(ossia::audio_port& p) const noexcept
×
211
    {
212
      if(p.empty())
×
UNCOV
213
        p.set_channels(2);
×
214

215
      for(auto& c : p.get())
×
216
      {
217
        c.shrink_to_fit();
×
UNCOV
218
        c.reserve(buffer_size);
×
219
      }
UNCOV
220
    }
×
221
    void operator()(ossia::midi_port& p) const noexcept { }
×
UNCOV
222
    void operator()(ossia::value_port& p) const noexcept { }
×
223
    void operator()(ossia::geometry_port& p) const noexcept { }
UNCOV
224
  } vis;
×
UNCOV
225
  for(auto& in : this->m_inlets)
×
226
  {
227
    in->visit(vis);
×
228
  }
229
  for(auto& out : this->m_outlets)
×
230
  {
UNCOV
231
    out->visit(vis);
×
232
  }
UNCOV
233
}
×
234

235
graph_node::graph_node() noexcept = default;
12,477 ✔
236

UNCOV
237
bool graph_node::consumes(const execution_state&) const noexcept
×
238
{
239
  return false;
×
240
}
241

UNCOV
242
void graph_node::run(const token_request& t, exec_state_facade) noexcept { }
×
243

244
std::string graph_node::label() const noexcept
×
245
{
246
  return {};
×
247
}
248

UNCOV
249
bool graph_node::has_port_inputs() const noexcept
×
250
{
251
  return any_of_inlet(*this, [](const inlet& inlet) { return !inlet.sources.empty(); });
×
252
}
253

254
bool graph_node::has_global_inputs() const noexcept
×
255
{
256
  return any_of_inlet(*this, [&](const inlet& inlet) {
×
UNCOV
257
    return (inlet.scope & port::scope_t::global) && bool(inlet.address);
×
UNCOV
258
  });
×
259
}
260

261
bool graph_node::has_local_inputs(const execution_state& st) const noexcept
×
262
{
263
  return any_of_inlet(*this, [&](const inlet& inlet) {
×
264
    if(inlet.scope & port::scope_t::local)
×
265
    {
UNCOV
266
      bool b = false;
×
267

268
      // TODO optimize by stopping when found
UNCOV
269
      apply_to_destination(
×
270
          inlet.address, st.exec_devices(),
×
271
          [&](ossia::net::parameter_base* addr, bool) {
×
UNCOV
272
        if(!b || st.in_local_scope(*addr))
×
273
          b = true;
×
274
          },
×
275
          do_nothing_for_nodes{});
276

UNCOV
277
      if(b)
×
UNCOV
278
        return true;
×
279

UNCOV
280
      if(consumes(st))
×
UNCOV
281
        return true;
×
282
    }
UNCOV
283
    return false;
×
UNCOV
284
  });
×
285
}
286

287
void graph_node::clear() noexcept
119 ✔
288
{
289
  for_each_inlet(*this, [](auto& port) {
252 ✔
290
    for(ossia::graph_edge* e : port.cables())
266 ✔
291
    {
UNCOV
292
      e->clear();
×
293
    }
294
  });
133 ✔
295
  for_each_outlet(*this, [](auto& port) {
119 ✔
296
    for(ossia::graph_edge* e : port.cables())
186 ✔
297
    {
UNCOV
298
      e->clear();
×
299
    }
300
  });
93 ✔
301

302
  for(auto outl : m_outlets)
424 ✔
303
  {
304
    delete outl;
93 ✔
305
  }
306
  for(auto inl : m_inlets)
420 ✔
307
  {
308
    delete inl;
91 ✔
309
  }
310
  m_inlets.clear();
119 ✔
311
  m_outlets.clear();
119 ✔
312
}
119 ✔
313

314
void graph_node::request(const token_request& req) noexcept
176,553 ✔
315
{
316
  /*
317
  if(std::abs(req.date - req.prev_date) > 1000)
318
  {
319
    std::cerr << typeid(this).name() << " " << req.prev_date << " => " <<
320
  req.date << std::endl;
321
  }
322
  */
323

324
  requested_tokens.push_back(std::move(req));
176,553 ✔
325
}
176,553 ✔
326

327
void graph_node::process_time(
488 ✔
328
    const ossia::token_request& req, execution_state& st) noexcept
329
{
330
  auto [s, d] = exec_state_facade{&st}.timings(req);
488 ✔
331
  this->m_processed_frames += d;
488 ✔
332
}
488 ✔
333

334
void graph_node::begin_request(
488 ✔
335
    const ossia::token_request& req, execution_state& st) noexcept
336
{
337
  // A span length is never negative, so the frame counter cannot follow a
338
  // rewind. The playhead can: map the date of the tick's first sample through
339
  // the same model -> sample map the spans are taken from. Set before the
340
  // tick runs, so that run() sees where its own first sample is.
341
  if(req.speed != 0.)
488 ✔
342
    this->m_transport_frames = req.start_date_to_physical(st.modelToSamplesRatio);
488 ✔
343
}
488 ✔
344

345
void graph_node::all_notes_off() noexcept { }
2,185 ✔
346

347
void release_held_notes(const graph_interface& g, execution_state& e)
2 ✔
348
{
349
  for(ossia::graph_node* n : g.get_nodes())
4 ✔
350
    for(ossia::outlet* out : n->root_outputs())
8 ✔
351
      e.release_held_notes(*out);
2 ✔
352
}
2 ✔
353

354
nonowning_graph_node::~nonowning_graph_node()
1,308 ✔
355
{
356
  m_inlets.clear();
1,308 ✔
357
  m_outlets.clear();
1,308 ✔
358
}
1,308 ✔
359

360
void nonowning_graph_node::clear() noexcept
8 ✔
361
{
362
  for(auto inl : m_inlets)
24 ✔
363
  {
364
    for(ossia::graph_edge* e : inl->sources)
8 ✔
365
    {
UNCOV
366
      e->clear();
×
367
    }
368
  }
369
  for(auto outl : m_outlets)
32 ✔
370
  {
371
    for(ossia::graph_edge* e : outl->targets)
16 ✔
372
    {
UNCOV
373
      e->clear();
×
374
    }
375
  }
376
}
8 ✔
377
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc