-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStereo to Mono.cs
135 lines (121 loc) · 4.03 KB
/
Stereo to Mono.cs
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
* This script converts stereo events to pairs of mono events. It
* only operates on the selected audio events or, if none are
* selected, all audio events.
*
* Revision Date: March 26, 2010.
**/
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ScriptPortal.Vegas;
public class EntryPoint {
Vegas myVegas;
public void FromVegas(Vegas vegas) {
myVegas = vegas;
List<WorkItem> workItems = new List<WorkItem>();
List<AudioEvent> events = new List<AudioEvent>();
AddSelectedAudioEvents(events);
if (0 == events.Count)
{
AddAllAudioEvents(events);
}
foreach (AudioEvent audioEvent in events)
{
if (audioEvent.Channels == ChannelRemapping.None)
{
Track destTrack = FindDestTrack(audioEvent.Track);
if (null == destTrack)
{
destTrack = CreateDestTrack(audioEvent.Track);
}
workItems.Add(new WorkItem(audioEvent, destTrack));
}
}
foreach (WorkItem workItem in workItems)
{
AudioEvent destEvent = (AudioEvent) workItem.SrcEvent.Copy(workItem.DstTrack, workItem.SrcEvent.Start);
workItem.SrcEvent.Channels = ChannelRemapping.DisableRight;
destEvent.Channels = ChannelRemapping.DisableLeft;
TrackEventGroup sourceGroup = workItem.SrcEvent.Group;
if (null == sourceGroup)
{
sourceGroup = new TrackEventGroup();
myVegas.Project.Groups.Add(sourceGroup);
sourceGroup.Add(workItem.SrcEvent);
}
sourceGroup.Add(destEvent);
}
}
class WorkItem
{
public readonly AudioEvent SrcEvent;
public readonly Track DstTrack;
public WorkItem(AudioEvent src, Track dst)
{
SrcEvent = src;
DstTrack = dst;
}
}
void AddSelectedAudioEvents(List<AudioEvent> events)
{
foreach (Track track in myVegas.Project.Tracks)
{
if (track.IsAudio())
{
foreach (AudioEvent audioEvent in track.Events)
{
if (audioEvent.Selected)
{
events.Add(audioEvent);
}
}
}
}
}
void AddAllAudioEvents(List<AudioEvent> events)
{
foreach (Track track in myVegas.Project.Tracks)
{
if (track.IsAudio())
{
foreach (AudioEvent audioEvent in track.Events)
{
events.Add(audioEvent);
}
}
}
}
// {07226981-7E13-45fc-825E-D54B6D63CBF1}
Guid StereoToMonoPairCustomDataID = new Guid(0x7226981, 0x7e13, 0x45fc, 0x82, 0x5e, 0xd5, 0x4b, 0x6d, 0x63, 0xcb, 0xf1);
AudioTrack FindDestTrack(Track srcTrack)
{
string dstTok = srcTrack.CustomData.GetObject(StereoToMonoPairCustomDataID) as string;
if (String.IsNullOrEmpty(dstTok))
return null;
foreach (Track dstTrack in myVegas.Project.Tracks)
{
if (!dstTrack.IsAudio())
continue;
if (dstTrack == srcTrack)
continue;
string srcTok = dstTrack.CustomData.GetObject(StereoToMonoPairCustomDataID) as string;
if (String.IsNullOrEmpty(srcTok))
continue;
if (dstTok == srcTok)
{
return dstTrack as AudioTrack;
}
}
return null;
}
Track CreateDestTrack(Track srcTrack)
{
Track dstTrack = new AudioTrack(srcTrack.Index + 1);
myVegas.Project.Tracks.Add(dstTrack);
Guid pairTok = Guid.NewGuid();
dstTrack.CustomData.SetObject(StereoToMonoPairCustomDataID, pairTok.ToString());
srcTrack.CustomData.SetObject(StereoToMonoPairCustomDataID, pairTok.ToString());
return dstTrack;
}
}