Nanook.TheGhost.ProjectSong.FinaliseSettings C# (CSharp) Method

FinaliseSettings() public method

Apply any padding to notes, audio, frets and generate practise markers
public FinaliseSettings ( ) : void
return void
        public void FinaliseSettings()
        {
            int notesLength = 0;

            List<string> wavs = new List<string>();

            this.UpdateQbChanges();

            bool updateNotes = this.Notes.LastChanged > this.LastApplied || _project.Defaults.ReapplyAll;
            bool updateAudio = this.Audio.LastChanged > this.LastApplied || _project.Defaults.ReapplyAll;

            //if either the notes or the audio have changed then update the notes.

            if (updateNotes || updateAudio)
            {
                //this sets the _startPaddingMs and _fretPadding (these are important as they are required to pad the audio correctly)

                notesLength = replaceNotesItems();
            }

            if (updateAudio || this.Notes.UpdateAffectsAudio)
            {
                //import missing files (was the item green then modified)
                this.Audio.ImportMissingAudioFiles();

                this.Audio.RemoveAndDeleteRedundantFiles();

                float ac = 0;
                if (this.Audio.RhythmFile != null && this.Audio.RhythmFile.Name.Length != 0 && File.Exists(this.Audio.RawRhythmFilename))
                    ac++;
                if (this.Audio.GuitarFile != null && this.Audio.GuitarFile.Name.Length != 0 && File.Exists(this.Audio.RawGuitarFilename))
                    ac++;
                if (this.Audio.SongFiles.Count > 0)
                    ac++;

                if (ac != 0)
                    ac = 0.66F; // 1 / ac;

                //ensure audio is all the same length
                int newAudioLen = this.Audio.AudioLength + _startPaddingMs + _fretPadding; //to keep in sync
                if (newAudioLen < notesLength + 500) //to ensure is greater than notes (last fret)
                    newAudioLen = notesLength + 500;

                if (this.Audio.RhythmFile != null && this.Audio.RhythmFile.Name.Length != 0 && File.Exists(this.Audio.RawRhythmFilename))
                    WavProcessor.SetLengthSilenceAndVolume(_startPaddingMs + _fretPadding, newAudioLen, (this.Audio.RhythmFile.Volume * ac) / 100F, this.Audio.RawRhythmFilename);
                if (this.Audio.GuitarFile != null && this.Audio.GuitarFile.Name.Length != 0 && File.Exists(this.Audio.RawGuitarFilename))
                    WavProcessor.SetLengthSilenceAndVolume(_startPaddingMs + _fretPadding, newAudioLen, (this.Audio.GuitarFile.Volume * ac) / 100F, this.Audio.RawGuitarFilename);

                for (int i = 0; i < this.Audio.SongFiles.Count; i++)
                {
                    if (File.Exists(this.Audio.RawSongFilenames[i]))
                    {
                        float vol = this.Audio.SongFiles[i].Volume / 100F;

                        //if no guitar or rhythm then half the volume of the song as it will be used as the guitar as well (stops the distortion).
                        if ((this.Audio.RhythmFile == null || this.Audio.RhythmFile.Name.Length == 0 || !File.Exists(this.Audio.RawRhythmFilename))
                            && (this.Audio.GuitarFile == null || this.Audio.GuitarFile.Name.Length == 0 || !File.Exists(this.Audio.RawGuitarFilename)))
                        {
                            if (this.Audio.SongFiles.Count == 1)
                                WavProcessor.Normalize(this.Audio.RawSongFilenames[i], true); //don't normalise when there's >1 because all files will be 100% and not the correct levels
                            else
                                vol *= 0.5F; //about half the volume
                        }
                        else
                            vol *= ac; //third if guitar and rhythm exists for example

                        WavProcessor.SetLengthSilenceAndVolume(_startPaddingMs + _fretPadding, newAudioLen, vol, this.Audio.RawSongFilenames[i]);
                    }
                }
            }
        }