|
| 1 | +const expect = chai.expect; |
| 2 | +let metro; |
| 3 | + |
| 4 | +describe('p5.Metro', function () { |
| 5 | + beforeEach(function () { |
| 6 | + metro = new p5.Metro(); |
| 7 | + }); |
| 8 | + |
| 9 | + it('can be created', function () { |
| 10 | + expect(metro).to.have.property('bpm').to.equal(120); |
| 11 | + expect(metro).to.have.property('clock'); |
| 12 | + expect(metro).to.have.property('syncedParts').to.be.an('array'); |
| 13 | + }); |
| 14 | + |
| 15 | + it('can be initialised with a beatlength, bpm', function () { |
| 16 | + metro.beatLength(0.0625); |
| 17 | + metro.setBPM(60); |
| 18 | + expect(metro.tatums).to.equal(4); |
| 19 | + expect(metro.tatumTime).to.equal(0.25); |
| 20 | + expect(metro.getBPM()).to.equal(60); |
| 21 | + }); |
| 22 | + |
| 23 | + it('can be started and stopped', function (done) { |
| 24 | + this.timeout = 2000; |
| 25 | + let ticks; |
| 26 | + metro.setBPM(600); |
| 27 | + metro.start(); |
| 28 | + setTimeout(() => { |
| 29 | + ticks = metro.metroTicks; |
| 30 | + metro.stop(); |
| 31 | + expect(ticks).to.not.equal(0); |
| 32 | + setTimeout(() => { |
| 33 | + expect(metro.metroTicks).to.equal(ticks); |
| 34 | + done(); |
| 35 | + }, 100); |
| 36 | + }, 1000); |
| 37 | + }); |
| 38 | + |
| 39 | + it('can be started and stopped with dealy', function (done) { |
| 40 | + let ticks; |
| 41 | + metro.setBPM(600); |
| 42 | + metro.start(0.1); |
| 43 | + setTimeout(() => { |
| 44 | + ticks = metro.metroTicks; |
| 45 | + metro.stop(0.2); |
| 46 | + expect(ticks).to.not.equal(0); |
| 47 | + setTimeout(() => { |
| 48 | + expect(metro.metroTicks).to.not.equal(ticks); |
| 49 | + }, 100); |
| 50 | + setTimeout(() => { |
| 51 | + ticks = metro.metroTicks; |
| 52 | + setTimeout(() => { |
| 53 | + expect(metro.metroTicks).to.equal(ticks); |
| 54 | + done(); |
| 55 | + }, 100); |
| 56 | + }, 200); |
| 57 | + }, 1000); |
| 58 | + }); |
| 59 | + |
| 60 | + it('can sync parts', function () { |
| 61 | + let part = new p5.Part(); |
| 62 | + part.addPhrase('snare', () => {}, [0, 0, 1, 0]); |
| 63 | + part.setBPM(60); |
| 64 | + part.noLoop(); |
| 65 | + part.start(); |
| 66 | + expect(metro.syncedParts.length).to.equal(0); |
| 67 | + metro.resetSync(part); |
| 68 | + expect(metro.syncedParts.length).to.equal(1); |
| 69 | + }); |
| 70 | + |
| 71 | + it('parts can be pushed into syncedParts', function () { |
| 72 | + let phraseAttack = new p5.Phrase('testerAttack', () => {}, [1, 0, 0, 0]); |
| 73 | + let part = new p5.Part(); |
| 74 | + part.addPhrase(phraseAttack); |
| 75 | + part.setBPM(60); |
| 76 | + part.start(); |
| 77 | + expect(metro.syncedParts.length).to.equal(0); |
| 78 | + metro.pushSync(part); |
| 79 | + expect(metro.syncedParts.length).to.equal(1); |
| 80 | + metro.pushSync(part); |
| 81 | + expect(metro.syncedParts.length).to.equal(2); |
| 82 | + metro.resetSync(part); |
| 83 | + expect(metro.syncedParts.length).to.equal(1); |
| 84 | + }); |
| 85 | +}); |
0 commit comments