Subversion Repositories DIN Is Noise

Rev

Rev 2097 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1970 jag 1
/*
2
* autopause.cc
2302 jag 3
* DIN Is Noise is copyright (c) 2006-2025 Jagannathan Sampath
1970 jag 4
* DIN Is Noise is released under GNU Public License 2.0
5
* For more information, please visit https://dinisnoise.org/
6
*/
7
 
8
#include "chrono.h"
9
#include "autopause.h"
10
#include "defvelaccel.h"
11
#include "autorotator.h"
1971 jag 12
#include "console.h"
1970 jag 13
 
14
autopauset::autopauset (defvelaccel& d) {
1976 jag 15
  a = 0;
1970 jag 16
  yes = d.autos.pause.yes;
2027 jag 17
  tar = d.autos.pause.tar;
1970 jag 18
  every = d.autos.pause.every ();
19
  f0r = d.autos.pause.f0r ();
1976 jag 20
  rndt[0] = d.autos.pause.every.rndrd;
21
  rndt[1] = d.autos.pause.f0r.rndrd;
1974 jag 22
  settrigt (0, every);
23
  settrigt (1, f0r);
1970 jag 24
  t[0] = &every;
25
  t[1] = &f0r;
1976 jag 26
  vt[0] = &d.autos.pause.every;
27
  vt[1] = &d.autos.pause.f0r;
1970 jag 28
}
29
 
1974 jag 30
void autopauset::settrigt (int i, double& d) {
31
  alarmt& ai = alm[i];
32
  ai.triggert = d;
33
}
34
 
1970 jag 35
void autopauset::operator() (autorotator& ar) {
36
  alarmt &aa = alm[a];
37
  if (aa(ui_clk())) {
38
    aa.stop ();
39
    a = !a;
40
    double& ta = *t[a];
1978 jag 41
    if (rndt[a]) ta = (*vt[a])(1);
2027 jag 42
    int* tars [] = {&ar.yes, &ar.autoflip.yes};
43
    int& taryes = *tars[tar];
44
    taryes = !a;
1970 jag 45
    alarmt& nxt = alm[a];
46
    nxt.triggert = ta;
47
    nxt.start ();
48
  }
49
}
50
 
51
void autopauset::go () {
52
  a = 0;
53
  alm[a].start ();
54
}
1974 jag 55
 
56
void autopauset::setyes (int y, autorotator& ar) {
57
  yes = y;
58
  if (!yes && a) ar.setyes (1);
59
}
1977 jag 60
 
61
std::istream& operator>> (std::istream& file, autopauset& ap) {
62
  file >> ap.yes >> ap.rndt[0] >> ap.rndt[1];
1978 jag 63
  return file;
1977 jag 64
}
65
 
66
std::ostream& operator<< (std::ostream& file, autopauset& ap) {
67
  file << ap.yes << spc << ap.rndt[0] << spc << ap.rndt[1] << spc;
1978 jag 68
  return file;
1977 jag 69
}