Skip to content

Commit

Permalink
Use mc::container for v::Model::Channel
Browse files Browse the repository at this point in the history
  • Loading branch information
gvnnz committed Apr 28, 2024
1 parent f982220 commit 2290a89
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/glue/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Column makeColumn_(const v::Model::Column& modelColumn)
for (const v::Model::Channel& channel : modelColumn)
{
column.channels.push_back(makeData_(channel));
for (const v::Model::Channel& child : channel.channels.getAll()) // for groups
for (const v::Model::Channel& child : channel) // for groups
column.channels.push_back(makeData_(child));
}

Expand Down
16 changes: 13 additions & 3 deletions src/gui/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@

namespace giada::v
{
Model::Channel::Channel(ID id, std::size_t columnIndex)
: columnIndex(columnIndex)
{
this->id = id;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

Model::Column::Column(int width)
: width(width)
{
Expand Down Expand Up @@ -232,9 +242,9 @@ void Model::addChannelToGroup(ID channelId, ID groupId, int position)
Column& column = getColumnByChannelId(groupId);
Channel& group = column.getById(groupId);
if (position == -1)
group.channels.add({channelId, column.index});
group.add({channelId, column.index});
else
group.channels.insert({channelId, column.index}, position);
group.insert({channelId, column.index}, position);
}

/* -------------------------------------------------------------------------- */
Expand All @@ -245,7 +255,7 @@ void Model::removeChannelFromColumn(ID channelId)
{
column.removeById(channelId);
for (Channel& channel : column)
channel.channels.removeById(channelId);
channel.removeById(channelId);
}
}

Expand Down
13 changes: 4 additions & 9 deletions src/gui/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "core/plugins/pluginManager.h"
#include "deps/geompp/src/rect.hpp"
#include "deps/mcl-container/src/container.hpp"
#include "utils/container.h"
#include <FL/Enumerations.H>
#include <string>
#include <vector>
Expand All @@ -41,18 +40,14 @@ namespace giada::v
{
struct Model
{
template <typename T>
using Channels = u::Container<T, /*Identifiable=*/true, /*Sortable=*/true>;

template <typename T>
using Columns = mcl::Container<T>;

struct Channel
struct Channel : public mcl::Container<Channel, /*Identifiable=*/true, /*Sortable=*/true>
{
ID id;
std::size_t columnIndex;
int index = -1;
Channels<Channel> channels = {};
Channel(ID id, std::size_t columnIndex);

std::size_t columnIndex;
};

struct Column : public mcl::Container<Channel, /*Identifiable=*/false, /*Sortable=*/true>
Expand Down

0 comments on commit 2290a89

Please sign in to comment.