Skip to content

Commit

Permalink
new feature data in project file
Browse files Browse the repository at this point in the history
  • Loading branch information
elventian committed Apr 12, 2020
1 parent 3f12b6f commit 768896f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 184 deletions.
20 changes: 12 additions & 8 deletions src/ntff_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <list>
#include <set>
#include <limits>
#include <algorithm>

namespace Ntff {

Expand Down Expand Up @@ -173,6 +174,11 @@ class UserAction: public Combobox
setText(values[selected]);
}
Action getAction() const { return (Action)getSelectedId(); }
static Action fromStr(const std::string &action)
{
if (action == "add") { return Add; }
return Remove;
}
};

class FeatureWidget: public ComplexWidget
Expand All @@ -183,7 +189,7 @@ class FeatureWidget: public ComplexWidget
{
addWidget(new Label(dialog, "then", row));

action = new UserAction(dialog, UserAction::Add, row);
action = new UserAction(dialog, UserAction::fromStr(feature->getAction()), row);
addWidget(action);

addWidget(new Label(dialog, "intervals where", row));
Expand All @@ -197,10 +203,13 @@ class FeatureWidget: public ComplexWidget
eqStr.push_back(">");
eqStr.push_back("");
eqStr.push_back("");
equality = new Combobox(dialog, eqStr[2], eqStr, row);
std::string eq = (std::find(eqStr.begin(), eqStr.end(), feature->getEq()) != eqStr.end()) ?
feature->getEq() : eqStr[0];

equality = new Combobox(dialog, eq, eqStr, row);
addWidget(equality);

value = new Combobox(dialog, std::to_string(feature->getRecommendedMin()),
value = new Combobox(dialog, std::to_string(feature->getRecIntensity()),
feature->getIntervalsIntensity(), row);
addWidget(value);

Expand Down Expand Up @@ -229,7 +238,6 @@ class FeatureWidget: public ComplexWidget
}
}

