Commit Graph

18821 Commits

Author SHA1 Message Date
e33d131174
Fix deadlock when creating VCAs
VCAManager::create_vca sets PI::order while holding the
VCAManager:lock mutex. PI order changes emit a "changed" signal
which in turn can result in querying a list of all strips
(reassign_track_numbers) which requires the VCA mutex:

See also 729ff35faf

```
#2  Glib::Threads::Mutex::Lock::Lock(Glib::Threads::Mutex&) (this=0x7fffffffb070, mutex=...) at /usr/include/glibmm-2.4/glibmm/threads.h:687
#3  ARDOUR::VCAManager::vcas[abi:cxx11]() const (this=0x5555599b6d10) at ../libs/ardour/vca_manager.cc:77
#4  ARDOUR::Session::get_stripables(std::__cxx11::list<boost::shared_ptr<ARDOUR::Stripable>, std::allocator<boost::shared_ptr<ARDOUR::Stripable> > >&, ARDOUR::PresentationInfo::Flag) const (this=0x55555bf03910, sl=std::__cxx11::list = {...}, fl=127) at ../libs/ardour/session.cc:3949
#5  ARDOUR::Session::ensure_stripable_sort_order() (this=0x55555bf03910) at ../libs/ardour/session.cc:2634
#6  ARDOUR::Session::notify_presentation_info_change(PBD::PropertyChange const&) (this=0x55555bf03910, what_changed=...) at ../libs/ardour/session.cc:7016
[ .. connect same thread ..]
#13 ARDOUR::PresentationInfo::send_static_change(PBD::PropertyChange const&) (what_changed=...) at ../libs/ardour/presentation_info.cc:113
#14 ARDOUR::PresentationInfo::set_order(unsigned int) (this=0x5555619ceca0, order=5) at ../libs/ardour/presentation_info.cc:288
#15 ARDOUR::Stripable::set_presentation_order(unsigned int) (this=0x5555619ce8a0, order=5) at ../libs/ardour/stripable.cc:55
#16 ARDOUR::VCAManager::create_vca(unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
    (this=0x5555599b6d10, howmany=1, name_template="VCA %n") at ../libs/ardour/vca_manager.cc:105
```
2022-03-03 17:43:37 +01:00
84c51a1411
Fix BaseUI x-thread signal vs thread-start race
Control surfaces c'tor usually subscribe to signals e.g.
PortConnectedOrDisconnected. This happens after the parent BaseUI
is created, but before set_active() -> BaseUI::run() is called.

At this point in time there is no run_loop thread.

There are two options to handle AbstractUI::call_slot():

 A. Queue the event in the event-loop, using the thread-local
    request buffer of the caller. Then hope the BaseUI
    thread is started, and calls ::handle_ui_requests() before
    the memory pool runs out of space.

 B. Handle the event in the calling thread. -- This may not be
    rt-safe and may call functions with locks held by the caller.
    It will however not accumulate events.

This takes approach (B). If _run_loop_thread is NULL, directly
handle the signal.

In the past, prior to 50abcc74b5, approach (A) was taken.
NULL never matched Glib::Threads::Thread::self().

This also reverts a prior attempt (e417495505) to address this issue.
2022-03-02 21:19:12 +01:00
bff55cc881
Fix crash when deleting MIDI trigger
The Model must be destroyed after the iterator, otherwise
the iterator's d'tor will cause memory corruption trying to lock
the model:

