File size: 1,452 Bytes
f23825d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { assemble, deassemble } from "./noteAssembler"

describe("deassemble", () => {
  it("should deassemble to two notes", () => {
    const note = {
      type: "channel",
      subtype: "note",
      noteNumber: 32,
      tick: 100,
      duration: 60,
      velocity: 50,
      channel: 3,
    }
    const result = deassemble(note)
    expect(result.length).toBe(2)
    expect(result[0]).toStrictEqual({
      type: "channel",
      subtype: "noteOn",
      noteNumber: 32,
      deltaTime: 0,
      tick: 100,
      velocity: 50,
      channel: 3,
    })
    expect(result[1]).toStrictEqual({
      type: "channel",
      subtype: "noteOff",
      noteNumber: 32,
      deltaTime: 0,
      tick: 100 + 60,
      velocity: 0,
      channel: 3,
    })
  })
})

describe("assemble", () => {
  it("should assemble to an note", () => {
    const notes = [
      {
        type: "channel",
        subtype: "noteOn",
        noteNumber: 14,
        tick: 93,
        velocity: 120,
        channel: 5,
      },
      {
        type: "channel",
        subtype: "noteOff",
        noteNumber: 14,
        tick: 193,
        velocity: 0,
        channel: 5,
      },
    ]
    const result = assemble(notes)
    expect(result.length).toBe(1)
    expect(result[0]).toStrictEqual({
      id: -1,
      type: "channel",
      subtype: "note",
      noteNumber: 14,
      tick: 93,
      velocity: 120,
      channel: 5,
      duration: 100,
    })
  })
})