File: FormVibratoConfig.cs

package info (click to toggle)
cadencii 3.3.9%2Bsvn20110818.r1732-6
  • links: PTS
  • area: main
  • in suites: buster
  • size: 35,916 kB
  • sloc: cs: 160,836; java: 42,449; cpp: 7,605; ansic: 1,728; perl: 1,087; makefile: 236; php: 142; xml: 117; sh: 21
file content (539 lines) | stat: -rw-r--r-- 23,198 bytes parent folder | download | duplicates (5)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
/*
 * FormVibratoConfig.cs
 * Copyright © 2008-2011 kbinani
 *
 * This file is part of org.kbinani.cadencii.
 *
 * org.kbinani.cadencii is free software; you can redistribute it and/or
 * modify it under the terms of the GPLv3 License.
 *
 * org.kbinani.cadencii is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */
#if JAVA
package org.kbinani.cadencii;

//INCLUDE-SECTION IMPORT ../BuildJavaUI/src/org/kbinani/cadencii/FormVibratoConfig.java

import java.awt.event.*;
import java.util.*;
import org.kbinani.*;
import org.kbinani.apputil.*;
import org.kbinani.vsq.*;
import org.kbinani.windows.forms.*;
#else
using System;
using org.kbinani;
using org.kbinani.apputil;
using org.kbinani.vsq;
using org.kbinani.windows.forms;
using org.kbinani.java.awt.event_;
using org.kbinani.java.util;

namespace org.kbinani.cadencii
{
    using BEventArgs = System.EventArgs;
    using boolean = System.Boolean;
    using BEventHandler = System.EventHandler;
#endif

#if JAVA
    public class FormVibratoConfig extends BDialog{
#else
    public class FormVibratoConfig : BDialog
    {
#endif
        private VibratoHandle m_vibrato;
        private int m_note_length;

        /// <summary>
        /// コンストラクタ.引数vibrato_handleには,Cloneしたものを渡さなくてよい.
        /// </summary>
        /// <param name="vibrato_handle"></param>
        /// <param name="note_length"></param>
        /// <param name="default_vibrato_length"></param>
        /// <param name="type"></param>
        /// <param name="use_original"></param>
        public FormVibratoConfig( 
            VibratoHandle vibrato_handle, 
            int note_length, 
            DefaultVibratoLengthEnum default_vibrato_length, 
            SynthesizerType type, 
            boolean use_original )
        {
#if JAVA
            super();
            initialize();
#else
            InitializeComponent();
#endif

#if DEBUG
            AppManager.debugWriteLine( "FormVibratoConfig.ctor(Vsqhandle,int,DefaultVibratoLength)" );
            AppManager.debugWriteLine( "    (vibrato_handle==null)=" + (vibrato_handle == null) );
            sout.println( "    type=" + type );
#endif
            if ( use_original ) {
                radioUserDefined.setSelected( true );
            } else {
                if ( type == SynthesizerType.VOCALOID1 ) {
                    radioVocaloid1.setSelected( true );
                } else {
                    radioVocaloid2.setSelected( true );
                }
            }
            if ( vibrato_handle != null ) {
                m_vibrato = (VibratoHandle)vibrato_handle.clone();
            }

            // 選択肢の状態を更新
            updateComboBoxStatus();
            // どれを選ぶか?
            if( vibrato_handle != null ){
#if DEBUG
                sout.println( "FormVibratoConfig#.ctor; vibrato_handle.IconID=" + vibrato_handle.IconID );
#endif
                for ( int i = 0; i < comboVibratoType.getItemCount(); i++ ) {
                    VibratoHandle handle = (VibratoHandle)comboVibratoType.getItemAt( i );
#if DEBUG
                    sout.println( "FormVibratoConfig#.ctor; handle.IconID=" + handle.IconID );
#endif
                    if ( vibrato_handle.IconID.Equals( handle.IconID ) ) {
                        comboVibratoType.setSelectedIndex( i );
                        break;
                    }
                }
            }

            txtVibratoLength.setEnabled( vibrato_handle != null );
            if ( vibrato_handle != null ) {
                txtVibratoLength.setText( (int)((float)vibrato_handle.getLength() / (float)note_length * 100.0f) + "" );
            } else {
                String s = "";
                if ( default_vibrato_length == DefaultVibratoLengthEnum.L100 ) {
                    s = "100";
                } else if ( default_vibrato_length == DefaultVibratoLengthEnum.L50 ) {
                    s = "50";
                } else if ( default_vibrato_length == DefaultVibratoLengthEnum.L66 ) {
                    s = "66";
                } else if ( default_vibrato_length == DefaultVibratoLengthEnum.L75 ) {
                    s = "75";
                }
                txtVibratoLength.setText( s );
            }
  
            m_note_length = note_length;

            registerEventHandlers();
            setResources();
            applyLanguage();

            Util.applyFontRecurse( this, AppManager.editorConfig.getBaseFont() );
        }

