public FormGenerateKeySound(bool close_when_finished)
        {
            InitializeComponent();
            bgWork = new System.ComponentModel.BackgroundWorker();
            bgWork.WorkerReportsProgress      = true;
            bgWork.WorkerSupportsCancellation = true;
            folderBrowser = new FolderBrowserDialog();

            m_close_when_finished = close_when_finished;
            m_singer_config1      = VocaloSysUtil.getSingerConfigs(SynthesizerType.VOCALOID1);
            m_singer_config2      = VocaloSysUtil.getSingerConfigs(SynthesizerType.VOCALOID2);
            m_singer_config_utau  = AppManager.editorConfig.UtauSingers.ToArray();
            if (m_singer_config1.Length > 0)
            {
                comboSingingSynthSystem.Items.Add("VOCALOID1");
            }
            if (m_singer_config2.Length > 0)
            {
                comboSingingSynthSystem.Items.Add("VOCALOID2");
            }

            // 取りあえず最初に登録されているresamplerを使うってことで
            string resampler = AppManager.editorConfig.getResamplerAt(0);

            if (m_singer_config_utau.Length > 0 &&
                AppManager.editorConfig.PathWavtool != null && File.Exists(AppManager.editorConfig.PathWavtool) &&
                resampler != null && File.Exists(resampler))
            {
                comboSingingSynthSystem.Items.Add("UTAU");
            }
            if (comboSingingSynthSystem.Items.Count > 0)
            {
                comboSingingSynthSystem.SelectedIndex = 0;
            }
            updateSinger();
            txtDir.Text = Utility.getKeySoundPath();

            registerEventHandlers();
        }
        public static void GenerateSinglePhone(int note, string singer, string file, double amp)
        {
            string renderer = "";

            SingerConfig[] singers1             = VocaloSysUtil.getSingerConfigs(SynthesizerType.VOCALOID1);
            int            c                    = singers1.Length;
            string         first_found_singer   = "";
            string         first_found_renderer = "";

            for (int i = 0; i < c; i++)
            {
                if (first_found_singer.Equals(""))
                {
                    first_found_singer   = singers1[i].VOICENAME;
                    first_found_renderer = VsqFileEx.RENDERER_DSB2;
                }
                if (singers1[i].VOICENAME.Equals(singer))
                {
                    renderer = VsqFileEx.RENDERER_DSB2;
                    break;
                }
            }

            SingerConfig[] singers2 = VocaloSysUtil.getSingerConfigs(SynthesizerType.VOCALOID2);
            c = singers2.Length;
            for (int i = 0; i < c; i++)
            {
                if (first_found_singer.Equals(""))
                {
                    first_found_singer   = singers2[i].VOICENAME;
                    first_found_renderer = VsqFileEx.RENDERER_DSB3;
                }
                if (singers2[i].VOICENAME.Equals(singer))
                {
                    renderer = VsqFileEx.RENDERER_DSB3;
                    break;
                }
            }

            foreach (var sc in AppManager.editorConfig.UtauSingers)
            {
                if (first_found_singer.Equals(""))
                {
                    first_found_singer   = sc.VOICENAME;
                    first_found_renderer = VsqFileEx.RENDERER_UTU0;
                }
                if (sc.VOICENAME.Equals(singer))
                {
                    renderer = VsqFileEx.RENDERER_UTU0;
                    break;
                }
            }

            VsqFileEx vsq = new VsqFileEx(singer, 1, 4, 4, 500000);

            if (renderer.Equals(""))
            {
                singer   = first_found_singer;
                renderer = first_found_renderer;
            }
            vsq.Track[1].getCommon().Version = renderer;
            VsqEvent item = new VsqEvent(1920, new VsqID(0));

            item.ID.LyricHandle = new LyricHandle("あ", "a");
            item.ID.setLength(480);
            item.ID.Note          = note;
            item.ID.VibratoHandle = null;
            item.ID.type          = VsqIDType.Anote;
            vsq.Track[1].addEvent(item);
            vsq.updateTotalClocks();
            int    ms_presend = 500;
            string tempdir    = Path.Combine(AppManager.getCadenciiTempDir(), AppManager.getID());

            if (!Directory.Exists(tempdir))
            {
                try {
                    PortUtil.createDirectory(tempdir);
                } catch (Exception ex) {
                    Logger.write(typeof(FormGenerateKeySound) + ".GenerateSinglePhone; ex=" + ex + "\n");
                    serr.println("Program#GenerateSinglePhone; ex=" + ex);
                    return;
                }
            }
            WaveWriter ww = null;

            try {
                ww = new WaveWriter(file);
                RendererKind     kind        = VsqFileEx.getTrackRendererKind(vsq.Track[1]);
                WaveGenerator    generator   = VSTiDllManager.getWaveGenerator(kind);
                int              sample_rate = vsq.config.SamplingRate;
                FileWaveReceiver receiver    = new FileWaveReceiver(file, 1, 16, sample_rate);
                generator.setReceiver(receiver);
                generator.setGlobalConfig(AppManager.editorConfig);
#if DEBUG
                sout.println("FormGenerateKeySound#GenerateSinglePhone; sample_rate=" + sample_rate);
#endif
                generator.init(vsq, 1, 0, vsq.TotalClocks, sample_rate);
                double         total_sec = vsq.getSecFromClock(vsq.TotalClocks) + 1.0;
                WorkerStateImp state     = new WorkerStateImp();
                generator.begin((long)(total_sec * sample_rate), state);
            } catch (Exception ex) {
                serr.println("FormGenerateKeySound#GenerateSinglePhone; ex=" + ex);
                Logger.write(typeof(FormGenerateKeySound) + ".GenerateSinglePhone; ex=" + ex + "\n");
            } finally {
                if (ww != null)
                {
                    try {
                        ww.close();
                    } catch (Exception ex2) {
                        Logger.write(typeof(FormGenerateKeySound) + ".GenerateSinglePhone; ex=" + ex2 + "\n");
                        serr.println("FormGenerateKeySound#GenerateSinglePhone; ex2=" + ex2);
                    }
                }
            }
        }
