Skip to content

Commit a6adac9

Browse files
committed
dataflow: give exec_state_facade ability to process destination_t
1 parent 7e9b16e commit a6adac9

File tree

5 files changed

+120
-3
lines changed

5 files changed

+120
-3
lines changed

3rdparty/libremidi

src/ossia/dataflow/dataflow.hpp

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace ossia
99
{
10+
struct exec_state_facade;
1011
struct do_nothing_for_nodes
1112
{
1213
void operator()(ossia::net::node_base* node, bool) const noexcept { }
@@ -53,4 +54,12 @@ bool apply_to_destination(
5354
}
5455
}
5556
}
57+
58+
std::vector<ossia::net::node_base*> list_destinations(
59+
const destination_t& address,
60+
const ossia::small_vector<ossia::net::device_base*, 4>& devices);
61+
62+
ossia::net::node_base* get_first_destination(
63+
const destination_t& address,
64+
const ossia::small_vector<ossia::net::device_base*, 4>& devices);
5665
}

src/ossia/dataflow/exec_state_facade.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#pragma once
22
#include <ossia/detail/config.hpp>
33

4+
#include <ossia/dataflow/dataflow_fwd.hpp>
5+
46
#include <cinttypes>
57
#include <string_view>
68

@@ -48,6 +50,9 @@ struct OSSIA_EXPORT exec_state_facade
4850
void insert(ossia::net::parameter_base& dest, const value_port& v);
4951
void insert(ossia::audio_parameter& dest, const audio_port& v);
5052
void insert(ossia::net::midi::midi_parameter& dest, const midi_port& v);
53+
54+
std::vector<ossia::net::node_base*> list_destinations(const destination_t& address);
55+
ossia::net::node_base* get_first_destination(const destination_t& address);
5156
};
5257

5358
}

src/ossia/dataflow/execution_state.cpp

+95
Original file line numberDiff line numberDiff line change
@@ -563,4 +563,99 @@ void exec_state_facade::insert(net::midi::midi_parameter& dest, const midi_port&
563563
{
564564
impl->insert(dest, v);
565565
}
566+
567+
std::vector<ossia::net::node_base*>
568+
exec_state_facade::list_destinations(const destination_t& address)
569+
{
570+
return ossia::list_destinations(address, impl->exec_devices());
571+
}
572+
573+
ossia::net::node_base*
574+
exec_state_facade::get_first_destination(const destination_t& address)
575+
{
576+
return ossia::get_first_destination(address, impl->exec_devices());
577+
}
578+
579+
std::vector<ossia::net::node_base*> list_destinations(
580+
const destination_t& address,
581+
const ossia::small_vector<ossia::net::device_base*, 4>& devices)
582+
{
583+
std::vector<ossia::net::node_base*> ret;
584+
switch(address.which().index())
585+
{
586+
// ossia::net::parameter_base*
587+
case destination_t::index_of<ossia::net::parameter_base*>().index(): {
588+
auto addr = *address.target<ossia::net::parameter_base*>();
589+
if(addr)
590+
{
591+
ret.push_back(&addr->get_node());
592+
break;
593+
}
594+
break;
595+
}
596+
597+
// ossia::traversal::path
598+
case destination_t::index_of<ossia::traversal::path>().index(): {
599+
std::vector<ossia::net::node_base*> roots{};
600+
601+
for(auto n : devices)
602+
roots.push_back(&n->get_root_node());
603+
604+
auto& p = *address.target<ossia::traversal::path>();
605+
ossia::traversal::apply(p, roots);
606+
607+
for(auto n : roots)
608+
ret.push_back(n);
609+
break;
610+
}
611+
612+
// ossia::net::node_base*
613+
case destination_t::index_of<ossia::net::node_base*>().index(): {
614+
ret.push_back(*address.target<ossia::net::node_base*>());
615+
break;
616+
}
617+
default:
618+
break;
619+
}
620+
return ret;
621+
}
622+
623+
ossia::net::node_base* get_first_destination(
624+
const destination_t& address,
625+
const ossia::small_vector<ossia::net::device_base*, 4>& devices)
626+
{
627+
switch(address.which().index())
628+
{
629+
// ossia::net::parameter_base*
630+
case destination_t::index_of<ossia::net::parameter_base*>().index(): {
631+
auto addr = *address.target<ossia::net::parameter_base*>();
632+
if(addr)
633+
return &addr->get_node();
634+
break;
635+
}
636+
637+
// ossia::traversal::path
638+
case destination_t::index_of<ossia::traversal::path>().index(): {
639+
std::vector<ossia::net::node_base*> roots{};
640+
641+
for(auto n : devices)
642+
roots.push_back(&n->get_root_node());
643+
644+
auto& p = *address.target<ossia::traversal::path>();
645+
ossia::traversal::apply(p, roots);
646+
647+
for(auto n : roots)
648+
return n;
649+
break;
650+
}
651+
652+
// ossia::net::node_base*
653+
case destination_t::index_of<ossia::net::node_base*>().index(): {
654+
return *address.target<ossia::net::node_base*>();
655+
}
656+
default:
657+
break;
658+
}
659+
return nullptr;
660+
}
566661
}

src/ossia/detail/lockfree_queue.hpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
// TSAN seems to have some trouble with ReaderWriterQueue...
44
#if !defined(OSSIA_FREESTANDING)
55

6+
#include <blockingconcurrentqueue.h>
7+
#include <concurrentqueue.h>
8+
9+
// SPSC
610
#if defined(__has_feature)
711
#if __has_feature(thread_sanitizer)
8-
#include <concurrentqueue.h>
912
namespace ossia
1013
{
1114
template <typename T, size_t MAX_BLOCK_SIZE = 512>
@@ -28,12 +31,15 @@ using spsc_queue = moodycamel::ReaderWriterQueue<T, MAX_BLOCK_SIZE>;
2831
}
2932
#endif
3033

31-
#include <concurrentqueue.h>
34+
// MPMC
3235
namespace ossia
3336
{
3437
template <typename T>
3538
using mpmc_queue = moodycamel::ConcurrentQueue<T>;
39+
template <typename T>
40+
using blocking_mpmc_queue = moodycamel::BlockingConcurrentQueue<T>;
3641
}
42+
3743
#else
3844
// Will only be used on one thread anyways
3945
#include <vector>
@@ -62,5 +68,7 @@ template <typename T>
6268
using spsc_queue = ossia::minimal_queue<T>;
6369
template <typename T>
6470
using mpmc_queue = ossia::minimal_queue<T>;
71+
template <typename T>
72+
using blocking_mpmc_queue = ossia::minimal_queue<T>;
6573
}
6674
#endif

0 commit comments

Comments
 (0)