        #region public methods
        public void applyLanguage()
        {
            setTitle( _( "Vibrato property" ) );
            lblVibratoLength.setText( _( "Vibrato length" ) );
            lblVibratoLength.setMnemonic( KeyEvent.VK_L, txtVibratoLength );
            lblVibratoType.setText( _( "Vibrato Type" ) );
            lblVibratoType.setMnemonic( KeyEvent.VK_T, comboVibratoType );
            btnOK.setText( _( "OK" ) );
            btnCancel.setText( _( "Cancel" ) );
            groupSelect.setTitle( _( "Select from" ) );
        }

        /// <summary>
        /// 編集済みのビブラート設定.既にCloneされているので,改めてCloneしなくて良い
        /// </summary>
        public VibratoHandle getVibratoHandle()
        {
            return m_vibrato;
        }
        #endregion

        #region helper methods
        private static String _( String id )
        {
            return Messaging.getMessage( id );
        }

        /// <summary>
        /// ビブラートの選択肢の状態を更新します
        /// </summary>
        private void updateComboBoxStatus()
        {
            // 選択位置
            int old = comboVibratoType.getSelectedIndex();

            // 全部削除
            comboVibratoType.removeAllItems();

            // 「ビブラート無し」を表すアイテムを追加
            VibratoHandle empty = new VibratoHandle();
            empty.setCaption( "[Non Vibrato]" );
            empty.IconID = "$04040000";
            comboVibratoType.addItem( empty );

            // 選択元を元に,選択肢を追加する
            if ( radioUserDefined.isSelected() ) {
                // ユーザー定義のを使う場合
                int size = AppManager.editorConfig.AutoVibratoCustom.size();
                for ( int i = 0; i < size; i++ ) {
                    VibratoHandle handle = AppManager.editorConfig.AutoVibratoCustom.get( i );
                    comboVibratoType.addItem( handle );
                }
            } else {
                // VOCALOID1/VOCALOID2のシステム定義のを使う場合
                SynthesizerType type = radioVocaloid1.isSelected() ? SynthesizerType.VOCALOID1 : SynthesizerType.VOCALOID2;
                for ( Iterator<VibratoHandle> itr = VocaloSysUtil.vibratoConfigIterator( type ); itr.hasNext(); ) {
                    VibratoHandle vconfig = itr.next();
                    comboVibratoType.addItem( vconfig );
                }
            }

            // 選択位置を戻せるなら戻す
            int index = old;
            if ( index >= comboVibratoType.getItemCount() ) {
                index = comboVibratoType.getItemCount() - 1;
            }
            if ( 0 <= index ) {
                comboVibratoType.setSelectedIndex( index );
            }
        }

        private void registerEventHandlers()
        {
            btnOK.Click += new BEventHandler( btnOK_Click );
            btnCancel.Click += new BEventHandler( btnCancel_Click );
            radioUserDefined.CheckedChanged += new BEventHandler( handleRadioCheckedChanged );
            comboVibratoType.SelectedIndexChanged += new BEventHandler( comboVibratoType_SelectedIndexChanged );
              txtVibratoLength.TextChanged += new BEventHandler( txtVibratoLength_TextChanged );
        }