```
Invalid read of size 4
   at pthread_rwlock_unlock (pthread_rwlock_unlock.c:39)
   by Glib::Threads::RWLock::ReaderLock::~ReaderLock() (threads.h:828)
   by void boost::checked_delete<Glib::Threads::RWLock::ReaderLock>(Glib::Threads::RWLock::ReaderLock*) (checked_delete.hpp:36)
   by boost::detail::sp_counted_impl_p<Glib::Threads::RWLock::ReaderLock>::dispose() (sp_counted_impl.hpp:89)
   by boost::detail::sp_counted_base::release() (sp_counted_base_gcc_atomic.hpp:120)
   by boost::detail::shared_count::~shared_count() (shared_count.hpp:432)
   by boost::shared_ptr<Glib::Threads::RWLock::ReaderLock>::~shared_ptr() (shared_ptr.hpp:335)
   by Evoral::Sequence<Temporal::Beats>::const_iterator::~const_iterator() (Sequence.h:224)
   by ARDOUR::MIDITrigger::~MIDITrigger() (triggerbox.cc:2037)
   by ARDOUR::MIDITrigger::~MIDITrigger() (triggerbox.cc:2039)
   by ARDOUR::TriggerBoxThread::delete_trigger(ARDOUR::Trigger*) (triggerbox.cc:4386)
   by ARDOUR::TriggerBoxThread::thread_work() (triggerbox.cc:4314)
   by ARDOUR::TriggerBoxThread::_thread_work(void*) (triggerbox.cc:4285)
   by fake_thread_start(void*) (pthread_utils.cc:101)
   by start_thread (pthread_create.c:477)
   by clone (clone.S:95)
 Address 0x28229798 is 24 bytes inside a block of size 56 free'd
   at free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
   by Glib::Threads::RWLock::~RWLock() (in /usr/lib/x86_64-linux-gnu/libglibmm-2.4.so.1.3.0)
   by Evoral::Sequence<Temporal::Beats>::~Sequence() (Sequence.h:68)
   by ARDOUR::AutomatableSequence<Temporal::Beats>::~AutomatableSequence() (automatable_sequence.h:31)
   by ARDOUR::MidiModel::~MidiModel() (midi_model.h:58)
   by ARDOUR::MidiModel::~MidiModel() (midi_model.h:58)
   by void boost::checked_delete<ARDOUR::MidiModel>(ARDOUR::MidiModel*) (checked_delete.hpp:36)
   by boost::detail::sp_counted_impl_p<ARDOUR::MidiModel>::dispose() (sp_counted_impl.hpp:89)
   by boost::detail::sp_counted_base::release() (sp_counted_base_gcc_atomic.hpp:120)
   by boost::detail::shared_count::~shared_count() (shared_count.hpp:432)
   by boost::shared_ptr<ARDOUR::MidiModel>::~shared_ptr() (shared_ptr.hpp:335)
   by ARDOUR::MIDITrigger::~MIDITrigger() (triggerbox.cc:2037)
   by ARDOUR::MIDITrigger::~MIDITrigger() (triggerbox.cc:2039)
   by ARDOUR::TriggerBoxThread::delete_trigger(ARDOUR::Trigger*) (triggerbox.cc:4386)
   by ARDOUR::TriggerBoxThread::thread_work() (triggerbox.cc:4314)
   by ARDOUR::TriggerBoxThread::_thread_work(void*) (triggerbox.cc:4285)
   by fake_thread_start(void*) (pthread_utils.cc:101)
   by start_thread (pthread_create.c:477)
   by clone (clone.S:95)
```
2022-03-02 18:12:50 +01:00
57bf5be609
Fix use of uninitialized variable 2022-03-01 22:16:01 +01:00
75ec5ee87d
Terminate Peak file threads at exit 2022-03-01 18:20:40 +01:00
183f00bbed
NO-OP: cleanup and lang-format 2022-03-01 18:00:20 +01:00
e417495505
Fix possible race (BaseUI creation vs x-thread signal-emission)
When a BaseUI is being created, signals can arrive before the
_run_loop_thread is running, which can trigger an assert in
BaseUI::caller_is_self().
2022-03-01 17:19:20 +01:00
a1374c7a82 triggerbox: we no longer need to store Triggerbox::estimated_tempo in the snapshot file
* estimated tempo is cached in the SegmentDescriptor
* storing it in the Source's SD allows us to skip minibpm if we find a tempo there
2022-03-01 10:11:14 -06:00
2dd078aabe triggerbox: call copy_to_ui_state() after audio|midi state is recalled 2022-03-01 10:11:14 -06:00
2821ea7fc6 triggerbox: implement 'replace midi-file PGMs with the triggerbox PGMs"
* intercept {pgm|bank}-change messages, and replace them with triggerbox values
* check is_set() extensively; we have arrays of pgms but most are unused
2022-03-01 10:11:14 -06:00
b62f5e2cf7 triggerbox: estimate_midi_patches tries to retain patch info across domains
* initialize patches to GM standard (drums on 10) in case file has none
* in the case where file had none, check the Auditioner to see if user set any
* in the case where a file has patches, use those instead