bool isActive() const { return true; /*active->isChecked();*/ }
bool update()
{
bool res = false;
Expand Down Expand Up @@ -412,10 +420,6 @@ bool Dialog::updatedFeatures()
{
FeatureWidget *widget = p.first;
if (widget->update()) { updated = true; }
/*int8_t min, max;
widget->getSelectedIntensity(min, max);
updated |= feature->setSelected(min, max);
updated |= feature->setActive(widget->isActive());*/
}
return updated;
}
Expand Down
79 changes: 5 additions & 74 deletions src/ntff_feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
namespace Ntff
{

Feature::Feature(const std::string &name, const std::string &description, int recMin, int recMax) :
Feature::Feature(const std::string &name, const std::string &description,
const std::string &recAction, const std::string &recEq, int8_t recIntensity):
name(name), description(description),
recMin(recMin), recMax(recMax), active(true)
recIntensity(recIntensity), recAction(recAction), recEq(recEq)
{
min = std::numeric_limits<int8_t>::max();
max = std::numeric_limits<int8_t>::min();
Expand All @@ -16,13 +17,8 @@ Feature::Feature(const std::string &name, const std::string &description, int re
void Feature::appendInterval(const Ntff::Interval &interval)
{
intervals.push_back(interval);
selectedMin = min = std::min(min, interval.intensity);
selectedMax = max = std::max(min, interval.intensity);
}

bool Feature::isActive(const Interval &interval) const
{
return interval.intensity >= selectedMin && interval.intensity <= selectedMax;
min = std::min(min, interval.intensity);
max = std::max(min, interval.intensity);
}

std::vector<std::string> Feature::getIntervalsIntensity() const
Expand All @@ -35,71 +31,6 @@ std::vector<std::string> Feature::getIntervalsIntensity() const
return std::vector<std::string>(res.begin(), res.end());
}

std::ostream &operator<<(std::ostream &out, const Feature &item)
{
out << item.name << ", min = " << (int)item.recMin << ", max = " << (int)item.recMax << std::endl;
return out;
}

mtime_t FeatureList::formSelectedIntervals(std::map<mtime_t, Interval> &res, mtime_t len)
{
res.clear();
if (markedOnly) //collect only marked feature intervals
{
for (Feature *feature: *this)
{
if (!feature->isActive()) { continue; }
for (const Interval& interval: feature->getIntervals())
{
if (feature->isActive(interval))
{
insertInterval(res, interval);
}
}
}
}
else //find unselected intervals and collect all others
{
std::map<mtime_t, Interval> skipIntervals;
for (Feature *feature: *this)
{
for (const Interval& interval: feature->getIntervals())
{
if (!feature->isActive() || !feature->isActive(interval))
{
insertInterval(skipIntervals, interval);
}
}
}

mtime_t lastUnmarked = 0;
for (auto &it: skipIntervals)
{
Interval &skipInterval = it.second;
Interval interval(lastUnmarked, skipInterval.in);
if (interval.length() > 0)
{
res[interval.in] = interval;
}
lastUnmarked = skipInterval.out;
}

if (lastUnmarked < len)
{
Interval interval(lastUnmarked, len);
res[interval.in] = interval;
}
}

mtime_t length = 0;
for (auto &it: res)
{
Interval &interval = it.second;
length += (interval.out - interval.in);
}
return length;
}

FeatureList::~FeatureList()
{
for (Feature *feature: *this)
Expand Down
40 changes: 8 additions & 32 deletions src/ntff_feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,58 +25,34 @@ struct Interval

class Feature
{
friend std::ostream &operator<<(std::ostream &out, const Feature &item);
public:
Feature(const std::string &name, const std::string &description, int recMin, int recMax);
Feature(const std::string &name, const std::string &description,
const std::string &recAction, const std::string &recEq, int8_t recIntensity);
void appendInterval(const Interval &interval);
const std::vector<Interval> &getIntervals() const { return intervals; }
bool isActive(const Interval &interval) const;
const std::string &getName() const { return name; }
const std::string &getDescription() const { return description; }
const std::string &getAction() const { return recAction; }
const std::string &getEq() const { return recEq; }
int8_t getRecIntensity() const { return recIntensity; }
std::vector<std::string> getIntervalsIntensity() const;
int8_t getRecommendedMin() const { return recMin; }
int8_t getRecommendedMax() const { return recMax; }
bool setSelected(int8_t min, int8_t max)
{
bool res = (selectedMin != min || selectedMax != max);
selectedMin = min;
selectedMax = max;
return res;
}
bool setActive(bool activate = true)
{
bool res = (active != activate);
active = activate;
return res;
}
bool isActive() const { return active; }
private:
std::string name;
std::string description;
int8_t recIntensity;
std::string recAction;
std::string recEq;
int8_t min;
int8_t max;
int8_t recMin;
int8_t recMax;
int8_t selectedMin;
int8_t selectedMax;
bool active;
std::vector<Interval> intervals;
};

class FeatureList: public std::vector<Feature *>
{
public:
mtime_t formSelectedIntervals(std::map<mtime_t, Interval> &res, mtime_t len);
~FeatureList();
bool appendUnmarked(bool unmarked) {
bool res = (markedOnly == unmarked);
markedOnly = !unmarked;
return res;
}
static void insertInterval(std::map<mtime_t, Interval> &container, const Interval& interval);
static void removeInterval(std::map<mtime_t, Interval> &container, const Interval& interval);
private:
bool markedOnly;
};

}
Expand Down
53 changes: 3 additions & 50 deletions src/ntff_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ void Player::addFile(const Interval &interval, const std::string &filename)
{
out->reuseStreams();
items[interval.in] = Item((vlc_object_t *)obj, interval, out->getWrapperStream(), filename);
wholeDuration = interval.out;
length = wholeDuration = interval.out;
playIntervals[0] = Interval(0, wholeDuration);
curInterval = playIntervals.begin();
}

bool Player::timeIsInPlayInterval(mtime_t time) const
Expand Down Expand Up @@ -87,44 +89,8 @@ int Player::getCurIntervalFirstFrame() const
return getFrameId(timeInItem);
}

void Player::updatePlayIntervals()
{
if (items.size() == 0) return;

msg_Dbg(obj, "updatePlayIntervals");

vlc_mutex_lock(&intervalsMutex);

Item &lastItem = items.rbegin()->second;
length = featureList->formSelectedIntervals(playIntervals, lastItem.getInterval().out); //TODO: split intervals in between files

//var_SetInteger(obj->p_input, "length", length);

if (savedTime)
{
auto closestIt = playIntervals.lower_bound(savedTime);
if (closestIt == playIntervals.end())
{
closestIt = playIntervals.begin();
}
else if (closestIt != playIntervals.begin())
{
closestIt--; //select prev interval, if it contains our timestamp
if (closestIt->second.out <= savedTime)
{
closestIt++;
}
}
curInterval = closestIt;
}
else { curInterval = playIntervals.begin(); }

vlc_mutex_unlock(&intervalsMutex);
}

void Player::setIntervalsSelected()
{
//reset();
Interval &newInterval = curInterval->second;
mtime_t newTime = newInterval.contains(savedTime) ? savedTime : newInterval.in;

Expand Down Expand Up @@ -414,19 +380,6 @@ int Player::control(int query, va_list args)
}
}

