Esempio n. 1
0
        public static ProcessResultArray <Clip> Apply(TransposeOptions options, params Clip[] clips)
        {
            if (options.By == null)
            {
                options.By = new Clip(4, true);
            }
            if (options.By.Count == 0 && options.TransposeValues.Length == 0)
            {
                return(new ProcessResultArray <Clip>("No -by clip or transpose values specified."));
            }
            int basePitch = 60;

            if (options.By.Count > 0)
            {
                basePitch = options.By.Notes[0].Pitch;
            }
            if (options.Mode == TransposeMode.Absolute)
            {
                basePitch -= basePitch % 12;
            }

            if (options.Mode == TransposeMode.Relative && options.By.Notes.Count > 0)
            {
                basePitch = options.By.Notes[0].Pitch;
            }

            int[] transposeValues;
            if (options.TransposeValues.Length > 0)
            {
                transposeValues = options.TransposeValues;
            }
            else
            {
                transposeValues = options.By.Notes.Select(x => x.Pitch - basePitch).ToArray();
            }

            foreach (var clip in clips)
            {
                clip.GroupSimultaneousNotes();
                for (var i = 0; i < clip.Count; i++)
                {
                    clip.Notes[i].Pitch += transposeValues[i % transposeValues.Length];
                }
                clip.Flatten();
            }
            return(new ProcessResultArray <Clip>(clips));
        }
Esempio n. 2
0
        public static ProcessResultArray <Clip> Apply(TransposeOptions options, params Clip[] clips)
        {
            if (options.By == null)
            {
                options.By = new Clip(4, true);
            }
            if (options.By.Count == 0 && options.TransposeValues.Length == 0)
            {
                return(new ProcessResultArray <Clip>("No -by clip or transpose values specified."));
            }
            //todo: maybe allow -mono option to monophonize by-clip
            //ClipUtilities.Monophonize(options.By);
            int basePitch = 60;

            if (options.By.Count > 0)
            {
                basePitch = options.By.Notes[0].Pitch;
            }
            if (options.Mode == TransposeMode.Absolute)
            {
                basePitch -= basePitch % 12;
            }

            if (options.Mode == TransposeMode.Relative && options.By.Notes.Count > 0)
            {
                basePitch = options.By.Notes[0].Pitch;
            }

            int[] transposeValues;
            if (options.TransposeValues.Length > 0)
            {
                transposeValues = options.TransposeValues;
            }
            else
            {
                transposeValues = options.By.Notes.Select(x =>
                                                          options.Mode == TransposeMode.Overwrite ?
                                                          x.Pitch :
                                                          x.Pitch - basePitch
                                                          ).ToArray();
            }

            foreach (var clip in clips)
            {
                clip.GroupSimultaneousNotes();
                if (options.Mode == TransposeMode.Overwrite)
                {
                    for (var i = 0; i < clip.Count; i++)
                    {
                        clip.Notes[i].Pitch = transposeValues[i % transposeValues.Length];
                    }
                }
                else
                {
                    for (var i = 0; i < clip.Count; i++)
                    {
                        clip.Notes[i].Pitch += transposeValues[i % transposeValues.Length];
                    }
                }
                clip.Flatten();
            }
            return(new ProcessResultArray <Clip>(clips)); // currently destructive
        }