better state logic, more features, rewritten timing of signals and more crashes
This commit is contained in:
+39
-12
@@ -21,6 +21,29 @@ class SignalManager{
|
||||
std::vector<Signal> signals;
|
||||
|
||||
bool loop = true;
|
||||
bool play = false;
|
||||
|
||||
void pause(){
|
||||
play = false;
|
||||
}
|
||||
|
||||
void stop(){
|
||||
play = false;
|
||||
reset();
|
||||
}
|
||||
|
||||
void start(){
|
||||
play = true;
|
||||
}
|
||||
|
||||
void reset(){
|
||||
for(auto &s : signals){
|
||||
s.position = s.start->position + Vec2D<float>{0.1, 0.1};
|
||||
s.next = s.start;
|
||||
s.last = s.start;
|
||||
}
|
||||
cm->reset();
|
||||
}
|
||||
|
||||
void startSignalThread(){
|
||||
std::thread t1(&SignalManager::updateSignals, this);
|
||||
@@ -36,6 +59,7 @@ class SignalManager{
|
||||
signals.emplace(signals.end(), Signal(node->position.x+1, node->position.y+1, 5.0f, app->speed, c)); // position + 1 or else it does not render. why? no idea!
|
||||
signals.back().next = node;
|
||||
signals.back().last = node;
|
||||
signals.back().start = node;
|
||||
}
|
||||
|
||||
void removeSignal(int n){
|
||||
@@ -45,19 +69,22 @@ class SignalManager{
|
||||
void updateSignals(){
|
||||
auto last = std::chrono::steady_clock::now();
|
||||
while(loop){
|
||||
std::chrono::duration<double, std::milli> diff = std::chrono::steady_clock::now() - last;
|
||||
if(diff.count() > 10){
|
||||
for(auto& s : signals){
|
||||
s.direction = (s.next->position - s.position).norm();
|
||||
if(s.position.dist(&s.next->position) < s.speed * 1.5) {
|
||||
Node* n = cm->next(s.next, s.last);
|
||||
|
||||
if(n != s.next && n != nullptr) {
|
||||
for(auto &m : s.next->midi_outs){
|
||||
if(m.second.enabled) midi->note(m.second.i, s.next->midi_channel, s.next->midi_note, s.next->midi_velocity, s.next->midi_gate);
|
||||
std::chrono::duration<double, std::micro> diff = std::chrono::steady_clock::now() - last;
|
||||
if(diff.count() > 500){
|
||||
if(play){
|
||||
for(auto& s : signals){
|
||||
s.direction = (s.next->position - s.position).norm();
|
||||
s.update(diff.count());
|
||||
if(s.position.dist(&s.next->position) < 1.0f) {
|
||||
Node* n = cm->next(s.next, s.last);
|
||||
|
||||
if(n != s.next && n != nullptr) {
|
||||
for(auto &m : s.next->midi_outs){
|
||||
if(m.second.enabled) midi->note(m.second.i, s.next->midi_channel, s.next->midi_note, s.next->midi_velocity, s.next->midi_gate);
|
||||
}
|
||||
s.last = s.next;
|
||||
s.next = n;
|
||||
}
|
||||
s.last = s.next;
|
||||
s.next = n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user