@omnimedia/omnitool 1.1.0-19 → 1.1.0-21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnimedia/omnitool",
3
- "version": "1.1.0-19",
3
+ "version": "1.1.0-21",
4
4
  "description": "open source video processing tools",
5
5
  "license": "MIT",
6
6
  "author": "Przemysław Gałęzki",
@@ -17,7 +17,7 @@ export const realtime = (
17
17
  let fps = 60
18
18
 
19
19
  let frameDuration = 1000 / fps
20
- let currentTimeS = 0
20
+ let composeTime = 0
21
21
  let lastTime = 0
22
22
  let accumulator = 0
23
23
  let currentTime = 0
@@ -29,12 +29,12 @@ export const realtime = (
29
29
  lastTime = now
30
30
 
31
31
  accumulator += deltaTime
32
- currentTime += deltaTime / 1000
32
+ currentTime += deltaTime
33
33
  onUpdate(currentTime)
34
34
 
35
35
  while (accumulator >= frameDuration) {
36
- onTick(currentTimeS)
37
- currentTimeS += frameDuration / 1000
36
+ onTick(composeTime)
37
+ composeTime += frameDuration
38
38
  accumulator -= frameDuration
39
39
  }
40
40
 
@@ -54,11 +54,11 @@ export const realtime = (
54
54
  if (rafId !== null) cancelAnimationFrame(rafId)
55
55
  rafId = null
56
56
  },
57
- seek(t) {
58
- currentTimeS = Math.max(0, t)
57
+ seek(ms) {
58
+ composeTime = ms
59
59
  accumulator = 0
60
- currentTime = t
61
- onUpdate(t)
60
+ currentTime = ms
61
+ onUpdate(ms)
62
62
  },
63
63
  dispose() {
64
64
  this.pause()
@@ -13,7 +13,7 @@ type ResolveMedia = (hash: string) => DecoderSource
13
13
  export class VideoPlayer {
14
14
  readonly currentTime = signal(0)
15
15
  #controller = realtime(
16
- tickTime => this.#tick(tickTime),
16
+ compositeTime => this.#tick(compositeTime),
17
17
  currentTime => this.currentTime(currentTime)
18
18
  )
19
19
 
@@ -42,15 +42,15 @@ export class VideoPlayer {
42
42
  return new this(driver, canvas, root, sampler)
43
43
  }
44
44
 
45
- async #tick(t: number) {
46
- const dur = this.root.duration
47
- const tt = (t > dur ? dur : t) * 1000
45
+ async #tick(ms: number) {
46
+ const duration = this.root.duration
47
+ const tt = ms > duration ? duration : ms
48
48
  this.root.audio?.onTimeUpdate(tt)
49
49
  const layers = await this.root.visuals?.sampleAt(tt) ?? []
50
50
  const frame = await this.driver.composite(layers)
51
51
  this.context.drawImage(frame, 0, 0)
52
52
  frame.close()
53
- if (t >= dur) this.pause()
53
+ if (ms >= duration) this.pause()
54
54
  }
55
55
 
56
56
  async play() {
@@ -12,6 +12,7 @@ export enum Kind {
12
12
  Gap,
13
13
  Spatial,
14
14
  Transition,
15
+ TextStyle
15
16
  }
16
17
 
17
18
  export enum Effect {
@@ -19,6 +20,12 @@ export enum Effect {
19
20
  }
20
21
 
21
22
  export namespace Item {
23
+ export type TextStyle = {
24
+ id: Id
25
+ kind: Kind.TextStyle
26
+ style: TextStyleOptions
27
+ }
28
+
22
29
  export type Spatial = {
23
30
  id: Id
24
31
  kind: Kind.Spatial
@@ -68,7 +75,7 @@ export namespace Item {
68
75
  content: string
69
76
  duration: number
70
77
  spatialId?: Id
71
- style: TextStyleOptions
78
+ styleId?: Id
72
79
  }
73
80
 
74
81
  export type Transition = {
@@ -1,3 +1,4 @@
1
+ import {TextStyleOptions} from "pixi.js"
1
2
 
2
3
  import {Media} from "../parts/media.js"
3
4
  import {Id, TimelineFile} from "../parts/basics.js"
@@ -22,6 +23,12 @@ export class O {
22
23
  this.state.project = fn(this.state.project)
23
24
  }
24
25
 
26
+ textStyle = (style: TextStyleOptions): Item.TextStyle => ({
27
+ id: this.#getId(),
28
+ kind: Kind.TextStyle,
29
+ style
30
+ })
31
+
25
32
  spatial = (transform: Transform): Item.Spatial => {
26
33
  const item: Item.Spatial = {
27
34
  id: this.#getId(),
@@ -107,8 +114,7 @@ export class O {
107
114
  id: this.#getId(),
108
115
  content,
109
116
  kind: Kind.Text,
110
- duration: 2000,
111
- style: {}
117
+ duration: 2000
112
118
  })
113
119
 
114
120
  gap = (duration: number): Item.Gap => ({
@@ -147,5 +153,20 @@ export class O {
147
153
  return state
148
154
  })
149
155
  }
156
+
157
+ update = <K extends keyof Item.Any>(itemId: Id, key: K, value: Item.Any[K]) => {
158
+ this.#mutate(project => {
159
+ const newItems = project.items.map(item => {
160
+ if (item.id === itemId) {
161
+ return {
162
+ ...item,
163
+ [key]: value,
164
+ }
165
+ }
166
+ return item
167
+ })
168
+ return {...project, items: newItems}
169
+ })
170
+ }
150
171
  }
151
172