segment_descriptor: stash UsedChannels here

* similar to segment_tempo, it is conceivable that a midi file would
 use different midi channels in different time ranges of the source
This commit is contained in:
Ben Loftis 2022-02-24 14:32:36 -06:00
parent 75e3646ed8
commit bda8048873
2 changed files with 32 additions and 0 deletions

View File

@ -19,9 +19,13 @@
#ifndef __libardour_segment_descriptor_h__
#define __libardour_segment_descriptor_h__
#include <bitset>
#include "temporal/timeline.h"
#include "temporal/tempo.h"
#include "evoral/SMF.h"
class XMLNode;
namespace ARDOUR {
@ -58,6 +62,9 @@ public:
Temporal::Tempo tempo() const { return _tempo; }
void set_tempo (Temporal::Tempo const&);
Evoral::SMF::UsedChannels used_channels() const { return _used_channels; }
void set_used_channels (Evoral::SMF::UsedChannels);
Temporal::Meter meter() const { return _meter; }
void set_meter (Temporal::Meter const&);
@ -69,6 +76,8 @@ public:
private:
Temporal::TimeDomain _time_domain;
Evoral::SMF::UsedChannels _used_channels;
/* cannot use a union for these because Temporal::Beats has a
"non-trivial" constructor.
*/

View File

@ -16,6 +16,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <sstream>
#include "pbd/enumwriter.h"
#include "pbd/failed_constructor.h"
#include "pbd/i18n.h"
@ -128,6 +130,12 @@ SegmentDescriptor::set_meter (Meter const & m)
_meter = m;
}
void
SegmentDescriptor::set_used_channels (Evoral::SMF::UsedChannels used)
{
_used_channels = used;
}
XMLNode&
SegmentDescriptor::get_state (void) const
{
@ -146,6 +154,9 @@ SegmentDescriptor::get_state (void) const
root->add_child_nocopy (_tempo.get_state());
root->add_child_nocopy (_meter.get_state());
std::string uchan = string_compose ("%1", _used_channels.to_ulong());
root->set_property (X_("used-channels"), uchan);
return *root;
}
@ -160,6 +171,18 @@ SegmentDescriptor::set_state (XMLNode const & node, int version)
return -1;
}
std::string uchan;
if (node.get_property (X_("used-channels"), uchan)) {
} else {
unsigned long ul;
std::stringstream ss (uchan);
ss >> ul;
if (!ss) {
return -1;
}
_used_channels = Evoral::SMF::UsedChannels(ul);
}
if (_time_domain == Temporal::AudioTime) {
if (node.get_property (X_("position"), _position_samples)) {
return -1;