Esempio n. 3
0
        public Preference()
        {
            InitializeComponent();
            fontDialog = new FontDialog();
            fontDialog.AllowVectorFonts   = false;
            fontDialog.AllowVerticalFonts = false;
            fontDialog.FontMustExist      = true;
            fontDialog.ShowEffects        = false;
            openUtauCore = new OpenFileDialog();

            folderBrowserSingers = new FolderBrowserDialog();
            folderBrowserSingers.ShowNewFolderButton = false;
            applyLanguage();

            comboVibratoLength.Items.Clear();
            foreach (DefaultVibratoLengthEnum dvl in Enum.GetValues(typeof(DefaultVibratoLengthEnum)))
            {
                comboVibratoLength.Items.Add(DefaultVibratoLengthUtil.toString(dvl));
            }
            comboVibratoLength.SelectedIndex = 1;

            txtAutoVibratoThresholdLength.Text = "480";

            comboAutoVibratoType1.Items.Clear();
            foreach (var vconfig in VocaloSysUtil.vibratoConfigIterator(SynthesizerType.VOCALOID1))
            {
                comboAutoVibratoType1.Items.Add(vconfig);
            }
            if (comboAutoVibratoType1.Items.Count > 0)
            {
                comboAutoVibratoType1.SelectedIndex = 0;
            }

            comboAutoVibratoType2.Items.Clear();
            foreach (var vconfig in VocaloSysUtil.vibratoConfigIterator(SynthesizerType.VOCALOID2))
            {
                comboAutoVibratoType2.Items.Add(vconfig);
            }
            if (comboAutoVibratoType2.Items.Count > 0)
            {
                comboAutoVibratoType2.SelectedIndex = 0;
            }

            updateCustomVibrato();

            comboResolControlCurve.Items.Clear();
            foreach (var cr in ClockResolutionUtility.iterator())
            {
                comboResolControlCurve.Items.Add(ClockResolutionUtility.toString(cr));
            }
            comboResolControlCurve.SelectedIndex = 0;

            comboLanguage.Items.Clear();
            string[] list  = Messaging.getRegisteredLanguage();
            int      index = 0;

            comboLanguage.Items.Add("Default");
            int count = 0;

            foreach (string s in list)
            {
                count++;
                comboLanguage.Items.Add(s);
                if (s.Equals(Messaging.getLanguage()))
                {
                    index = count;
                }
            }
            comboLanguage.SelectedIndex = index;

            SingerConfig[] dict = VocaloSysUtil.getSingerConfigs(SynthesizerType.VOCALOID2);
            m_program_change = new List <string>();
            comboDefualtSinger.Items.Clear();
            foreach (SingerConfig kvp in dict)
            {
                m_program_change.Add(kvp.VOICENAME);
                comboDefualtSinger.Items.Add(kvp.VOICENAME);
            }
            comboDefualtSinger.Enabled = (comboDefualtSinger.Items.Count > 0);
            if (comboDefualtSinger.Items.Count > 0)
            {
                comboDefualtSinger.SelectedIndex = 0;
            }

            updateMidiDevice();

            listSingers.Columns[0].Width = columnWidthHeaderProgramChange;
            listSingers.Columns[1].Width = columnWidthHeaderName;
            listSingers.Columns[2].Width = columnWidthHeaderPath;


            numBuffer.Maximum = EditorConfig.MAX_BUFFER_MILLISEC;
            numBuffer.Minimum = EditorConfig.MIN_BUFFER_MILLIXEC;

            registerEventHandlers();
            setResources();
        }