        public void handleRadioCheckedChanged( Object sender, EventArgs e )
        {
            comboVibratoType.SelectedIndexChanged -= new BEventHandler( comboVibratoType_SelectedIndexChanged );
            updateComboBoxStatus();
            comboVibratoType.SelectedIndexChanged += new BEventHandler( comboVibratoType_SelectedIndexChanged );
        }

        private void setResources()
        {
        }
        #endregion

        #region event handlers
        public void btnOK_Click( Object sender, BEventArgs e )
        {
            setDialogResult( BDialogResult.OK );
        }

        public void comboVibratoType_SelectedIndexChanged( Object sender, BEventArgs e )
        {
            int index = comboVibratoType.getSelectedIndex();
#if DEBUG
            sout.println( "FormVibratoConfig#comboVibratoType_SelectedIndexChanged; index=" + index );
#endif
            if ( index >= 0 ) {
                String s = ((VibratoHandle)comboVibratoType.getItemAt( index )).IconID;
#if DEBUG
                sout.println( "FormVibratoConfig#comboVibratoType_SelectedIndexChanged; index=" + index + "; iconid=" + s );
#endif
                if ( s.Equals( "$04040000" ) ) {
#if DEBUG
                    sout.println( "FormVibratoConfig#comboVibratoType_SelectedIndexChanged; B; m_vibrato -> null" );
#endif
                    m_vibrato = null;
                    txtVibratoLength.setEnabled( false );
                    return;
                } else {
                    txtVibratoLength.setEnabled( true );
                    VibratoHandle src = null;
                    if ( radioUserDefined.isSelected() ) {
                        int size = vec.size( AppManager.editorConfig.AutoVibratoCustom );
                        for ( int i = 0; i < size; i++ ) {
                            VibratoHandle handle = vec.get( AppManager.editorConfig.AutoVibratoCustom, i );
                            if ( str.compare( s, handle.IconID ) ) {
                                src = handle;
                                break;
                            }
                        }
                    } else {
                        SynthesizerType type = radioVocaloid1.isSelected() ? SynthesizerType.VOCALOID1 : SynthesizerType.VOCALOID2;
                        for ( Iterator<VibratoHandle> itr = VocaloSysUtil.vibratoConfigIterator( type ); itr.hasNext(); ) {
                            VibratoHandle vconfig = itr.next();
                            if ( str.compare( s, vconfig.IconID ) ) {
                                src = vconfig;
                                break;
                            }
                        }
                    }
#if DEBUG
                    sout.println( "FormVibratoConfig#comboVibratoType_SelectedIndexChanged; (src==null)=" + (src == null) );
#endif
                    if ( src != null ) {
                        int percent;
                        try {
                            percent = str.toi( txtVibratoLength.getText() );
                        } catch ( Exception ex ) {
                            return;
                        }
                        m_vibrato = (VibratoHandle)src.clone();
                        m_vibrato.setLength( (int)(m_note_length * percent / 100.0f) );
                        return;
                    }
                }
            }
        }

        public void txtVibratoLength_TextChanged( Object sender, BEventArgs e )
        {
#if DEBUG
            AppManager.debugWriteLine( "txtVibratoLength_TextChanged" );
            AppManager.debugWriteLine( "    (m_vibrato==null)=" + (m_vibrato == null) );
#endif
            int percent = 0;
            try {
                percent = str.toi( txtVibratoLength.getText() );
                if ( percent < 0 ) {
                    percent = 0;
                } else if ( 100 < percent ) {
                    percent = 100;
                }
            } catch ( Exception ex ) {
                return;
            }
            if ( percent == 0 ) {
                m_vibrato = null;
#if DEBUG
                sout.println( "FormVibratoConfig#txtVibratoLength_TextChanged; A; m_vibrato -> null" );
#endif
                txtVibratoLength.setEnabled( false );
            } else {
                if ( m_vibrato != null ) {
                    int new_length = (int)(m_note_length * percent / 100.0f);
                    m_vibrato.setLength( new_length );
                }
            }
        }