* also stash the UsedChannels so we can show only the used chans in the UI
2022-03-01 10:11:14 -06:00
e932afaf26 triggerbox: maintain UsedChannels and Patch Change data 2022-03-01 10:11:14 -06:00
ed07b26d76 auditioner: do not reset my patches when changing files
* if a file has program-changes, then it will set() my patches
* if a file does *not* have PCs, the user might choose one (which sets() it)
* if the next file does *not* have PCs, we should preserve the user's selection
* if the next file has PCs, it will set() it (losing the user selection)
2022-03-01 10:11:14 -06:00
eced764480 smf_source: implement SMF::UsedChannels as a bitset; move midi screening into load_model()
we screen midi files for some aggregate info:
 used channels, used patches, and note-count

you can't do this from open() because there are cases (after importing)
 when the source exists but it is not yet written to disk
2022-03-01 10:11:14 -06:00
b96b97c439 PatchChange: fix set_channel() 2022-03-01 10:11:14 -06:00
fc3abecca0 PatchChange: yet more checks to keep patch state in sync (is_set())
* fix the case for creating an empty, unset patch
* fix is_set() for bank changes: 2nd byte is the one that gets 'set'
2022-03-01 10:11:14 -06:00
5d6dfeacf6 add DEBUG flag: miditriggers 2022-03-01 10:11:14 -06:00
5c701a3673
NO-OP: clang-format 2022-03-01 16:22:50 +01:00
a5ae5855bb
Terminate Analysis thread at exit
This prevents a crash at exit if the analyzer is still analyzing
when Ardour terminates. A possible downside is that an ongoing
analysis will keep the application running for a bit longer.
2022-03-01 16:22:32 +01:00
50abcc74b5
Replace Glib::Threads with PBD::Thread (2/2) 2022-03-01 01:34:35 +01:00
24bbf403b9
Replace Glib::Threads with PBD::Thread (1/2) 2022-03-01 01:33:49 +01:00
a8559c8741
Remove unused variable 2022-03-01 01:33:21 +01:00
e515e73db6
Implement a replacement for Glib::Threads::Thread
This is mainly because Glib::Threads (g_system_thread_new)
uses pthread on Un*x, but on Windows relies on GThreadWin32
(HANDLE)_beginthreadex

This later causes issues e.g. in BaseUI::run()

