Log in

View Full Version : GetChannels() wants a series of integers?


FranceBB
25th November 2021, 20:57
If I do something like:

ColorBars(848, 480, pixel_type="YV12")

GetChannels(1,2,2)

it works and gets me channel 1, 2, 2.

Now, if I declare this function:

function mylist(int n, string "s")
{
s = default(s, "")
return (n > 0) ? mylist(n - 1, String(n) + "," + s)
\ : s
}

and then I call it like this:

ColorBars(848, 480, pixel_type="YV12")

clip1_channels=(HasAudio) ? (AudioChannels) : 0

clip1_channels_list=mylist(clip1_channels) + String(clip1_channels)

MessageClip(clip1_channels_list)

it returns 1,2,2

however if I try to use the variable I've just got with 1,2,2 inside GetChannels() it doesn't work:

ColorBars(848, 480, pixel_type="YV12")

clip1_channels=(HasAudio) ? (AudioChannels) : 0

clip1_channels_list=mylist(clip1_channels) + String(clip1_channels)

GetChannels(clip1_channels_list)



Script error: Invalid arguments to function 'GetChannels'.

p.s the reason I brought this up is because I'm trying to write a function that takes two inputs, clip1 and clip2, uses the video from clip1 and the audio from clip1 and uses mergechannels to append the channels from clip2 to clip1. The user is gonna have two more parameters: InsertAt and DeleteCount. The first, InsertAt, allows the user to choose after which channel of the clip1 the audio from clip2 is inserted. DeleteCount instead allows the user to delete a certain channel he specifies from clip1.
I was writing the basics but the aforementioned issue came up...

function InsertExternalAudio(clip clp1, clip clp2) {

clip1_channels=(clp1.HasAudio) ? (clp1.AudioChannels) : 0
clip2_channels=(clp2.HasAudio) ? (clp2.AudioChannels) : 0

my_clip1=(clip1_channels>0) ? clp1.ResampleAudio(48000).ConvertAudioToFloat() : clp1
my_clip2=(clip2_channels>0) ? clp2.ResampleAudio(48000).ConvertAudioToFloat() : clp2

clip1_channels_list=mylist(clip1_channels) + String(clip1_channels)
clip2_channels_list=mylist(clip2_channels) + String(clip2_channels)

audio1=GetChannels(my_clip1, clip1_channels_list)
audio2=GetChannels(my_clip2, clip2_channels_list)

video=clp1.KillAudio()
audio=MergeChannels(audio1, audio2)
AudioDub(video, audio)

}

StainlessS
26th November 2021, 06:37
I just popped by before I went to bed [05:32], and have done little more than glance at less than half of your post,
but methinks that [4th code block]

GetChannels(clip1_channels_list)

is calling getchannels with a string, getChannels dont work with a string, so maybe something like

Eval ( "GetChannels(" + clip1_channels_list + ")" )

Might work [assigns result to last - maybe you can get it to work by creating array from string, but I know nought bout that new fangled stuff].

VoodooFX
26th November 2021, 10:54
I dunno what GetChannels is, but your current mylist() could be replaced with something like this [how many channels there can be?]:


if (clip1_channels == 0) {
audio1=GetChannels(my_clip1, 0)
} else if (clip1_channels == 1) {
audio1=GetChannels(my_clip1, 1,1)
} else if (clip1_channels == 2) {
audio1=GetChannels(my_clip1, 1,2,2)
} else if (clip1_channels == 3) {
audio1=GetChannels(my_clip1, 1,2,3,3)
} else if (clip1_channels == 4) {
audio1=GetChannels(my_clip1, 1,2,3,4,4)
} else if (clip1_channels == 5) {
audio1=GetChannels(my_clip1, 1,2,3,4,5,5)
}