Skip to content

Commit f61dca8

Browse files
committed
Support setting tempo and time signature
1 parent 9178618 commit f61dca8

20 files changed

+457
-38
lines changed

src/libs/application/dspxmodel/src/AnchorNodeSequence.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <qqmlintegration.h>
55

66
#include <dspxmodel/EntityObject.h>
7+
#include <dspxmodel/rangehelpers.h>
78

89
namespace QDspx {
910
struct AnchorNode;
@@ -45,6 +46,10 @@ namespace dspx {
4546

4647
ParamCurveAnchor *paramCurveAnchor() const;
4748

49+
auto asRange() const {
50+
return impl::SequenceRange(this);
51+
}
52+
4853
Q_SIGNALS:
4954
void itemAboutToInsert(AnchorNode *item);
5055
void itemInserted(AnchorNode *item);

src/libs/application/dspxmodel/src/ClipSequence.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <qqmlintegration.h>
55

66
#include <dspxmodel/EntityObject.h>
7+
#include <dspxmodel/rangehelpers.h>
78

89
namespace QDspx {
910
struct Clip;
@@ -46,6 +47,10 @@ namespace dspx {
4647

4748
Track *track() const;
4849

50+
auto asRange() const {
51+
return impl::SequenceRange(this);
52+
}
53+
4954
Q_SIGNALS:
5055
void itemAboutToInsert(Clip *item);
5156
void itemInserted(Clip *item);

src/libs/application/dspxmodel/src/LabelSequence.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <qqmlintegration.h>
55

66
#include <dspxmodel/EntityObject.h>
7+
#include <dspxmodel/rangehelpers.h>
78

89
namespace QDspx {
910
struct Label;
@@ -41,6 +42,10 @@ namespace dspx {
4142
QList<QDspx::Label> toQDspx() const;
4243
void fromQDspx(const QList<QDspx::Label> &labels);
4344

45+
auto asRange() const {
46+
return impl::SequenceRange(this);
47+
}
48+
4449
Q_SIGNALS:
4550
void itemAboutToInsert(Label *item);
4651
void itemInserted(Label *item);

src/libs/application/dspxmodel/src/NoteSequence.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <qqmlintegration.h>
55

66
#include <dspxmodel/EntityObject.h>
7+
#include <dspxmodel/rangehelpers.h>
78

89
namespace QDspx {
910
struct Note;
@@ -46,6 +47,10 @@ namespace dspx {
4647

4748
SingingClip *singingClip() const;
4849

50+
auto asRange() const {
51+
return impl::SequenceRange(this);
52+
}
53+
4954
Q_SIGNALS:
5055
void itemAboutToInsert(Note *item);
5156
void itemInserted(Note *item);

src/libs/application/dspxmodel/src/ParamCurveSequence.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <qqmlintegration.h>
55

66
#include <dspxmodel/EntityObject.h>
7+
#include <dspxmodel/rangehelpers.h>
78

89
namespace QDspx {
910
struct ParamCurve;
@@ -46,6 +47,10 @@ namespace dspx {
4647

4748
Param *param() const;
4849

50+
auto asRange() const {
51+
return impl::SequenceRange(this);
52+
}
53+
4954
Q_SIGNALS:
5055
void itemAboutToInsert(ParamCurve *item);
5156
void itemInserted(ParamCurve *item);

src/libs/application/dspxmodel/src/PointSequenceContainer_p.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ namespace dspx {
7676
return {};
7777
}
7878
QList<T *> ret;
79-
auto it = m_items.lower_bound(position + length - 1);
80-
while (it != m_items.end() && it != m_items.begin() && it->first >= position + length - 1) {
81-
--it;
82-
}
79+
auto it = m_items.lower_bound(position + length);
8380
std::transform(m_items.lower_bound(position), it, std::back_inserter(ret), [](auto it) {
8481
return it.second;
8582
});

src/libs/application/dspxmodel/src/TempoSequence.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <qqmlintegration.h>
55

66
#include <dspxmodel/EntityObject.h>
7+
#include <dspxmodel/rangehelpers.h>
78

89
namespace QDspx {
910
struct Tempo;
@@ -41,6 +42,10 @@ namespace dspx {
4142
QList<QDspx::Tempo> toQDspx() const;
4243
void fromQDspx(const QList<QDspx::Tempo> &tempos);
4344

45+
auto asRange() const {
46+
return impl::SequenceRange(this);
47+
}
48+
4449
Q_SIGNALS:
4550
void itemAboutToInsert(Tempo *item);
4651
void itemInserted(Tempo *item);

src/libs/application/dspxmodel/src/TimeSignatureSequence.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <qqmlintegration.h>
55

66
#include <dspxmodel/EntityObject.h>
7+
#include <dspxmodel/rangehelpers.h>
78

89
namespace QDspx {
910
struct TimeSignature;
@@ -41,6 +42,10 @@ namespace dspx {
4142
QList<QDspx::TimeSignature> toQDspx() const;
4243
void fromQDspx(const QList<QDspx::TimeSignature> &timeSignatures);
4344

45+
auto asRange() const {
46+
return impl::SequenceRange(this);
47+
}
48+
4449
Q_SIGNALS:
4550
void itemAboutToInsert(TimeSignature *item);
4651
void itemInserted(TimeSignature *item);
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#ifndef DIFFSCOPE_DSPX_MODEL_RANGEHELPERS_H
2+
#define DIFFSCOPE_DSPX_MODEL_RANGEHELPERS_H
3+
4+
#include <iterator>
5+
6+
namespace dspx::impl {
7+
8+
template<class SequenceType>
9+
class SequenceRange {
10+
public:
11+
SequenceRange(const SequenceType *sequence) : m_sequence(sequence) {
12+
}
13+
14+
using ItemType = std::remove_pointer_t<decltype(std::declval<SequenceType>().firstItem())>;
15+
16+
class iterator {
17+
public:
18+
using iterator_category = std::bidirectional_iterator_tag;
19+
using value_type = ItemType *;
20+
using difference_type = std::ptrdiff_t;
21+
using pointer = ItemType **;
22+
using reference = ItemType *&;
23+
24+
iterator(const SequenceType *sequence, ItemType *item) : m_sequence(sequence), m_item(item) {
25+
}
26+
27+
value_type operator*() const {
28+
return m_item;
29+
}
30+
31+
iterator &operator++() {
32+
if (m_item) {
33+
m_item = m_sequence->nextItem(m_item);
34+
}
35+
return *this;
36+
}
37+
38+
iterator operator++(int) {
39+
iterator temp = *this;
40+
++(*this);
41+
return temp;
42+
}
43+
44+
iterator &operator--() {
45+
if (m_item) {
46+
m_item = m_sequence->previousItem(m_item);
47+
} else {
48+
m_item = m_sequence->lastItem();
49+
}
50+
return *this;
51+
}
52+
53+
iterator operator--(int) {
54+
iterator temp = *this;
55+
--(*this);
56+
return temp;
57+
}
58+
59+
bool operator==(const iterator &other) const {
60+
return m_item == other.m_item;
61+
}
62+
63+
bool operator!=(const iterator &other) const {
64+
return m_item != other.m_item;
65+
}
66+
67+
private:
68+
const SequenceType *m_sequence;
69+
ItemType *m_item;
70+
};
71+
72+
using const_iterator = iterator;
73+
using reverse_iterator = std::reverse_iterator<iterator>;
74+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
75+
76+
iterator begin() const {
77+
return iterator(m_sequence, m_sequence->firstItem());
78+
}
79+
80+
iterator end() const {
81+
return iterator(m_sequence, nullptr);
82+
}
83+
84+
const_iterator cbegin() const {
85+
return begin();
86+
}
87+
88+
const_iterator cend() const {
89+
return end();
90+
}
91+
92+
reverse_iterator rbegin() const {
93+
return reverse_iterator(end());
94+
}
95+
96+
reverse_iterator rend() const {
97+
return reverse_iterator(begin());
98+
}
99+
100+
const_reverse_iterator crbegin() const {
101+
return rbegin();
102+
}
103+
104+
const_reverse_iterator crend() const {
105+
return rend();
106+
}
107+
108+
private:
109+
const SequenceType *m_sequence;
110+
};
111+
112+
}
113+
114+
#endif //DIFFSCOPE_DSPX_MODEL_RANGEHELPERS_H

src/libs/application/transactional/TransactionController.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,38 @@ namespace Core {
4949
Q_INVOKABLE bool abortTransaction(TransactionId transactionId);
5050
Q_INVOKABLE bool commitTransaction(TransactionId transactionId, const QString &name);
5151

52+
template <typename Callback>
53+
requires requires (Callback callback) {
54+
{ callback() } -> std::convertible_to<bool>;
55+
}
56+
bool beginScopedTransaction(const QString &name, Callback callback) {
57+
auto transactionId = beginTransaction();
58+
if (transactionId == TransactionId::Invalid) {
59+
return false;
60+
}
61+
bool ok;
62+
if (!callback()) {
63+
ok = abortTransaction(transactionId);
64+
} else {
65+
ok = commitTransaction(transactionId, name);
66+
}
67+
Q_ASSERT(ok);
68+
return true;
69+
}
70+
71+
template <typename Callback, typename CallbackIfFails>
72+
requires requires (Callback callback, CallbackIfFails callbackIfFails) {
73+
{ callback() } -> std::convertible_to<bool>;
74+
{ callbackIfFails() };
75+
}
76+
bool beginScopedTransaction(const QString &name, Callback callback, CallbackIfFails callbackIfFails) {
77+
if (!beginScopedTransaction(name, callback)) {
78+
callbackIfFails();
79+
return false;
80+
}
81+
return true;
82+
}
83+
5284
Q_INVOKABLE TransactionId beginNonExclusiveTransaction(int lifeTime, const QString &name);
5385
Q_INVOKABLE void resetNonExclusiveTransactionLifeTime(TransactionId transactionId, int lifeTime, const QString &name = {});
5486

0 commit comments

Comments
 (0)