        public void btnCancel_Click( Object sender, BEventArgs e )
        {
            setDialogResult( BDialogResult.CANCEL );
        }
        #endregion

#if JAVA
        #region UI Impl for Java
        //INCLUDE-SECTION FIELD ../BuildJavaUI/src/org/kbinani/cadencii/FormVibratoConfig.java
        //INCLUDE-SECTION METHOD ../BuildJavaUI/src/org/kbinani/cadencii/FormVibratoConfig.java
        #endregion
#else
        #region UI Impl for C#
        /// <summary>
        /// 必要なデザイナ変数です。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 使用中のリソースをすべてクリーンアップします。
        /// </summary>
        /// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
        protected override void Dispose( boolean disposing )
        {
            if ( disposing && (components != null) ) {
                components.Dispose();
            }
            base.Dispose( disposing );
        }

        #region Windows フォーム デザイナで生成されたコード

        /// <summary>
        /// デザイナ サポートに必要なメソッドです。このメソッドの内容を
        /// コード エディタで変更しないでください。
        /// </summary>
        private void InitializeComponent()
        {
            this.lblVibratoLength = new org.kbinani.windows.forms.BLabel();
            this.lblVibratoType = new org.kbinani.windows.forms.BLabel();
            this.txtVibratoLength = new org.kbinani.cadencii.NumberTextBox();
            this.label3 = new org.kbinani.windows.forms.BLabel();
            this.comboVibratoType = new org.kbinani.windows.forms.BComboBox();
            this.btnCancel = new org.kbinani.windows.forms.BButton();
            this.btnOK = new org.kbinani.windows.forms.BButton();
            this.groupSelect = new BGroupBox();
            this.radioUserDefined = new BRadioButton();
            this.radioVocaloid2 = new BRadioButton();
            this.radioVocaloid1 = new BRadioButton();
            this.groupSelect.SuspendLayout();
            this.SuspendLayout();
            // 
            // lblVibratoLength
            // 
            this.lblVibratoLength.AutoSize = true;
            this.lblVibratoLength.Location = new System.Drawing.Point( 12, 15 );
            this.lblVibratoLength.Name = "lblVibratoLength";
            this.lblVibratoLength.Size = new System.Drawing.Size( 94, 12 );
            this.lblVibratoLength.TabIndex = 0;
            this.lblVibratoLength.Text = "Vibrato Length(&L)";
            // 
            // lblVibratoType
            // 
            this.lblVibratoType.AutoSize = true;
            this.lblVibratoType.Location = new System.Drawing.Point( 12, 39 );
            this.lblVibratoType.Name = "lblVibratoType";
            this.lblVibratoType.Size = new System.Drawing.Size( 86, 12 );
            this.lblVibratoType.TabIndex = 1;
            this.lblVibratoType.Text = "Vibrato Type(&T)";
            // 
            // txtVibratoLength
            // 
            this.txtVibratoLength.Enabled = false;
            this.txtVibratoLength.Location = new System.Drawing.Point( 143, 12 );
            this.txtVibratoLength.Name = "txtVibratoLength";
            this.txtVibratoLength.Size = new System.Drawing.Size( 61, 19 );
            this.txtVibratoLength.TabIndex = 2;
            this.txtVibratoLength.Type = org.kbinani.cadencii.NumberTextBox.ValueType.Integer;
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point( 210, 15 );
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size( 49, 12 );
            this.label3.TabIndex = 3;
            this.label3.Text = "%(0-100)";
            // 
            // comboVibratoType
            // 
            this.comboVibratoType.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.comboVibratoType.FormattingEnabled = true;
            this.comboVibratoType.Location = new System.Drawing.Point( 143, 36 );
            this.comboVibratoType.Name = "comboVibratoType";
            this.comboVibratoType.Size = new System.Drawing.Size( 167, 20 );
            this.comboVibratoType.TabIndex = 4;
            // 
            // btnCancel
            // 
            this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnCancel.Location = new System.Drawing.Point( 240, 129 );
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size( 75, 23 );
            this.btnCancel.TabIndex = 7;
            this.btnCancel.Text = "Cancel";
            this.btnCancel.UseVisualStyleBackColor = true;
            // 
            // btnOK
            // 
            this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.btnOK.Location = new System.Drawing.Point( 159, 129 );
            this.btnOK.Name = "btnOK";
            this.btnOK.Size = new System.Drawing.Size( 75, 23 );
            this.btnOK.TabIndex = 6;
            this.btnOK.Text = "OK";
            this.btnOK.UseVisualStyleBackColor = true;
            // 
            // groupSelect
            // 
            this.groupSelect.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.groupSelect.Controls.Add( this.radioUserDefined );
            this.groupSelect.Controls.Add( this.radioVocaloid2 );
            this.groupSelect.Controls.Add( this.radioVocaloid1 );
            this.groupSelect.Location = new System.Drawing.Point( 14, 61 );
            this.groupSelect.Name = "groupSelect";
            this.groupSelect.Size = new System.Drawing.Size( 301, 55 );
            this.groupSelect.TabIndex = 9;
            this.groupSelect.TabStop = false;
            this.groupSelect.Text = "Select from";
            // 
            // radioUserDefined
            // 
            this.radioUserDefined.AutoSize = true;
            this.radioUserDefined.Location = new System.Drawing.Point( 198, 21 );
            this.radioUserDefined.Name = "radioUserDefined";
            this.radioUserDefined.Size = new System.Drawing.Size( 88, 16 );
            this.radioUserDefined.TabIndex = 11;
            this.radioUserDefined.TabStop = true;
            this.radioUserDefined.Text = "User defined";
            this.radioUserDefined.UseVisualStyleBackColor = true;
            // 
            // radioVocaloid2
            // 
            this.radioVocaloid2.AutoSize = true;
            this.radioVocaloid2.Checked = true;
            this.radioVocaloid2.Location = new System.Drawing.Point( 106, 21 );
            this.radioVocaloid2.Name = "radioVocaloid2";
            this.radioVocaloid2.Size = new System.Drawing.Size( 86, 16 );
            this.radioVocaloid2.TabIndex = 10;
            this.radioVocaloid2.TabStop = true;
            this.radioVocaloid2.Text = "VOCALOID2";
            this.radioVocaloid2.UseVisualStyleBackColor = true;
            // 
            // radioVocaloid1
            // 
            this.radioVocaloid1.AutoSize = true;
            this.radioVocaloid1.Location = new System.Drawing.Point( 14, 21 );
            this.radioVocaloid1.Name = "radioVocaloid1";
            this.radioVocaloid1.Size = new System.Drawing.Size( 86, 16 );
            this.radioVocaloid1.TabIndex = 9;
            this.radioVocaloid1.TabStop = true;
            this.radioVocaloid1.Text = "VOCALOID1";
            this.radioVocaloid1.UseVisualStyleBackColor = true;
            // 
            // FormVibratoConfig
            // 
            this.AcceptButton = this.btnOK;
            this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 12F );
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.CancelButton = this.btnCancel;
            this.ClientSize = new System.Drawing.Size( 327, 164 );
            this.Controls.Add( this.groupSelect );
            this.Controls.Add( this.btnOK );
            this.Controls.Add( this.btnCancel );
            this.Controls.Add( this.comboVibratoType );
            this.Controls.Add( this.label3 );
            this.Controls.Add( this.txtVibratoLength );
            this.Controls.Add( this.lblVibratoType );
            this.Controls.Add( this.lblVibratoLength );
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FormVibratoConfig";
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
            this.Text = "Vibrato property";
            this.groupSelect.ResumeLayout( false );
            this.groupSelect.PerformLayout();
            this.ResumeLayout( false );
            this.PerformLayout();

        }
        #endregion

        private BLabel lblVibratoLength;
        private BLabel lblVibratoType;
        private NumberTextBox txtVibratoLength;
        private BLabel label3;
        private BComboBox comboVibratoType;
        private BButton btnCancel;
        private BButton btnOK;
        private BGroupBox groupSelect;
        private BRadioButton radioVocaloid2;
        private BRadioButton radioVocaloid1;
        private BRadioButton radioUserDefined;
        #endregion
#endif
    }

#if !JAVA
}
#endif