-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Joery-M/1-shared-implement-timeline-and-t…
…imelineitem 1 shared implement timeline and timelineitem
- Loading branch information
Showing
11 changed files
with
331 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,68 @@ | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { shallowReactive } from 'vue'; | ||
import { computed, ref, shallowReactive } from 'vue'; | ||
import BaseTimeline, { type TimelineType } from '../base/Timeline'; | ||
import type BaseTimelineItem from '../base/TimelineItem'; | ||
import type Media from '../Media/Media'; | ||
|
||
export default class SimpleTimeline extends BaseTimeline { | ||
public name = 'Untitled'; | ||
public name = ref('Untitled'); | ||
public id = uuidv4(); | ||
public type: TimelineType = 'Simple'; | ||
|
||
public items = shallowReactive<BaseTimelineItem[]>([]); | ||
public items = shallowReactive(new Set<BaseTimelineItem>()); | ||
|
||
public duration = 0; | ||
public viewportWidth = 1920; | ||
public viewportWeight = 1080; | ||
public framerate = 60; | ||
public width = ref(1920); | ||
public height = ref(1080); | ||
public framerate = ref(60); | ||
/** | ||
* Duration of a single frame in milliseconds | ||
*/ | ||
public frameDuration = computed(() => { | ||
return 1000 / this.framerate.value; | ||
}); | ||
|
||
constructor() { | ||
constructor(config: SimpleTimelineConfig) { | ||
super(); | ||
this.duration = 0; | ||
this.width = 1920; | ||
this.height = 1080; | ||
this.framerate = 60; | ||
if (config.name) { | ||
this.name.value = config.name; | ||
} | ||
this.width.value = config.width; | ||
this.height.value = config.height; | ||
this.framerate.value = config.framerate; | ||
} | ||
|
||
updateDuration() {} | ||
/** | ||
* Called when an item is dropped in the timeline | ||
*/ | ||
public itemDropped(otherItem: BaseTimelineItem) { | ||
this.items.forEach((item) => { | ||
if ( | ||
item.layer.value === otherItem.layer.value && | ||
item.end.value > otherItem.start.value && | ||
item.start.value < otherItem.end.value && | ||
item.id !== otherItem.id | ||
) { | ||
item.onDroppedOn(otherItem); | ||
} | ||
}); | ||
} | ||
|
||
public usesMedia(media: Media) { | ||
for (const item of this.items) { | ||
return item.hasMedia() && item.media.value == media; | ||
} | ||
return false; | ||
} | ||
|
||
public deleteItem(item: BaseTimelineItem) { | ||
item.Delete(); | ||
return this.items.delete(item); | ||
} | ||
} | ||
|
||
export interface SimpleTimelineConfig { | ||
name?: string; | ||
width: number; | ||
height: number; | ||
framerate: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
import { shallowRef } from 'vue'; | ||
import Media from '../Media/Media'; | ||
import { ref, shallowRef } from 'vue'; | ||
import Media, { type AudioTrackInfo } from '../Media/Media'; | ||
import BaseTimelineItem, { type TimelineItemType } from '../base/TimelineItem'; | ||
import type { TimelineItemMedia } from './interfaces'; | ||
|
||
export default class AudioTimelineItem extends BaseTimelineItem { | ||
export default class AudioTimelineItem extends BaseTimelineItem implements TimelineItemMedia { | ||
public type: TimelineItemType = 'Audio'; | ||
public media = shallowRef<Media>(); | ||
|
||
/** | ||
* Offset from the start of this timeline item to the start of the audio track. | ||
*/ | ||
public startOffset = ref(0); | ||
/** | ||
* Total duration of this audio track. | ||
*/ | ||
public duration = ref(0); | ||
|
||
public trackInfo = ref<AudioTrackInfo>(); | ||
|
||
hasMedia = (): this is typeof this & TimelineItemMedia => true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,27 @@ | ||
import { shallowRef } from 'vue'; | ||
import Media from '../Media/Media'; | ||
import { ref, shallowRef } from 'vue'; | ||
import Media, { type VideoTrackInfo } from '../Media/Media'; | ||
import BaseTimelineItem, { type TimelineItemType } from '../base/TimelineItem'; | ||
import type { TimelineItemMedia } from './interfaces'; | ||
|
||
export default class VideoTimelineItem extends BaseTimelineItem { | ||
export default class VideoTimelineItem extends BaseTimelineItem implements TimelineItemMedia { | ||
public type: TimelineItemType = 'Video'; | ||
public media = shallowRef<Media>(); | ||
|
||
public RenderVideoFrame() {} | ||
/** | ||
* Offset from the start of this timeline item to the start of the video track. | ||
*/ | ||
public startOffset = ref(0); | ||
/** | ||
* Total duration of this video track. | ||
*/ | ||
public duration = ref(0); | ||
|
||
public trackInfo = ref<VideoTrackInfo>(); | ||
|
||
// TODO: Create a whole extensible rendering engine (lol) | ||
public RenderVideoFrame() { | ||
throw new Error('Not implemented'); | ||
} | ||
|
||
hasMedia = (): this is typeof this & TimelineItemMedia => true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { ShallowRef } from 'vue'; | ||
import type Media from '../Media/Media'; | ||
|
||
export interface TimelineItemMedia { | ||
media: ShallowRef<Media | undefined>; | ||
hasMedia: () => this is TimelineItemMedia; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.