Skip to content
This repository
Newer
Older
100644 94 lines (75 sloc) 2.047 kb
995de50e »
2010-02-04 adding Sleep.ck and append/prepend wait methods to Loops
1 /*
2
3 LiCK Library for ChucK.
f29d9098 »
2014-01-02 updating copyright year
4 Copyright (c) 2007-2014 held jointly by the individual authors.
995de50e »
2010-02-04 adding Sleep.ck and append/prepend wait methods to Loops
5
6 This file is part of LiCK.
7
8 LiCK is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 LiCK is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with LiCK. If not, see <http://www.gnu.org/licenses/>.
20
21 */
22
23 class SleepProcedure extends Procedure
24 {
25 Sleep @ sleep;
26
27 fun void run()
28 {
29 sleep.sleep();
30 }
31 }
32
33 class SleepIntProcedure extends IntProcedure
34 {
35 Sleep @ sleep;
36
37 fun void run(int n)
38 {
39 sleep.value => dur oldValue;
40 sleep.value * n => sleep.value;
41 sleep.sleep();
42 oldValue => sleep.value;
43 }
44 }
45
46 class SleepFloatProcedure extends FloatProcedure
47 {
48 Sleep @ sleep;
49
50 fun void run(float f)
51 {
52 sleep.value => dur oldValue;
53 sleep.value * f => sleep.value;
54 sleep.sleep();
55 oldValue => sleep.value;
56 }
57 }
58
59 public class Sleep
60 // implements Procedure, IntProcedure, FloatProcedure
61 {
62 0::ms => dur value;
63
64 // hack to simulate multiple inheritance
65 SleepProcedure _procedure;
66 SleepIntProcedure _intProcedure;
67 SleepFloatProcedure _floatProcedure;
68
69 {
70 this @=> _procedure.sleep;
71 this @=> _intProcedure.sleep;
72 this @=> _floatProcedure.sleep;
73 }
74
75 fun void sleep()
76 {
77 value => now;
78 }
79
80 fun Procedure asProcedure()
81 {
82 return _procedure;
83 }
84
85 fun IntProcedure asIntProcedure()
86 {
87 return _intProcedure;
88 }
89
90 fun FloatProcedure asFloatProcedure()
91 {
92 return _floatProcedure;
93 }
94 }
Something went wrong with that request. Please try again.