```
unhandled exception (type Glib::Error) in signal handler:
domain: g_thread_error
code  : 0
what  : Error setting new thread priority: The parameter is incorrect.
```
2022-03-01 01:33:08 +01:00
8408d5916c triggerbox: if we find a cue marker, we are no longer locate armed 2022-02-22 22:00:11 -07:00
4048118926 triggerbox: stop-all-cues cue event now stops all running triggers
This is done regardless of whether or not the trigger was started by a cue or individually
2022-02-21 21:06:17 -07:00
28db0c1d2b triggerbox: fix logic error in handling of locate-while-playing-triggers 2022-02-21 12:45:13 -07:00
92d82866e0 temporal: add some basic BBT time tests
Some of the subtraction tests may need revising because it is not immediately clear that the
current answers are correct.
2022-02-21 11:55:44 -07:00
47bf18101b triggerbox: don't set transition times when we are not transitioning
At some point during code refactoring, we ended up setting up the 3 transition times, intedned
to define when the *previous* transition occured, as we checked to see if a transition
would occur during this ::run() call. This led to (in particular) MIDI clips ending early,
because the transition_beats value was set to the *next* (upcoming) transition, and we used
this to define the timeline position of MIDI events
2022-02-20 11:00:01 -07:00
b9de15d285 triggerbox: split apart semantics of WaitingToStop
This allows for a different quantization to be used when WaitingToSwitch,
used when we explicitly start a different Trigger. When "just stopping"
we continue to use 1 bar quantization; when switching to a different
Trigger we use the quantization of the next Trigger
2022-02-20 09:20:47 -07:00
b506a243a2 move cue-behavior from rc_configuration to per-session config 2022-02-19 11:48:56 -06:00
3bfcfe178d triggerbox: some work towards keeping GUI state in sync with "Play Cues"
This still needs some mechanism to request a fast-forward when "Play Cues" is enabled
in a (G)UI thread
2022-02-19 08:53:30 -07:00
a01325c693 triggerbox: NOOP: whitespace cleanup 2022-02-18 18:02:56 -07:00
1e7ca734d6 triggerbox: reapply change in 9abc4642 with more explanatory comments 2022-02-18 18:01:52 -07:00
00185aadcf triggerbox: leave a possibly helpful comment 2022-02-18 12:57:14 -07:00
f5ef5f44a3 triggerbox: include change intended to be in cb815bf8d
This properly splits the condition into "before final beat" and
"after final beat"
2022-02-18 12:57:14 -07:00
66b9bc5c40 triggerbox: alter several DEBUG_TRACE statements 2022-02-18 12:57:14 -07:00
fe76432061 triggerbox: help MIDITriggers find their ends consistently 2022-02-18 12:57:14 -07:00
19f6a6a739 triggerbox: during fast-forward, if there's nothing to do, set_currently_playing to null
if left non-null, the next TriggerBox::run() method will start the transport
rolling.
2022-02-18 12:57:14 -07:00
8a36f9fce8 triggerbox: reset _loop_cnt to zero on shutdown
This helps with preventing _loop_cnt incrementing to unintended values.
2022-02-18 12:57:14 -07:00
0762ef4f35 triggerbox: remove Playout enum from enums registation 2022-02-18 12:57:14 -07:00
401e5a572c triggerbox: clean up comments for Trigger state decls 2022-02-18 12:57:14 -07:00
4b7c0448e4 triggerbox: remove Playout as a possible state and use a separate bool
A trigger can be in a playout state when we decide to change its
state to WaitingToStop (e.g. due to a cue marker). This design
leaves the playout condition "in effect" despite the state changing.
2022-02-18 12:57:14 -07:00
fbbe74a530 triggerbox: revert gain() as a queued UISTate value
It's impractical/impossible to set the gain if you have to wait for a retrigger
2022-02-18 11:15:43 -06:00
c09ffd4fcd triggerbox: consolidate ::start_and_roll_to() across Audio & MIDI triggers
This uses a mild trick to pass both the object and ptr-to-member-function from the child class
to the parent class.

Note: before this commit, both instances of ::start_and_roll_to() were identical.
2022-02-15 16:24:01 -07:00
e75a8ab77c triggerbox: clarify handling of end-of-clip conditions
This doesn't enter Playout state, when the final event matches the predicted
final beat, but also returns the correct number of frames covered
2022-02-15 15:28:01 -07:00
9abc4642ed triggerbox: fix midi timing in the case where a note-off arrives exactly at the end of the clip (amends cbbe5) 2022-02-14 21:30:23 -06:00
8741c4cc5d triggerbox: NOOP - rename template parameter for *_run<bool> to be more clear about its purpose 2022-02-14 18:13:06 -07:00
cb815bf8dd triggerbox: drop useless computation 2022-02-14 18:09:03 -07:00
cbbe595162 triggerbox: fix end-handling of MIDI triggers (again)
If we reach the last event in a MIDI file, the test to enter Playout
is whether the last event is *before* not at or later to our computed
final beat.
2022-02-14 18:07:54 -07:00
91e7361e08 triggerbox: ensure _currently_playing reflects fast_forward logic
If we decide after fast forwarding that this TriggerBox has no triggers
active at the transport position, we must mark _currently_playing as null,
because otherwise the TB can still start the transport (in error) during
run()
2022-02-14 12:59:24 -07:00