void Player::reset()
{
updatePlayIntervals();
curInterval = playIntervals.begin();
skipToCurInterval();

msg_Dbg(obj, "~~~~Player Items: %li", items.size());
for (auto p: items)
{
msg_Dbg(obj, "~~~~item length: %li - %li", p.second.getInterval().in, p.second.getInterval().out);
}
}

void Player::seek(double pos)
{
const mtime_t streamTime = length * pos;
Expand Down
2 changes: 0 additions & 2 deletions src/ntff_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class Player
void addFile(const Interval &interval, const std::string &filename);
int play();
int control(int query, va_list args);
void reset();
void seek(double pos);
void setPause(bool pause) const;

Expand All @@ -30,7 +29,6 @@ class Player
mtime_t getFrameLen() const;
int getFrameId(mtime_t timeInItem) const;
int getCurIntervalFirstFrame() const;
void updatePlayIntervals();
void setIntervalsSelected();
void showDialog();
void hideDialog();
Expand Down
31 changes: 13 additions & 18 deletions src/ntff_project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ FeatureTrack::FeatureTrack(xml_reader_t *reader): feature(nullptr), playlist(nul
bool empty = xml_ReaderIsEmptyElement(reader);
std::string node(nodeC);

std::string name, description;
int recMin = 0, recMax = 0;
std::string name, description, recAction, recEq;
int recIntensity = 0;
bool isFeature = false;

do
Expand All @@ -272,13 +272,9 @@ FeatureTrack::FeatureTrack(xml_reader_t *reader): feature(nullptr), playlist(nul
const char *data;
xml_ReaderNextNode(reader, &data);

if (property == "kdenlive:feature_rec_min")
if (property == "kdenlive:feature_rec_intensity")
{
recMin = atoi(data);
}
else if (property == "kdenlive:feature_rec_max")
{
recMax = atoi(data);
recIntensity = atoi(data);
}
else if (property == "kdenlive:track_name")
{
Expand All @@ -292,6 +288,14 @@ FeatureTrack::FeatureTrack(xml_reader_t *reader): feature(nullptr), playlist(nul
{
isFeature = true;
}
else if (property == "kdenlive:feature_rec_action")
{
recAction = std::string(data);
}
else if (property == "kdenlive:feature_rec_eq")
{
recEq = std::string(data);
}

#ifdef DEBUG_PROJECT_PARSING
msg_Dbg(Project::getVlcObj(), "~~~~~~Project track: property = %s, data = %s",
Expand All @@ -318,7 +322,7 @@ FeatureTrack::FeatureTrack(xml_reader_t *reader): feature(nullptr), playlist(nul

if (isFeature)
{
feature = new Feature(name, description, recMin, recMax);
feature = new Feature(name, description, recAction, recEq, recIntensity);
}

#ifdef DEBUG_PROJECT_PARSING
Expand Down Expand Up @@ -510,14 +514,6 @@ FeatureList *Project::generateFeatureList() const
flist->push_back(feature);
}

std::stringstream ss;
ss << "~~~~Features num: " << flist->size() << std::endl;
for (Ntff::Feature *f: *flist)
{
ss << "~~~~~~" << *f;
}
msg_Dbg(obj, "%s", ss.str().c_str());

return flist;
}

Expand All @@ -528,7 +524,6 @@ Player *Project::createPlayer(demux_t *demux) const
{
player->addFile(entry.getInterval(), entry.getResource());
}
player->reset();
return player;
}

Expand Down

0 comments on commit 768896f

Please sign in to comment.