use a note tracker to resolve notes cut off during render by the end of the region
[ardour.git] / libs / ardour / unknown_processor.cc
1 /*
2  * Copyright (C) 2010-2011 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2013-2017 Robin Gareus <robin@gareus.org>
4  * Copyright (C) 2016-2017 Paul Davis <paul@linuxaudiosystems.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 #include "ardour/audio_buffer.h"
22 #include "ardour/unknown_processor.h"
23
24 #include "pbd/i18n.h"
25
26 using namespace std;
27 using namespace ARDOUR;
28
29 UnknownProcessor::UnknownProcessor (Session& s, XMLNode const & state)
30         : Processor (s, "")
31         , _state (state)
32         , have_ioconfig (false)
33         , saved_input (0)
34         , saved_output (0)
35 {
36         XMLProperty const * prop = state.property (X_("name"));
37         if (prop) {
38                 set_name (prop->value ());
39                 _display_to_user = true;
40         }
41
42         int have_io = 0;
43         XMLNodeList kids = state.children ();
44         for (XMLNodeIterator i = kids.begin(); i != kids.end(); ++i) {
45                 if ((*i)->name() == X_("ConfiguredInput")) {
46                         have_io |= 1;
47                         saved_input = new ChanCount(**i);
48                 }
49                 if ((*i)->name() == X_("ConfiguredOutput")) {
50                         have_io |= 2;
51                         saved_output = new ChanCount(**i);
52                 }
53         }
54         have_ioconfig = (have_io == 3);
55 }
56
57 UnknownProcessor::~UnknownProcessor () {
58         delete saved_input;;
59         delete saved_output;
60 }
61
62 XMLNode &
63 UnknownProcessor::state ()
64 {
65         return *(new XMLNode (_state));
66 }
67
68 bool
69 UnknownProcessor::can_support_io_configuration (const ChanCount &in, ChanCount & out) {
70         if (have_ioconfig && in == *saved_input) {
71                 out = *saved_output;
72                 return true;
73         } else if (!have_ioconfig) {
74                 /* pass for old sessions.
75                  *
76                  * session load assumes processor config succeeds.
77                  * if initial configuration fails, processors downstream
78                  * remain unconfigured and at least the panner will assert/segfault.
79                  *
80                  * This may still result in impossible setup, however
81                  * Route::configure_processors_unlocked() ignores configure_io() return value
82                  * in the inner loop and configures all available processors.
83                  *
84                  * It can still lead to segfaults IFF the track has no inputs and this is a
85                  * generator (processor_max_streams will be zero).
86                  */
87                 PBD::warning << _("Using plugin-stub with unknown i/o configuration for: ") << name() << endmsg;
88 #if 0
89                 /* No output channels are fine (or should be, there may be edge-cases with e.g sends).
90                  *
91                  * Discussion needed.
92                  *
93                  * This is the safer option (no audio output, no possible damage)
94                  * and the way to go in the long run.
95                  * An even better solution is to disable the route if there are missing plugins
96                  * and/or impossible configurations.
97                  *
98                  * Currently no output channels results in awkward GUI route display and also
99                  * breaks semantics in mixbus (which assumes that the route has channels required
100                  * for the always present mixer-strip plugin).
101                  */
102                 out = ChanCount ();
103 #else
104                 out = in;
105 #endif
106                 return true;
107         } else {
108                 PBD::error << _("Using plugin-stub with mismatching i/o configuration for: ") << name() << endmsg;
109                 out = in;
110         }
111         return true;
112 }
113
114 void
115 UnknownProcessor::run (BufferSet& bufs, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, double /*speed*/, pframes_t nframes, bool)
116 {
117         if (!have_ioconfig) {
118                 return;
119         }
120         // silence excess output buffers
121         for (uint32_t i = saved_input->n_audio(); i < saved_output->n_audio(); ++i) {
122                 bufs.get_audio (i).silence (nframes);
123         }
124 }