diff --git a/trunk/Boare.Lib.AppUtil/AuthorListEntry.cs b/trunk/Boare.Lib.AppUtil/AuthorListEntry.cs
index 8b75b3c..c23d126 100644
--- a/trunk/Boare.Lib.AppUtil/AuthorListEntry.cs
+++ b/trunk/Boare.Lib.AppUtil/AuthorListEntry.cs
@@ -11,40 +11,49 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
-using System.Drawing;
+#if JAVA
+package org.kbinani.apputil;
+
+import java.awt.*;
+#else
+using System;
+using bocoree.java.awt;
namespace Boare.Lib.AppUtil {
+#endif
public class AuthorListEntry {
- string m_name;
- FontStyle m_style;
+ String m_name;
+ int m_style;
- public AuthorListEntry( string name, FontStyle style )
- : this( name ) {
+ public AuthorListEntry( String name, int style ) {
+ m_name = name;
m_style = style;
}
- public AuthorListEntry( string name ) {
- m_name = name;
- m_style = FontStyle.Regular;
+#if JAVA
+ public AuthorListEntry( String name ){
+ this( name, Font.PLAIN );
+#else
+ public AuthorListEntry( String name )
+ : this( name, Font.PLAIN ) {
+#endif
}
public AuthorListEntry() {
m_name = "";
- m_style = FontStyle.Regular;
+ m_style = Font.PLAIN;
}
- public string Name {
- get {
- return m_name;
- }
+ public String getName() {
+ return m_name;
}
- public FontStyle Style {
- get {
- return m_style;
- }
+ public int getStyle() {
+ return m_style;
}
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.AppUtil/BHScrollBar.Designer.cs b/trunk/Boare.Lib.AppUtil/BHScrollBar.Designer.cs
index 9564606..166780e 100644
--- a/trunk/Boare.Lib.AppUtil/BHScrollBar.Designer.cs
+++ b/trunk/Boare.Lib.AppUtil/BHScrollBar.Designer.cs
@@ -1,4 +1,5 @@
-/*
+#if !JAVA
+/*
* BHScrollBar.Designer.cs
* Copyright (c) 2009 kbinani
*
@@ -12,7 +13,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace Boare.Lib.AppUtil {
- partial class BHScrollBar {
+ partial class OBSOLUTE_BHScrollBar {
///
/// 必要なデザイナ変数です。
///
@@ -64,3 +65,4 @@ namespace Boare.Lib.AppUtil {
private System.Windows.Forms.HScrollBar hScroll;
}
}
+#endif
diff --git a/trunk/Boare.Lib.AppUtil/BHScrollBar.cs b/trunk/Boare.Lib.AppUtil/BHScrollBar.cs
index 0831ec9..899ac4b 100644
--- a/trunk/Boare.Lib.AppUtil/BHScrollBar.cs
+++ b/trunk/Boare.Lib.AppUtil/BHScrollBar.cs
@@ -1,4 +1,5 @@
-/*
+#if !JAVA
+/*
* BHScrollBar.cs
* Copyright (c) 2009 kbinani
*
@@ -19,13 +20,13 @@ namespace Boare.Lib.AppUtil {
///
/// Valueの値が正しくMinimumからMaximumの間を動くスクロールバー
///
- public partial class BHScrollBar : UserControl {
+ public partial class OBSOLUTE_BHScrollBar : UserControl {
int m_max = 100;
int m_min = 0;
public event EventHandler ValueChanged;
- public BHScrollBar() {
+ public OBSOLUTE_BHScrollBar() {
InitializeComponent();
}
@@ -84,3 +85,4 @@ namespace Boare.Lib.AppUtil {
}
}
+#endif
diff --git a/trunk/Boare.Lib.AppUtil/BSplitContainer.cs b/trunk/Boare.Lib.AppUtil/BSplitContainer.cs
index aac39df..dcfbd19 100644
--- a/trunk/Boare.Lib.AppUtil/BSplitContainer.cs
+++ b/trunk/Boare.Lib.AppUtil/BSplitContainer.cs
@@ -1,4 +1,5 @@
-/*
+#if !JAVA
+/*
* BSplitContainer.cs
* Copyright (c) 2008-2009 kbinani
*
@@ -102,6 +103,14 @@ namespace Boare.Lib.AppUtil {
}
}
+ public bool isSplitterFixed() {
+ return this.IsSplitterFixed;
+ }
+
+ public void setSplitterFixed( bool value ) {
+ this.IsSplitterFixed = value;
+ }
+
///
/// 使用中のリソースをすべてクリーンアップします。
///
@@ -277,6 +286,14 @@ namespace Boare.Lib.AppUtil {
}
}
+ public int getDividerSize() {
+ return this.SplitterWidth;
+ }
+
+ public void setDividerSize( int value ) {
+ this.SplitterWidth = value;
+ }
+
private bool UpdateLayout( int splitter_distance, int splitter_width, int panel1_min, int panel2_min, bool check_only ) {
Point mouse = this.PointToClient( Control.MousePosition );
int pad1 = (m_panel1.BorderStyle == BorderStyle.FixedSingle) ? 1 : 0;
@@ -396,6 +413,14 @@ namespace Boare.Lib.AppUtil {
}
}
+ public int getDividerLocation() {
+ return this.SplitterDistance;
+ }
+
+ public void setDividerLocation( int value ) {
+ this.SplitterDistance = value;
+ }
+
public Orientation Orientation {
get {
return m_orientation;
@@ -504,3 +529,4 @@ namespace Boare.Lib.AppUtil {
}
}
+#endif
diff --git a/trunk/Boare.Lib.AppUtil/BSplitterPanel.cs b/trunk/Boare.Lib.AppUtil/BSplitterPanel.cs
index e886e8d..02dfcc0 100644
--- a/trunk/Boare.Lib.AppUtil/BSplitterPanel.cs
+++ b/trunk/Boare.Lib.AppUtil/BSplitterPanel.cs
@@ -1,4 +1,5 @@
-/*
+#if !JAVA
+/*
* BSplitterPanel.cs
* Copyright (c) 2008-2009 kbinani
*
@@ -94,3 +95,4 @@ namespace Boare.Lib.AppUtil {
}
}
+#endif
diff --git a/trunk/Boare.Lib.AppUtil/BTrackBar.cs b/trunk/Boare.Lib.AppUtil/BTrackBar.cs
index afd4b16..36551f8 100644
--- a/trunk/Boare.Lib.AppUtil/BTrackBar.cs
+++ b/trunk/Boare.Lib.AppUtil/BTrackBar.cs
@@ -1,4 +1,5 @@
-/*
+#if !JAVA
+/*
* BTrackBar.cs
* Copyright (c) 2009 kbinani
*
@@ -287,3 +288,4 @@ namespace Boare.Lib.AppUtil {
}
}
+#endif
diff --git a/trunk/Boare.Lib.AppUtil/BVScrollBar.Designer.cs b/trunk/Boare.Lib.AppUtil/BVScrollBar.Designer.cs
index 83939a7..f0484a0 100644
--- a/trunk/Boare.Lib.AppUtil/BVScrollBar.Designer.cs
+++ b/trunk/Boare.Lib.AppUtil/BVScrollBar.Designer.cs
@@ -12,7 +12,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace Boare.Lib.AppUtil {
- partial class BVScrollBar {
+ partial class OBSOLUTE_BVScrollBar {
///
/// 必要なデザイナ変数です。
///
diff --git a/trunk/Boare.Lib.AppUtil/BVScrollBar.cs b/trunk/Boare.Lib.AppUtil/BVScrollBar.cs
index 1a43c4d..2592103 100644
--- a/trunk/Boare.Lib.AppUtil/BVScrollBar.cs
+++ b/trunk/Boare.Lib.AppUtil/BVScrollBar.cs
@@ -1,4 +1,5 @@
-/*
+#if !JAVA
+/*
* BVScrollBar.cs
* Copyright (c) 2009 kbinani
*
@@ -19,13 +20,13 @@ namespace Boare.Lib.AppUtil {
///
/// Valueの値が正しくMinimumからMaximumの間を動くスクロールバー
///
- public partial class BVScrollBar : UserControl {
+ public partial class OBSOLUTE_BVScrollBar : UserControl {
int m_max = 100;
int m_min = 0;
public event EventHandler ValueChanged;
- public BVScrollBar() {
+ public OBSOLUTE_BVScrollBar() {
InitializeComponent();
}
@@ -84,3 +85,4 @@ namespace Boare.Lib.AppUtil {
}
}
+#endif
diff --git a/trunk/Boare.Lib.AppUtil/BitmapEx.cs b/trunk/Boare.Lib.AppUtil/BitmapEx.cs
index 4a22791..62202af 100644
--- a/trunk/Boare.Lib.AppUtil/BitmapEx.cs
+++ b/trunk/Boare.Lib.AppUtil/BitmapEx.cs
@@ -1,4 +1,5 @@
-/*
+#if !JAVA
+/*
* BitmapEx.cs
* Copyright (c) 2008-2009 kbinani
*
@@ -156,4 +157,5 @@ namespace Boare.Lib.AppUtil {
}
}
-}
\ No newline at end of file
+}
+#endif
diff --git a/trunk/Boare.Lib.AppUtil/Boare.Lib.AppUtil.csproj b/trunk/Boare.Lib.AppUtil/Boare.Lib.AppUtil.csproj
index 0b38cdb..4b16d1c 100644
--- a/trunk/Boare.Lib.AppUtil/Boare.Lib.AppUtil.csproj
+++ b/trunk/Boare.Lib.AppUtil/Boare.Lib.AppUtil.csproj
@@ -3,7 +3,7 @@
Debug
AnyCPU
- 9.0.30729
+ 9.0.21022
2.0
{0C58B068-272F-4390-A14F-3D72AFCF3DFB}
Library
@@ -18,37 +18,17 @@
true
- full
- false
bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- Boare.Lib.AppUtil.xml
+ DEBUG
true
+ bin\x86\Debug\Boare.Lib.AppUtil.XML
+ AnyCPU
- pdbonly
- true
bin\Release\
- TRACE
- prompt
- 4
- Boare.Lib.AppUtil.xml
- true
-
-
- x86
- bin\x86\Debug\
- true
- DEBUG
- bin\x86\Debug\Boare.Lib.AppUtil.XML
-
-
- x86
- bin\x86\Release\
true
bin\x86\Release\Boare.Lib.AppUtil.XML
+ AnyCPU
@@ -81,14 +61,10 @@
Form
-
- InputBox.cs
-
-
Component
@@ -99,6 +75,7 @@
UserControl
+
Form
@@ -111,8 +88,6 @@
BVScrollBar.cs
-
-
diff --git a/trunk/Boare.Lib.AppUtil/ColorBar.cs b/trunk/Boare.Lib.AppUtil/ColorBar.cs
index d0464f2..f8afeb0 100644
--- a/trunk/Boare.Lib.AppUtil/ColorBar.cs
+++ b/trunk/Boare.Lib.AppUtil/ColorBar.cs
@@ -1,3 +1,4 @@
+#if !JAVA
/*
* ColorBar.cs
* Copyright (c) 2008-2009 kbinani
@@ -41,7 +42,7 @@ namespace Boare.Lib.AppUtil {
rflow_rainbow = 20,
}
- public static partial class Misc {
+ public static partial class Util {
const double OPORT_OP_PI = 3.141592653589793238462643383279502884197169399;
const double OPORT_OP_PI2 = 3.141592653589793238462643383279502884197169399 * 2.0;
const double OPORT_OP_1P9 = 1.0 / 9.0;
@@ -120,7 +121,7 @@ namespace Boare.Lib.AppUtil {
h = oport_colorbar_rainbow_banded_h( y );
s = oport_colorbar_rainbow_banded_s( y );
v = oport_colorbar_rainbow_banded_v( y );
- HsvToRgb( h, s, v, out r, out g, out b );
+ Util.HsvToRgb( h, s, v, out r, out g, out b );
red = (int)(r * 255.0);
green = (int)(g * 255.0);
blue = (int)(b * 255.0);
@@ -139,7 +140,7 @@ namespace Boare.Lib.AppUtil {
h = oport_colorbar_rainbow_striped_h( y );
s = oport_colorbar_rainbow_striped_s( y );
v = oport_colorbar_rainbow_striped_v( y );
- HsvToRgb( h, s, v, out r, out g, out b );
+ Util.HsvToRgb( h, s, v, out r, out g, out b );
red = (int)(r * 255.0);
green = (int)(g * 255.0);
blue = (int)(b * 255.0);
@@ -1116,3 +1117,4 @@ namespace Boare.Lib.AppUtil {
}
}
+#endif
diff --git a/trunk/Boare.Lib.AppUtil/CubicSpline.cs b/trunk/Boare.Lib.AppUtil/CubicSpline.cs
index bf0f59e..dfd4fa4 100644
--- a/trunk/Boare.Lib.AppUtil/CubicSpline.cs
+++ b/trunk/Boare.Lib.AppUtil/CubicSpline.cs
@@ -1,4 +1,5 @@
-/*
+#if !JAVA
+/*
* CubicSpline.cs
* Copyright (c) 2008-2009 kbinani
*
@@ -273,3 +274,4 @@ namespace Boare.Lib.AppUtil {
}
}
+#endif
diff --git a/trunk/Boare.Lib.AppUtil/CursorUtil.cs b/trunk/Boare.Lib.AppUtil/CursorUtil.cs
index 9dfda41..d99d42e 100644
--- a/trunk/Boare.Lib.AppUtil/CursorUtil.cs
+++ b/trunk/Boare.Lib.AppUtil/CursorUtil.cs
@@ -1,4 +1,5 @@
-#define RGB24
+#if !JAVA
+#define RGB24
using System;
using System.Runtime.InteropServices;
using System.Drawing;
@@ -208,3 +209,4 @@ namespace Boare.Lib.AppUtil {
}
}
+#endif
diff --git a/trunk/Boare.Lib.AppUtil/DockPanelContainer.cs b/trunk/Boare.Lib.AppUtil/DockPanelContainer.cs
index c8784b2..8194400 100644
--- a/trunk/Boare.Lib.AppUtil/DockPanelContainer.cs
+++ b/trunk/Boare.Lib.AppUtil/DockPanelContainer.cs
@@ -1,4 +1,5 @@
-using System;
+#if !JAVA
+using System;
using System.Windows.Forms;
namespace Boare.Lib.AppUtil {
@@ -7,3 +8,4 @@ namespace Boare.Lib.AppUtil {
}
}
+#endif
diff --git a/trunk/Boare.Lib.AppUtil/ISO639.cs b/trunk/Boare.Lib.AppUtil/ISO639.cs
index 601b2fa..645960b 100644
--- a/trunk/Boare.Lib.AppUtil/ISO639.cs
+++ b/trunk/Boare.Lib.AppUtil/ISO639.cs
@@ -1,4 +1,5 @@
-/*
+#if !JAVA
+/*
* ISO639.cs
* Copyright (c) 2008-2009 kbinani
*
@@ -27,3 +28,4 @@ namespace Boare.Lib.AppUtil {
}
}
+#endif
diff --git a/trunk/Boare.Lib.AppUtil/InputBox.Designer.cs b/trunk/Boare.Lib.AppUtil/InputBox.Designer.cs
index 23c6272..1c11a90 100644
--- a/trunk/Boare.Lib.AppUtil/InputBox.Designer.cs
+++ b/trunk/Boare.Lib.AppUtil/InputBox.Designer.cs
@@ -97,6 +97,7 @@ namespace Boare.Lib.AppUtil {
this.Name = "InputBox";
this.ShowIcon = false;
this.ShowInTaskbar = false;
+ this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "InputBox";
this.ResumeLayout( false );
this.PerformLayout();
diff --git a/trunk/Boare.Lib.AppUtil/InputBox.cs b/trunk/Boare.Lib.AppUtil/InputBox.cs
index db2ea7e..495accb 100644
--- a/trunk/Boare.Lib.AppUtil/InputBox.cs
+++ b/trunk/Boare.Lib.AppUtil/InputBox.cs
@@ -11,27 +11,281 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
+#if JAVA
+package org.kbinani.apputil;
+
+import java.awt.*;
+import javax.swing.*;
+import org.kbinani.*;
+import org.kbinani.windows.forms.*;
+#else
using System;
using System.Windows.Forms;
+using bocoree.windows.forms;
namespace Boare.Lib.AppUtil {
- public partial class InputBox : Form {
- public InputBox( string message ) {
+ using BEventArgs = System.EventArgs;
+#endif
+
+#if JAVA
+ public class InputBox extends BForm{
+#else
+ public class InputBox : BForm {
+#endif
+ private BLabel lblMessage;
+ private BButton btnCancel;
+ private BTextBox txtInput;
+ private BButton btnOk;
+#if JAVA
+ public boolean closed = false;
+ private BDialogResult m_result = BDialogResult.CANCEL;
+#else
+ ///
+ /// 必要なデザイナ変数です。
+ ///
+ private System.ComponentModel.IContainer components = null;
+#endif
+
+ public InputBox( String message ) {
+#if JAVA
+ initializeComponent();
+#else
InitializeComponent();
- lblMessage.Text = message;
+#endif
+ lblMessage.setText( message );
}
- public string Result {
- get {
- return txtInput.Text;
- }
- set {
- txtInput.Text = value;
+#if JAVA
+ public class ShowDialogRunner implements Runnable{
+ public void run(){
+ show();
+ while( !closed ){
+ try{
+ Thread.sleep( 100 );
+ }catch( Exception ex ){
+ break;
+ }
+ }
+ hide();
}
}
- private void btnOk_Click( object sender, EventArgs e ) {
+ public BDialogResult showDialog(){
+ Thread t = new Thread( new ShowDialogRunner() );
+ t.run();
+ return m_result;
+ }
+#endif
+
+ public String getResult(){
+ return txtInput.getText();
+ }
+
+ public void setResult( String value ){
+ txtInput.setText( value );
+ }
+
+ public void btnOk_Click( Object sender, BEventArgs e ) {
+#if JAVA
+ closed = true;
+ m_result = BDialogResult.OK;
+#else
DialogResult = DialogResult.OK;
+#endif
}
+
+#if JAVA
+ private void initializeComponent(){
+ txtInput = new BTextBox();
+ btnOk = new BButton();
+ lblMessage = new BLabel();
+ btnCancel = new BButton();
+ //
+ // txtInput
+ //
+ //
+ // btnOk
+ //
+ this.btnOk.setText( "OK" );
+ this.btnOk.clickEvent.add( new BEventHandler( this, "btnOk_Click" ) );
+ //
+ // lblMessage
+ //
+ //
+ // btnCancel
+ //
+ this.btnCancel.setText( "Cancel" );
+ this.btnCancel.setVisible( false );
+ //
+ // InputBox
+ //
+ GridBagLayout gridbag = new GridBagLayout();
+ GridBagConstraints c = new GridBagConstraints();
+ setLayout( gridbag );
+ // 1段目
+ JPanel jp1_1 = new JPanel();
+ gridbag.setConstraints( jp1_1, c );
+ add( jp1_1 );
+
+ c.gridwidth = 2;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ gridbag.setConstraints( lblMessage, c );
+ add( lblMessage );
+
+ JPanel jp1_2 = new JPanel();
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ c.fill = GridBagConstraints.NONE;
+ gridbag.setConstraints( jp1_2, c );
+ add( jp1_2 );
+
+ // 2段目
+ JPanel jp2_1 = new JPanel();
+ c.gridwidth = 1;
+ gridbag.setConstraints( jp2_1, c );
+ add( jp2_1 );
+
+ c.gridwidth = 2;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.weightx = 1.0;
+ gridbag.setConstraints( txtInput, c );
+ add( txtInput );
+
+ JPanel jp2_2 = new JPanel();
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ c.fill = GridBagConstraints.NONE;
+ c.weightx = 0.0;
+ gridbag.setConstraints( jp2_2, c );
+ add( jp2_2 );
+
+ // 3段目
+ JPanel jp3 = new JPanel();
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ gridbag.setConstraints( jp3, c );
+ add( jp3 );
+
+ // 4段目
+ JPanel jp4_1 = new JPanel();
+ c.gridwidth = 2;
+ gridbag.setConstraints( jp4_1, c );
+ add( jp4_1 );
+
+ c.gridwidth = 1;
+ c.anchor = GridBagConstraints.EAST;
+ gridbag.setConstraints( btnOk, c );
+ add( btnOk );
+
+ JPanel jp4_2 = new JPanel();
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ c.anchor = GridBagConstraints.CENTER;
+ gridbag.setConstraints( jp4_2, c );
+ add( jp4_2 );
+
+ // 5段目
+ JPanel jp5 = new JPanel();
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ c.gridheight = GridBagConstraints.REMAINDER;
+ c.fill = GridBagConstraints.BOTH;
+ gridbag.setConstraints( jp5, c );
+ add( jp5 );
+
+ this.formClosedEvent.add( new BEventHandler( this, "InputBox_FormClosed" ) );
+ this.setTitle( "InputBox" );
+ this.setSize( 339, 110 );
+ }
+
+ public void InputBox_FormClosed( Object sender, BEventArgs e ){
+ closed = true;
+ }
+#else
+ ///
+ /// 使用中のリソースをすべてクリーンアップします。
+ ///
+ /// マネージ リソースが破棄される場合 true、破棄されない場合は false です。
+ protected override void Dispose( bool disposing ) {
+ if ( disposing && (components != null) ) {
+ components.Dispose();
+ }
+ base.Dispose( disposing );
+ }
+
+ #region Windows フォーム デザイナで生成されたコード
+
+ ///
+ /// デザイナ サポートに必要なメソッドです。このメソッドの内容を
+ /// コード エディタで変更しないでください。
+ ///
+ private void InitializeComponent() {
+ this.txtInput = new BTextBox();
+ this.btnOk = new BButton();
+ this.lblMessage = new BLabel();
+ this.btnCancel = new BButton();
+ this.SuspendLayout();
+ //
+ // txtInput
+ //
+ this.txtInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.txtInput.Location = new System.Drawing.Point( 12, 24 );
+ this.txtInput.Name = "txtInput";
+ this.txtInput.Size = new System.Drawing.Size( 309, 19 );
+ this.txtInput.TabIndex = 0;
+ //
+ // btnOk
+ //
+ this.btnOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.btnOk.Location = new System.Drawing.Point( 246, 49 );
+ this.btnOk.Name = "btnOk";
+ this.btnOk.Size = new System.Drawing.Size( 75, 23 );
+ this.btnOk.TabIndex = 1;
+ this.btnOk.Text = "OK";
+ this.btnOk.UseVisualStyleBackColor = true;
+ this.btnOk.Click += new System.EventHandler( this.btnOk_Click );
+ //
+ // lblMessage
+ //
+ this.lblMessage.AutoSize = true;
+ this.lblMessage.Location = new System.Drawing.Point( 12, 9 );
+ this.lblMessage.Name = "lblMessage";
+ this.lblMessage.Size = new System.Drawing.Size( 0, 12 );
+ this.lblMessage.TabIndex = 2;
+ //
+ // btnCancel
+ //
+ this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
+ this.btnCancel.Location = new System.Drawing.Point( -100, 49 );
+ this.btnCancel.Name = "btnCancel";
+ this.btnCancel.Size = new System.Drawing.Size( 75, 23 );
+ this.btnCancel.TabIndex = 3;
+ this.btnCancel.Text = "Cancel";
+ this.btnCancel.UseVisualStyleBackColor = true;
+ //
+ // InputBox
+ //
+ 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( 333, 82 );
+ this.Controls.Add( this.btnCancel );
+ this.Controls.Add( this.lblMessage );
+ this.Controls.Add( this.btnOk );
+ this.Controls.Add( this.txtInput );
+ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
+ this.MaximizeBox = false;
+ this.MinimizeBox = false;
+ this.Name = "InputBox";
+ this.ShowIcon = false;
+ this.ShowInTaskbar = false;
+ this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
+ this.Text = "InputBox";
+ this.ResumeLayout( false );
+ this.PerformLayout();
+
+ }
+ #endregion
+#endif
}
+
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.AppUtil/MessageBody.cs b/trunk/Boare.Lib.AppUtil/MessageBody.cs
index 2ca09ac..bb7361a 100644
--- a/trunk/Boare.Lib.AppUtil/MessageBody.cs
+++ b/trunk/Boare.Lib.AppUtil/MessageBody.cs
@@ -11,192 +11,235 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
+#if JAVA
+package org.kbinani.apputil;
+
+import java.util.*;
+import java.io.*;
+import java.awt.image.*;
+import org.kbinani.*;
+#else
using System;
-using System.Collections.Generic;
-using System.Text;
-using System.IO;
+using bocoree;
+using bocoree.java.util;
+using bocoree.java.io;
namespace Boare.Lib.AppUtil {
+ using boolean = System.Boolean;
+#endif
public class MessageBody {
- public string lang;
- public string po_header = "";
- public Dictionary list = new Dictionary();
+ public String lang;
+ public String poHeader = "";
+ public TreeMap list = new TreeMap();
- public MessageBody( string lang_ ) {
+ public MessageBody( String lang_ ) {
lang = lang_;
}
- public MessageBody( string lang, string[] ids, string[] messages ) {
+ public MessageBody( String lang, String[] ids, String[] messages ) {
this.lang = lang;
- list = new Dictionary();
+ list = new TreeMap();
for( int i = 0; i < ids.Length; i++ ) {
- list.Add( ids[i], new MessageBodyEntry( messages[i], new string[] { } ) );
+ list.put( ids[i], new MessageBodyEntry( messages[i], new String[] { } ) );
}
}
- public MessageBody( string lang_, string file ) {
+ public MessageBody( String lang_, String file ) {
lang = lang_;
- po_header = "";
- using ( StreamReader sr = new StreamReader( file ) ) {
- while ( sr.Peek() >= 0 ) {
- string msgid;
- string first_line = sr.ReadLine();
- string[] location;
- string last_line = ReadTillMessageEnd( sr, first_line, "msgid", out msgid, out location );
- string msgstr;
- string[] location_dumy;
- last_line = ReadTillMessageEnd( sr, last_line, "msgstr", out msgstr, out location_dumy );
- if ( msgid.Length > 0 ) {
- if ( list.ContainsKey( msgid ) ) {
- list[msgid] = new MessageBodyEntry( msgstr, location );
- } else {
- list.Add( msgid, new MessageBodyEntry( msgstr, location ) );
- }
+ poHeader = "";
+ BufferedReader sr = null;
+ try {
+ sr = new BufferedReader( new FileReader( file ) );
+ String line2 = "";
+ while ( (line2 = sr.readLine()) != null ) {
+ ByRef msgid = new ByRef( "" );
+ String first_line = line2;
+ ByRef location = new ByRef();
+ String last_line = readTillMessageEnd( sr, first_line, "msgid", msgid, location );
+ ByRef msgstr = new ByRef( "" );
+ ByRef location_dumy = new ByRef();
+ last_line = readTillMessageEnd( sr, last_line, "msgstr", msgstr, location_dumy );
+ if ( PortUtil.getStringLength( msgid.value ) > 0 ) {
+ list.put( msgid.value, new MessageBodyEntry( msgstr.value, location.value ) );
} else {
- po_header = msgstr;
- string[] spl = po_header.Split( new char[] { (char)0x0d, (char)0x0a }, StringSplitOptions.RemoveEmptyEntries );
- po_header = "";
+ poHeader = msgstr.value;
+ String[] spl = PortUtil.splitString( poHeader, new char[] { (char)0x0d, (char)0x0a }, true );
+ poHeader = "";
int count = 0;
- foreach ( string line in spl ) {
- string[] spl2 = line.Split( new char[] { ':' }, 2 );
+ for ( int i = 0; i < spl.Length; i++ ) {
+ String line = spl[i];
+ String[] spl2 = PortUtil.splitString( line, new char[] { ':' }, 2 );
if ( spl2.Length == 2 ) {
- string name = spl2[0].Trim();
- if ( name.ToLower() == "Content-Type".ToLower() ) {
- po_header += (count == 0 ? "" : "\n") + "Content-Type: text/plain; charset=UTF-8";
- } else if ( name.ToLower() == "Content-Transfer-Encoding".ToLower() ) {
- po_header += (count == 0 ? "" : "\n") + "Content-Transfer-Encoding: 8bit";
+ String name = spl2[0].Trim();
+ String ct = "Content-Type";
+ String cte = "Content-Transfer-Encoding";
+ if ( name.ToLower().Equals( ct.ToLower() ) ) {
+ poHeader += (count == 0 ? "" : "\n") + "Content-Type: text/plain; charset=UTF-8";
+ } else if ( name.ToLower().Equals( cte.ToLower() ) ) {
+ poHeader += (count == 0 ? "" : "\n") + "Content-Transfer-Encoding: 8bit";
} else {
- po_header += (count == 0 ? "" : "\n") + line;
+ poHeader += (count == 0 ? "" : "\n") + line;
}
} else {
- po_header += (count == 0 ? "" : "\n") + line;
+ poHeader += (count == 0 ? "" : "\n") + line;
}
count++;
}
}
}
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sr != null ) {
+ try {
+ sr.close();
+ } catch ( Exception ex2 ) {
+ }
+ }
}
-#if DEBUG
- Console.WriteLine( "MessageBody..ctor; po_header=" + po_header );
-#endif
}
- public string GetMessage( string id ) {
- if ( list.ContainsKey( id ) ) {
- string ret = list[id].Message;
- if ( ret == "" ) {
+ public String getMessage( String id ) {
+ if ( list.containsKey( id ) ) {
+ String ret = list.get( id ).message;
+ if ( ret.Equals( "" ) ) {
return id;
} else {
- return list[id].Message;
+ return list.get( id ).message;
}
}
return id;
}
- public MessageBodyEntry GetMessageDetail( string id ) {
- if ( list.ContainsKey( id ) ) {
- string ret = list[id].Message;
- if ( ret == "" ) {
- return new MessageBodyEntry( id, new string[] { } );
+ public MessageBodyEntry getMessageDetail( String id ) {
+ if ( list.containsKey( id ) ) {
+ String ret = list.get( id ).message;
+ if ( ret.Equals( "" ) ) {
+ return new MessageBodyEntry( id, new String[] { } );
} else {
- return list[id];
+ return list.get( id );
}
}
- return new MessageBodyEntry( id, new string[] { } );
+ return new MessageBodyEntry( id, new String[] { } );
}
- public void Write( string file ) {
- using ( StreamWriter sw = new StreamWriter( file ) ) {
- if ( po_header != "" ) {
- sw.WriteLine( "msgid \"\"" );
- sw.WriteLine( "msgstr \"\"" );
- string[] spl = po_header.Split( new char[] { (char)0x0d, (char)0x0a }, StringSplitOptions.RemoveEmptyEntries );
- foreach ( string line in spl ) {
- sw.WriteLine( "\"" + line + "\\" + "n\"" );
+ public void write( String file ) {
+ BufferedWriter sw = null;
+ try {
+ sw = new BufferedWriter( new FileWriter( file ) );
+ if ( !poHeader.Equals( "" ) ) {
+ sw.write( "msgid \"\"" );
+ sw.newLine();
+ sw.write( "msgstr \"\"" );
+ sw.newLine();
+ String[] spl = PortUtil.splitString( poHeader, new char[] { (char)0x0d, (char)0x0a }, true );
+ for ( int i = 0; i < spl.Length; i++ ){
+ String line = spl[i];
+ sw.write( "\"" + line + "\\" + "n\"" );
+ sw.newLine();
}
- sw.WriteLine();
+ sw.newLine();
} else {
- sw.WriteLine( "msgid \"\"" );
- sw.WriteLine( "msgstr \"\"" );
- sw.WriteLine( "\"Content-Type: text/plain; charset=UTF-8\\" + "n\"" );
- sw.WriteLine( "\"Content-Transfer-Encoding: 8bit\\" + "n\"" );
- sw.WriteLine();
+ sw.write( "msgid \"\"" );
+ sw.newLine();
+ sw.write( "msgstr \"\"" );
+ sw.newLine();
+ sw.write( "\"Content-Type: text/plain; charset=UTF-8\\" + "n\"" );
+ sw.newLine();
+ sw.write( "\"Content-Transfer-Encoding: 8bit\\" + "n\"" );
+ sw.newLine();
+ sw.newLine();
}
- foreach ( string key in list.Keys ) {
- string skey = key.Replace( "\n", "\\n\"\n\"" );
- string s = list[key].Message;
- List location = list[key].Location;
- for ( int i = 0; i < location.Count; i++ ) {
- sw.WriteLine( "#: " + location[i] );
+ for ( Iterator itr = list.keySet().iterator(); itr.hasNext(); ){
+ String key = (String)itr.next();
+ String skey = key.Replace( "\n", "\\n\"\n\"" );
+ MessageBodyEntry mbe = list.get( key );
+ String s = mbe.message;
+ Vector location = mbe.location;
+ int count = location.size();
+ for ( int i = 0; i < count; i++ ) {
+ sw.write( "#: " + location.get( i ) );
+ sw.newLine();
}
- sw.WriteLine( "msgid \"" + skey + "\"" );
+ sw.write( "msgid \"" + skey + "\"" );
+ sw.newLine();
s = s.Replace( "\n", "\\n\"\n\"" );
- sw.WriteLine( "msgstr \"" + s + "\"" );
- sw.WriteLine();
+ sw.write( "msgstr \"" + s + "\"" );
+ sw.newLine();
+ sw.newLine();
+ }
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sw != null ) {
+ try {
+ sw.close();
+ } catch ( Exception ex2 ) {
+ }
}
}
}
- private static void SeparateEntryAndMessage( string source, out string entry, out string message ) {
- string line = source.Trim();
- entry = "";
- message = "";
- if ( line.Length <= 0 ) {
+ private static void separateEntryAndMessage( String source, ByRef entry, ByRef message ) {
+ String line = source.Trim();
+ entry.value = "";
+ message.value = "";
+ if ( PortUtil.getStringLength( line ) <= 0 ) {
return;
}
int index_space = line.IndexOf( ' ' );
int index_dquoter = line.IndexOf( '"' );
int index = Math.Min( index_dquoter, index_space );
- entry = line.Substring( 0, index );
- message = line.Substring( index_dquoter + 1 );
- message = message.Substring( 0, message.Length - 1 );
+ entry.value = line.Substring( 0, index );
+ message.value = line.Substring( index_dquoter + 1 );
+ message.value = message.value.Substring( 0, PortUtil.getStringLength( message.value ) - 1 );
}
- private static string ReadTillMessageEnd( StreamReader sr, string first_line, string entry, out string msg, out string[] locations ) {
- msg = "";
- string line = first_line;
- List location = new List();
- bool entry_found = false;
+ private static String readTillMessageEnd( BufferedReader sr, String first_line, String entry, ByRef msg, ByRef locations )
+#if JAVA
+ throws IOException
+#endif
+ {
+ msg.value = "";
+ String line = first_line;
+ Vector location = new Vector();
+ boolean entry_found = false;
if ( line.StartsWith( entry ) ) {
// 1行目がすでに"entry"の行だった場合
- string dum, dum2;
- SeparateEntryAndMessage( line, out dum, out dum2 );
- msg += dum2;
+ ByRef dum = new ByRef( "" );
+ ByRef dum2 = new ByRef( "" );
+ separateEntryAndMessage( line, dum, dum2 );
+ msg.value += dum2.value;
} else {
- while ( true ) {
+ while ( (line = sr.readLine()) != null ) {
if ( line.StartsWith( "#:" ) ) {
line = line.Substring( 2 ).Trim();
- location.Add( line );
+ location.add( line );
} else if ( line.StartsWith( entry ) ) {
- string dum, dum2;
- SeparateEntryAndMessage( line, out dum, out dum2 );
- msg += dum2;
- break;
- }
- if ( sr.Peek() >= 0 ) {
- line = sr.ReadLine();
- } else {
+ ByRef dum = new ByRef( "" );
+ ByRef dum2 = new ByRef( "" );
+ separateEntryAndMessage( line, dum, dum2 );
+ msg.value += dum2.value;
break;
}
}
}
- locations = location.ToArray();
- string ret = "";
- while ( sr.Peek() >= 0 ) {
- line = sr.ReadLine();
+ locations.value = location.toArray( new String[] { } );
+ String ret = "";
+ while ( (line = sr.readLine()) != null ) {
if ( !line.StartsWith( "\"" ) ) {
- msg = msg.Replace( "\\\"", "\"" );
- msg = msg.Replace( "\\n", "\n" );
+ msg.value = msg.value.Replace( "\\\"", "\"" );
+ msg.value = msg.value.Replace( "\\n", "\n" );
return line;
}
int index = line.LastIndexOf( "\"" );
- msg += line.Substring( 1, index - 1 );
+ msg.value += line.Substring( 1, index - 1 );
}
- msg = msg.Replace( "\\\"", "\"" );
- msg = msg.Replace( "\\n", "\n" );
+ msg.value = msg.value.Replace( "\\\"", "\"" );
+ msg.value = msg.value.Replace( "\\n", "\n" );
return line;
}
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.AppUtil/MessageBodyEntry.cs b/trunk/Boare.Lib.AppUtil/MessageBodyEntry.cs
index 21367cd..1d35678 100644
--- a/trunk/Boare.Lib.AppUtil/MessageBodyEntry.cs
+++ b/trunk/Boare.Lib.AppUtil/MessageBodyEntry.cs
@@ -11,21 +11,29 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
+#if JAVA
+package org.kbinani.apputil;
+
+import java.util.*;
+#else
using System;
-using System.Collections.Generic;
+using bocoree.java.util;
namespace Boare.Lib.AppUtil {
+#endif
public class MessageBodyEntry {
- public string Message;
- public List Location = new List();
+ public String message;
+ public Vector location = new Vector();
- public MessageBodyEntry( string message, string[] location ) {
- Message = message;
- for ( int i = 0; i < location.Length; i++ ) {
- Location.Add( location[i] );
+ public MessageBodyEntry( String message_, String[] location_ ) {
+ message = message_;
+ for ( int i = 0; i < location_.Length; i++ ) {
+ location.add( location_[i] );
}
}
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.AppUtil/Messaging.cs b/trunk/Boare.Lib.AppUtil/Messaging.cs
index 4af6471..f25c690 100644
--- a/trunk/Boare.Lib.AppUtil/Messaging.cs
+++ b/trunk/Boare.Lib.AppUtil/Messaging.cs
@@ -11,109 +11,121 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
+#if JAVA
+package org.kbinani.apputil;
+
+import org.kbinani.*;
+import java.util.*;
+#else
using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Windows.Forms;
+using bocoree;
+using bocoree.java.util;
namespace Boare.Lib.AppUtil {
+#endif
- public static class Messaging {
- private static string s_lang = "";
- private static List s_messages = new List();
+ public class Messaging {
+ private static String s_lang = "";
+ private static Vector s_messages = new Vector();
- public static string[] GetKeys( string lang ) {
- foreach ( MessageBody dict in s_messages ) {
- if ( lang == dict.lang ) {
- List list = new List();
- foreach ( string key in dict.list.Keys ) {
- list.Add( key );
+ public static String[] getKeys( String lang ) {
+ for( Iterator itr = s_messages.iterator(); itr.hasNext(); ){
+ MessageBody dict = (MessageBody)itr.next();
+ if ( lang.Equals( dict.lang ) ) {
+ Vector list = new Vector();
+ for ( Iterator itr2 = dict.list.keySet().iterator(); itr2.hasNext(); ) {
+ String key = (String)itr2.next();
+ list.add( key );
}
- return list.ToArray();
+ return list.toArray( new String[] { } );
}
}
return null;
}
- public static string[] GetRegisteredLanguage() {
- List res = new List();
- foreach ( MessageBody dict in s_messages ) {
- res.Add( dict.lang );
+ public static String[] getRegisteredLanguage() {
+ Vector res = new Vector();
+ for ( Iterator itr = s_messages.iterator(); itr.hasNext(); ) {
+ MessageBody dict = (MessageBody)itr.next();
+ res.add( dict.lang );
}
- return res.ToArray();
+ return res.toArray( new String[] { } );
}
- public static string Language {
- get {
- if ( s_lang != "" ) {
- return s_lang;
- } else {
- s_lang = "en";
- return s_lang;
- }
+ public static String getLanguage() {
+ if ( !s_lang.Equals( "" ) ) {
+ return s_lang;
+ } else {
+ s_lang = "en";
+ return s_lang;
}
- set {
- if ( value != "" ) {
- s_lang = value;
- } else {
- s_lang = "en";
- }
+ }
+
+ public static void setLanguage( String value ) {
+ if ( !value.Equals( "" ) ) {
+ s_lang = value;
+ } else {
+ s_lang = "en";
}
}
///
/// 現在の実行ディレクトリにある言語設定ファイルを全て読込み、メッセージリストに追加します
///
- public static void LoadMessages() {
- LoadMessages( Application.StartupPath );
+ public static void loadMessages() {
+ loadMessages( PortUtil.getApplicationStartupPath() );
}
///
/// 指定されたディレクトリにある言語設定ファイルを全て読込み、メッセージリストに追加します
///
///
- public static void LoadMessages( string directory ) {
- DirectoryInfo current = new DirectoryInfo( directory );
- s_messages.Clear();
+ public static void loadMessages( String directory ) {
+ s_messages.clear();
#if DEBUG
Console.WriteLine( "Messaging+LoadMessages()" );
#endif
- foreach ( FileInfo fi in current.GetFiles( "*.po" ) ) {
- string fname = fi.FullName;
+ String[] files = PortUtil.listFiles( directory, ".po" );
+ for ( int i = 0; i < files.Length; i++ ){
+ String fname = PortUtil.combinePath( directory, files[i] );
#if DEBUG
Console.WriteLine( " fname=" + fname );
#endif
- AppendFromFile( fname );
+ appendFromFile( fname );
}
}
- public static void AppendFromFile( string file ) {
- s_messages.Add( new MessageBody( Path.GetFileNameWithoutExtension( file ), file ) );
+ public static void appendFromFile( String file ) {
+ s_messages.add( new MessageBody( PortUtil.getFileNameWithoutExtension( file ), file ) );
}
- public static MessageBodyEntry GetMessageDetail( string id ) {
- if ( s_lang.Length <= 0 ) {
+ public static MessageBodyEntry getMessageDetail( String id ) {
+ if ( s_lang.Equals( "" ) ) {
s_lang = "en";
}
- foreach ( MessageBody mb in s_messages ) {
- if ( mb.lang == s_lang ) {
- return mb.GetMessageDetail( id );
+ for ( Iterator itr = s_messages.iterator(); itr.hasNext(); ){
+ MessageBody mb = (MessageBody)itr.next();
+ if ( mb.lang.Equals( s_lang ) ) {
+ return mb.getMessageDetail( id );
}
}
- return new MessageBodyEntry( id, new string[] { } );
+ return new MessageBodyEntry( id, new String[] { } );
}
- public static string GetMessage( string id ) {
- if ( s_lang.Length <= 0 ) {
+ public static String getMessage( String id ) {
+ if ( s_lang.Equals( "" ) ) {
s_lang = "en";
}
- foreach ( MessageBody mb in s_messages ) {
- if ( mb.lang == s_lang ) {
- return mb.GetMessage( id );
+ for ( Iterator itr = s_messages.iterator(); itr.hasNext(); ){
+ MessageBody mb = (MessageBody)itr.next();
+ if ( mb.lang.Equals( s_lang ) ) {
+ return mb.getMessage( id );
}
}
return id;
}
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.AppUtil/Misc.cs b/trunk/Boare.Lib.AppUtil/Misc.cs
index 28d1e40..7d62d46 100644
--- a/trunk/Boare.Lib.AppUtil/Misc.cs
+++ b/trunk/Boare.Lib.AppUtil/Misc.cs
@@ -21,7 +21,7 @@ using System.Windows.Forms;
namespace Boare.Lib.AppUtil {
- public static partial class Misc {
+ public static partial class Util {
public static void ApplyContextMenuFontRecurse( ContextMenuStrip item, Font font ) {
item.Font = font;
foreach ( ToolStripItem tsi in item.Items ) {
diff --git a/trunk/Boare.Lib.AppUtil/VersionInfo.Designer.cs b/trunk/Boare.Lib.AppUtil/VersionInfo.Designer.cs
index dcd0c91..65671bd 100644
--- a/trunk/Boare.Lib.AppUtil/VersionInfo.Designer.cs
+++ b/trunk/Boare.Lib.AppUtil/VersionInfo.Designer.cs
@@ -115,10 +115,10 @@ namespace Boare.Lib.AppUtil {
public void ApplyLanguage() {
string about = string.Format( _( "About {0}" ), m_app_name );
string credit = _( "Credit" );
- Size size1 = Misc.MeasureString( about, btnFlip.Font );
- Size size2 = Misc.MeasureString( credit, btnFlip.Font );
- m_button_width_about = Math.Max( 75, (int)(size1.Width * 1.3) );
- m_button_width_credit = Math.Max( 75, (int)(size2.Width * 1.3) );
+ bocoree.java.awt.Dimension size1 = Util.measureString( about, new bocoree.java.awt.Font( btnFlip.Font ) );
+ bocoree.java.awt.Dimension size2 = Util.measureString( credit, new bocoree.java.awt.Font( btnFlip.Font ) );
+ m_button_width_about = Math.Max( 75, (int)(size1.width * 1.3) );
+ m_button_width_credit = Math.Max( 75, (int)(size2.width * 1.3) );
if( m_credit_mode ) {
btnFlip.Width = m_button_width_about;
btnFlip.Text = about;
diff --git a/trunk/Boare.Lib.AppUtil/VersionInfo.cs b/trunk/Boare.Lib.AppUtil/VersionInfo.cs
index e1af10a..b89ef76 100644
--- a/trunk/Boare.Lib.AppUtil/VersionInfo.cs
+++ b/trunk/Boare.Lib.AppUtil/VersionInfo.cs
@@ -1,4 +1,5 @@
-/*
+#if !JAVA
+/*
* VersionInfo.cs
* Copyright (c) 2008-2009 kbinani
*
@@ -12,13 +13,19 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System;
-using System.Drawing;
-using System.Drawing.Drawing2D;
-using System.Windows.Forms;
+//using System.Drawing;
+//using System.Drawing.Drawing2D;
+//using System.Windows.Forms;
+using bocoree;
+using bocoree.java.awt;
+using bocoree.java.awt.image;
namespace Boare.Lib.AppUtil {
+ using java = bocoree.java;
+ using javax = bocoree.javax;
+ using Graphics = bocoree.java.awt.Graphics2D;
- public partial class VersionInfo : Form {
+ public partial class VersionInfo : System.Windows.Forms.Form {
DateTime m_scroll_started;
private AuthorListEntry[] m_credit;
const float m_speed = 35f;
@@ -29,12 +36,12 @@ namespace Boare.Lib.AppUtil {
float m_shift = 0f;
int m_button_width_about = 75;
int m_button_width_credit = 75;
- Bitmap m_scroll;
+ BufferedImage m_scroll;
const int m_height = 380;
- readonly Color m_background = Color.White;
+ readonly Color m_background = Color.white;
private string m_app_name = "";
- private Color m_app_name_color = Color.Black;
- private Color m_version_color = Color.FromArgb( 105, 105, 105 );
+ private Color m_app_name_color = Color.black;
+ private Color m_version_color = new Color( 105, 105, 105 );
private bool m_shadow_enablde = true;
public VersionInfo( string app_name, string version ) {
@@ -43,9 +50,9 @@ namespace Boare.Lib.AppUtil {
InitializeComponent();
ApplyLanguage();
- this.SetStyle( ControlStyles.DoubleBuffer, true );
- this.SetStyle( ControlStyles.UserPaint, true );
- this.SetStyle( ControlStyles.AllPaintingInWmPaint, true );
+ this.SetStyle( System.Windows.Forms.ControlStyles.DoubleBuffer, true );
+ this.SetStyle( System.Windows.Forms.ControlStyles.UserPaint, true );
+ this.SetStyle( System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true );
m_credit = new AuthorListEntry[] { };
btnSaveAuthorList.Visible = false;
@@ -63,7 +70,7 @@ namespace Boare.Lib.AppUtil {
}
public static string _( string s ) {
- return Messaging.GetMessage( s );
+ return Messaging.getMessage( s );
}
///
@@ -90,7 +97,7 @@ namespace Boare.Lib.AppUtil {
}
}
- public Bitmap Credit {
+ public BufferedImage Credit {
set {
m_scroll = value;
}
@@ -118,55 +125,44 @@ namespace Boare.Lib.AppUtil {
const float shadow_shift = 2f;
const string font_name = "Arial";
const int font_size = 10;
- Font font = new Font( font_name, font_size );
- Size size = Boare.Lib.AppUtil.Misc.MeasureString( "Qjqp", font );
+ Font font = new Font( font_name, java.awt.Font.PLAIN, font_size );
+ Dimension size = Boare.Lib.AppUtil.Util.measureString( "Qjqp", font );
float width = this.Width;
- float height = size.Height;
- StringFormat sf = new StringFormat();
- m_scroll = new Bitmap( (int)width, (int)(40f + m_credit.Length * height * 1.1f) );
- using ( Graphics g = Graphics.FromImage( m_scroll ) ) {
- sf.Alignment = StringAlignment.Center;
+ float height = size.height;
+ //StringFormat sf = new StringFormat();
+ m_scroll = new BufferedImage( (int)width, (int)(40f + m_credit.Length * height * 1.1f), BufferedImage.TYPE_INT_BGR );
+ Graphics2D g = m_scroll.createGraphics();
+ //sf.Alignment = StringAlignment.Center;
+ g.setFont( new Font( font_name, java.awt.Font.BOLD, (int)(font_size * 1.1f) ) );
+ if ( m_shadow_enablde ) {
+ g.setColor( new Color( 0, 0, 0, 40 ) );
+ g.drawString( m_app_name, shadow_shift, shadow_shift ); //, width, height ), sf );
+ }
+ g.setColor( Color.black );
+ g.drawString( m_app_name, 0f, 0f ); //, width, height ), sf );
+ for ( int i = 0; i < m_credit.Length; i++ ) {
+ g.setFont( new Font( font_name, m_credit[i].getStyle(), font_size ) );
if ( m_shadow_enablde ) {
- g.DrawString( m_app_name,
- new Font( font_name, (int)(font_size * 1.1f), FontStyle.Bold ),
- new SolidBrush( Color.FromArgb( 40, Color.Black ) ),
- new RectangleF( shadow_shift, shadow_shift, width, height ),
- sf );
- }
- g.DrawString( m_app_name,
- new Font( font_name, (int)(font_size * 1.1f), FontStyle.Bold ),
- Brushes.Black,
- new RectangleF( 0f, 0f, width, height ),
- sf );
- for ( int i = 0; i < m_credit.Length; i++ ) {
- if ( m_shadow_enablde ) {
- g.DrawString( m_credit[i].Name,
- new Font( font_name, font_size, m_credit[i].Style ),
- new SolidBrush( Color.FromArgb( 40, Color.Black ) ),
- new RectangleF( 0f + shadow_shift, 40f + i * height * 1.1f + shadow_shift, width, height ),
- sf );
- }
- g.DrawString( m_credit[i].Name,
- new Font( font_name, font_size, m_credit[i].Style ),
- Brushes.Black,
- new RectangleF( 0f, 40f + i * height * 1.1f, width, height ),
- sf );
+ g.setColor( new Color( 0, 0, 0, 40 ) );
+ g.drawString( m_credit[i].getName(), 0f + shadow_shift, 40f + i * height * 1.1f + shadow_shift ); //, width, height ), sf );
}
+ g.setColor( Color.black );
+ g.drawString( m_credit[i].getName(), 0f, 40f + i * height * 1.1f );// , width, height ), sf );
}
}
void btnSaveAuthorList_Click( object sender, EventArgs e ) {
#if DEBUG
- using ( SaveFileDialog dlg = new SaveFileDialog() ){
- if( dlg.ShowDialog() == DialogResult.OK ){
- m_scroll.Save( dlg.FileName, System.Drawing.Imaging.ImageFormat.Png );
+ using ( System.Windows.Forms.SaveFileDialog dlg = new System.Windows.Forms.SaveFileDialog() ){
+ if( dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK ){
+ javax.imageio.ImageIO.write( m_scroll, "png", new java.io.File( dlg.FileName ) );
}
}
#endif
}
private void btnOK_Click( object sender, EventArgs e ) {
- this.DialogResult = DialogResult.OK;
+ this.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
}
@@ -193,50 +189,9 @@ namespace Boare.Lib.AppUtil {
this.Invalidate();
}
- private void VersionInfoEx_Paint( object sender, PaintEventArgs e ) {
+ private void VersionInfoEx_Paint( object sender, System.Windows.Forms.PaintEventArgs e ) {
try {
- Graphics g = e.Graphics;
- g.Clip = new Region( new Rectangle( 0, 0, this.Width, m_height ) );
- g.Clear( m_background );
- if ( m_credit_mode ) {
- float times = (float)(((DateTime.Now).Subtract( m_scroll_started )).TotalSeconds) - 3f;
- float speed = (float)((2.0 - bocoree.math.erfcc( times * 0.8 )) / 2.0) * m_speed;
- float dt = times - m_last_t;
- m_shift += (speed + m_last_speed) * dt / 2f;
- m_last_t = times;
- m_last_speed = speed;
- float dx = (this.Width - m_scroll.Width) * 0.5f;
- if ( m_scroll != null ) {
- g.DrawImage( m_scroll,
- dx, 90f - m_shift,
- m_scroll.Width, m_scroll.Height );
- if ( 90f - m_shift + m_scroll.Height < 0 ) {
- m_shift = -m_height * 1.5f;
- }
- }
- int grad_height = 60;
- Rectangle top = new Rectangle( 0, 0, this.Width, grad_height );
- using ( LinearGradientBrush lgb = new LinearGradientBrush( top, Color.White, Color.Transparent, LinearGradientMode.Vertical ) ) {
- g.FillRectangle( lgb, top );
- }
- Rectangle bottom = new Rectangle( 0, m_height - grad_height, this.Width, grad_height );
- g.Clip = new Region( new Rectangle( 0, m_height - grad_height + 1, this.Width, grad_height - 1 ) );
- using ( LinearGradientBrush lgb = new LinearGradientBrush( bottom, Color.Transparent, Color.White, LinearGradientMode.Vertical ) ) {
- g.FillRectangle( lgb, bottom );
- }
- g.ResetClip();
- } else {
- g.DrawString(
- m_app_name,
- new Font( "Century Gorhic", 24, FontStyle.Bold ),
- new SolidBrush( m_app_name_color ),
- new PointF( 20, 110 ) );
- g.DrawString(
- "version " + m_version,
- new Font( "Arial", 10 ),
- new SolidBrush( m_version_color ),
- new PointF( 25, 150 ) );
- }
+ paint( new Graphics2D( e.Graphics ) );
} catch ( Exception ex ) {
#if DEBUG
Console.WriteLine( "VersionInfoEx_Paint" );
@@ -245,19 +200,57 @@ namespace Boare.Lib.AppUtil {
}
}
- private void VersionInfoEx_KeyDown( object sender, KeyEventArgs e ) {
- if ( (e.KeyCode & Keys.Escape) == Keys.Escape ) {
- this.DialogResult = DialogResult.Cancel;
+ public void paint( Graphics g1 ) {
+ Graphics2D g = (Graphics2D)g1;
+ g.clipRect( 0, 0, this.Width, m_height );
+ g.clearRect( 0, 0, this.Width, this.Height );
+ if ( m_credit_mode ) {
+ float times = (float)(((DateTime.Now).Subtract( m_scroll_started )).TotalSeconds) - 3f;
+ float speed = (float)((2.0 - bocoree.math.erfcc( times * 0.8 )) / 2.0) * m_speed;
+ float dt = times - m_last_t;
+ m_shift += (speed + m_last_speed) * dt / 2f;
+ m_last_t = times;
+ m_last_speed = speed;
+ float dx = (this.Width - m_scroll.getWidth( null )) * 0.5f;
+ if ( m_scroll != null ) {
+ g.drawImage( m_scroll, (int)dx, (int)(90f - m_shift), null );
+ if ( 90f - m_shift + m_scroll.getHeight( null ) < 0 ) {
+ m_shift = -m_height * 1.5f;
+ }
+ }
+ int grad_height = 60;
+ Rectangle top = new Rectangle( 0, 0, this.Width, grad_height );
+ /*using ( LinearGradientBrush lgb = new LinearGradientBrush( top, Color.White, Color.Transparent, LinearGradientMode.Vertical ) ) {
+ g.FillRectangle( lgb, top );
+ }*/
+ Rectangle bottom = new Rectangle( 0, m_height - grad_height, this.Width, grad_height );
+ g.clipRect( 0, m_height - grad_height + 1, this.Width, grad_height - 1 );
+ /*using ( LinearGradientBrush lgb = new LinearGradientBrush( bottom, Color.Transparent, Color.White, LinearGradientMode.Vertical ) ) {
+ g.FillRectangle( lgb, bottom );
+ }*/
+ g.setClip( null );
+ } else {
+ g.setFont( new Font( "Century Gorhic", java.awt.Font.BOLD, 24 ) );
+ g.setColor( m_app_name_color );
+ g.drawString( m_app_name, 20, 110 );
+ g.setFont( new Font( "Arial", 0, 10 ) );
+ g.drawString( "version " + m_version, 25, 150 );
+ }
+ }
+
+ private void VersionInfoEx_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e ) {
+ if ( (e.KeyCode & System.Windows.Forms.Keys.Escape) == System.Windows.Forms.Keys.Escape ) {
+ this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.Close();
}
}
private void VersionInfoEx_FontChanged( object sender, EventArgs e ) {
- Font font = this.Font;
for ( int i = 0; i < this.Controls.Count; i++ ) {
- Misc.ApplyFontRecurse( this.Controls[i], font );
+ Util.applyFontRecurse( this.Controls[i], new java.awt.Font( this.Font ) );
}
}
}
}
+#endif
diff --git a/trunk/Boare.Lib.Media/AviReader.cs b/trunk/Boare.Lib.Media/AviReader.cs
index 05312a6..7af83c4 100644
--- a/trunk/Boare.Lib.Media/AviReader.cs
+++ b/trunk/Boare.Lib.Media/AviReader.cs
@@ -82,7 +82,7 @@ namespace Boare.Lib.Media {
//Open the file
int result = VFW.AVIFileOpenW(
ref aviFile, fileName,
- (int)windows.OF_SHARE_DENY_WRITE, 0 );
+ (int)win32.OF_SHARE_DENY_WRITE, 0 );
if ( result != 0 ) {
throw new Exception( "Exception in AVIFileOpen: " + result.ToString() );
diff --git a/trunk/Boare.Lib.Media/BSoundPlayer.cs b/trunk/Boare.Lib.Media/BSoundPlayer.cs
new file mode 100644
index 0000000..232e531
--- /dev/null
+++ b/trunk/Boare.Lib.Media/BSoundPlayer.cs
@@ -0,0 +1,131 @@
+#if JAVA
+package org.kbinani.media;
+
+import java.io.*;
+import javax.sound.sampled.*;
+
+public class BSoundPlayer{
+ private static final int BUFLEN = 128000;
+ private AudioInputStream m_stream = null;
+ private boolean m_stop_required = false;
+ private boolean m_playing = false;
+ private String m_sound_location = "";
+
+ public BSoundPlayer( String sound_location ){
+ setSoundLocation( sound_location );
+ }
+
+ public BSoundPlayer(){
+ }
+
+ public String getSoundLocation(){
+ return m_sound_location;
+ }
+
+ public void setSoundLocation( String value ){
+ stop();
+ m_sound_location = value;
+ if( m_stream != null ){
+ try{
+ m_stream.close();
+ }catch( Exception ex0 ){
+ System.err.println( "BSoundPlayer#setSoundLocation; ex0=" + ex0 );
+ }
+ }
+ try {
+ File sound_file = new File( m_sound_location );
+ m_stream = AudioSystem.getAudioInputStream( sound_file );
+ }catch( Exception ex ){
+ System.err.println( "BSoundPlayer#.ctor; ex=" + ex );
+ }
+ }
+
+ public void play(){
+ try{
+ Thread t = new Thread( new PlaySoundRunner() );
+ t.start();
+ t.join();
+ }catch( Exception ex ){
+ System.out.println( "BSoundPlayer#play; ex=" + ex );
+ }
+ }
+
+ public void stop(){
+ if( m_playing ){
+ try{
+ m_stop_required = true;
+ while( m_playing ){
+ Thread.sleep( 0 );
+ }
+ m_stop_required = false;
+ }catch( Exception ex ){
+ System.err.println( "BSoundPlayer#stop; ex=" + ex );
+ }
+ }
+ }
+
+ public class PlaySoundRunner implements Runnable{
+ public void run(){
+ SourceDataLine line = null;
+ m_playing = true;
+ try{
+ AudioFormat audioFormat = m_stream.getFormat();
+
+ DataLine.Info info = new DataLine.Info( SourceDataLine.class, audioFormat );
+ line = (SourceDataLine)AudioSystem.getLine( info );
+ line.open( audioFormat );
+ line.start();
+
+ int len = 1;
+ byte[] buf = new byte[BUFLEN];
+ while( len > 0 && !m_stop_required ){
+ len = m_stream.read( buf, 0, buf.length );
+ if( len >= 0 ){
+ int nBytesWritten = line.write( buf, 0, len );
+ }else{
+ break;
+ }
+ }
+ } catch( Exception ex ){
+ System.err.println( "BSoundPlayer.PlaySoundRunner#run; ex=" + ex );
+ } finally {
+ if( line != null ){
+ try{
+ line.drain();
+ line.close();
+ }catch( Exception ex2 ){
+ System.err.println( "BSoundPlayer.PlaySoundRunner#run; ex2=" + ex2 );
+ }
+ }
+ }
+ m_playing = false;
+ }
+ }
+}
+#else
+namespace Boare.Lib.Media {
+
+ public class BSoundPlayer : System.Media.SoundPlayer {
+ public BSoundPlayer( string sound_location )
+ : base( sound_location ) {
+ }
+
+ public BSoundPlayer()
+ : base() {
+ }
+
+ public void play() {
+ base.Play();
+ }
+
+ public string getSoundLocation() {
+ return base.SoundLocation;
+ }
+
+ public void setSoundLocation( string value ) {
+ base.SoundLocation = value;
+ }
+ }
+
+}
+#endif
diff --git a/trunk/Boare.Lib.Media/Boare.Lib.Media.csproj b/trunk/Boare.Lib.Media/Boare.Lib.Media.csproj
index 9e0ac18..d19e9bb 100644
--- a/trunk/Boare.Lib.Media/Boare.Lib.Media.csproj
+++ b/trunk/Boare.Lib.Media/Boare.Lib.Media.csproj
@@ -2,7 +2,7 @@
Debug
AnyCPU
- 9.0.21022
+ 9.0.30729
2.0
{F4F8F601-4E3D-43F5-A8A8-AA1FB7F48452}
Library
@@ -63,6 +63,9 @@
+
+ Component
+
diff --git a/trunk/Boare.Lib.Media/MediaPlayer.cs b/trunk/Boare.Lib.Media/MediaPlayer.cs
index fd20f96..a11314f 100644
--- a/trunk/Boare.Lib.Media/MediaPlayer.cs
+++ b/trunk/Boare.Lib.Media/MediaPlayer.cs
@@ -229,7 +229,7 @@ namespace Boare.Lib.Media {
Close();
}
this.m_filename = filename;
- m_alias = bocoree.misc.getmd5( m_filename );
+ m_alias = bocoree.Misc.getmd5( m_filename );
#if DEBUG
Console.WriteLine( " m_alias=" + m_alias );
#endif
diff --git a/trunk/Boare.Lib.Media/MidiInDevice.cs b/trunk/Boare.Lib.Media/MidiInDevice.cs
index aca1e56..d86458e 100644
--- a/trunk/Boare.Lib.Media/MidiInDevice.cs
+++ b/trunk/Boare.Lib.Media/MidiInDevice.cs
@@ -11,15 +11,21 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
-using System;
-using System.Runtime.InteropServices;
-using System.Collections.Generic;
+#if JAVA
+package org.kbinani.media;
+public class MidiInDevice{
+
+}
+#else
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
using bocoree;
namespace Boare.Lib.Media {
- public delegate void MidiReceivedEventHandler( DateTime time, byte[] data );
+ public delegate void MidiReceivedEventHandler( double time, byte[] data );
public class MidiInDevice : IDisposable {
delegate void MidiInProcDelegate( uint hMidiIn, uint wMsg, int dwInstance, int dwParam1, int dwParam2 );
@@ -35,13 +41,13 @@ namespace Boare.Lib.Media {
m_port_number = port_number;
m_delegate = new MidiInProcDelegate( MidiInProc );
m_delegate_pointer = Marshal.GetFunctionPointerForDelegate( m_delegate );
- windows.midiInOpen( ref m_hmidiin, port_number, m_delegate_pointer, 0, windows.CALLBACK_FUNCTION );
+ win32.midiInOpen( ref m_hmidiin, port_number, m_delegate_pointer, 0, win32.CALLBACK_FUNCTION );
}
public void Start() {
if ( m_hmidiin > 0 ) {
try {
- windows.midiInStart( m_hmidiin );
+ win32.midiInStart( m_hmidiin );
} catch ( Exception ex ) {
debug.push_log( "MidiInDevice.Start" );
debug.push_log( " ex=" + ex );
@@ -52,7 +58,7 @@ namespace Boare.Lib.Media {
public void Stop() {
if ( m_hmidiin > 0 ) {
try {
- windows.midiInReset( m_hmidiin );
+ win32.midiInReset( m_hmidiin );
} catch ( Exception ex ) {
debug.push_log( "MidiInDevice.Stop" );
debug.push_log( " ex=" + ex );
@@ -63,7 +69,7 @@ namespace Boare.Lib.Media {
public void Close() {
if ( m_hmidiin > 0 ) {
try {
- windows.midiInClose( m_hmidiin );
+ win32.midiInClose( m_hmidiin );
} catch ( Exception ex ) {
debug.push_log( "MidiInDevice.Close" );
debug.push_log( " ex=" + ex );
@@ -78,7 +84,7 @@ namespace Boare.Lib.Media {
public static int GetNumDevs() {
try {
- int i = (int)windows.midiInGetNumDevs();
+ int i = (int)win32.midiInGetNumDevs();
return i;
} catch ( Exception ex ) {
debug.push_log( "MidiInDevice.GetNumDevs" );
@@ -91,13 +97,13 @@ namespace Boare.Lib.Media {
List ret = new List();
uint num = 0;
try {
- num = windows.midiInGetNumDevs();
+ num = win32.midiInGetNumDevs();
} catch {
num = 0;
}
for ( uint i = 0; i < num; i++ ) {
MIDIINCAPS m = new MIDIINCAPS();
- uint r = windows.midiInGetDevCaps( i, ref m, (uint)Marshal.SizeOf( m ) );
+ uint r = win32.midiInGetDevCaps( i, ref m, (uint)Marshal.SizeOf( m ) );
ret.Add( m );
}
return ret.ToArray();
@@ -106,13 +112,13 @@ namespace Boare.Lib.Media {
public void MidiInProc( uint hMidiIn, uint wMsg, int dwInstance, int dwParam1, int dwParam2 ) {
try {
switch ( wMsg ) {
- case windows.MM_MIM_OPEN:
+ case win32.MM_MIM_OPEN:
return;
- case windows.MM_MIM_CLOSE:
+ case win32.MM_MIM_CLOSE:
return;
- case windows.MM_MIM_DATA:
+ case win32.MM_MIM_DATA:
int receive = dwParam1;
- DateTime now = DateTime.Now;
+ double now = PortUtil.getCurrentTime();
switch ( receive & 0xF0 ) {
case 0x80:
case 0x90:
@@ -134,11 +140,11 @@ namespace Boare.Lib.Media {
break;
}
return;
- case windows.MM_MIM_LONGDATA:
+ case win32.MM_MIM_LONGDATA:
return;
- case windows.MM_MIM_ERROR:
+ case win32.MM_MIM_ERROR:
return;
- case windows.MM_MIM_LONGERROR:
+ case win32.MM_MIM_LONGERROR:
return;
}
} catch ( Exception ex ) {
@@ -149,3 +155,4 @@ namespace Boare.Lib.Media {
}
}
+#endif
diff --git a/trunk/Boare.Lib.Media/MidiOutDevice.cs b/trunk/Boare.Lib.Media/MidiOutDevice.cs
index a57c84f..705526c 100644
--- a/trunk/Boare.Lib.Media/MidiOutDevice.cs
+++ b/trunk/Boare.Lib.Media/MidiOutDevice.cs
@@ -25,12 +25,12 @@ namespace Boare.Lib.Media {
public MidiOutDevice( uint device_id ) {
m_device_id = device_id;
- windows.midiOutOpen( ref m_handle, m_device_id, null, 0, windows.CALLBACK_NULL );
+ win32.midiOutOpen( ref m_handle, m_device_id, null, 0, win32.CALLBACK_NULL );
}
public void Close() {
if ( !m_handle.Equals( IntPtr.Zero ) ) {
- windows.midiOutClose( m_handle );
+ win32.midiOutClose( m_handle );
}
}
@@ -55,7 +55,7 @@ namespace Boare.Lib.Media {
for ( int i = 0; i < data.Length; i++ ) {
message |= ((uint)data[i]) << (i * 8);
}
- windows.midiOutShortMsg( m_handle, message );
+ win32.midiOutShortMsg( m_handle, message );
}
private void SendLong( byte[] data ) {
@@ -66,15 +66,15 @@ namespace Boare.Lib.Media {
hdr.lpData = (byte*)dataHandle.AddrOfPinnedObject().ToPointer();
hdr.dwBufferLength = (uint)data.Length;
hdr.dwFlags = 0;
- windows.midiOutPrepareHeader( m_handle, ref hdr, size );
- while ( (hdr.dwFlags & windows.WHDR_PREPARED) != windows.WHDR_PREPARED ) {
+ win32.midiOutPrepareHeader( m_handle, ref hdr, size );
+ while ( (hdr.dwFlags & win32.WHDR_PREPARED) != win32.WHDR_PREPARED ) {
Application.DoEvents();
}
- windows.midiOutLongMsg( m_handle, ref hdr, size );
- while ( (hdr.dwFlags & windows.WHDR_DONE) != windows.WHDR_DONE ) {
+ win32.midiOutLongMsg( m_handle, ref hdr, size );
+ while ( (hdr.dwFlags & win32.WHDR_DONE) != win32.WHDR_DONE ) {
Application.DoEvents();
}
- windows.midiOutUnprepareHeader( m_handle, ref hdr, size );
+ win32.midiOutUnprepareHeader( m_handle, ref hdr, size );
} finally {
dataHandle.Free();
}
diff --git a/trunk/Boare.Lib.Media/Wave.cs b/trunk/Boare.Lib.Media/Wave.cs
index 5de0197..6fdbe00 100644
--- a/trunk/Boare.Lib.Media/Wave.cs
+++ b/trunk/Boare.Lib.Media/Wave.cs
@@ -11,24 +11,22 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
-using System;
-using System.IO;
-using System.Collections.Generic;
+#if JAVA
+package org.kbinani.media;
+import java.io.*;
+import org.kbinani.*;
+#else
+using System;
+using System.Collections.Generic;
using bocoree;
+using bocoree.java.io;
namespace Boare.Lib.Media {
+ using boolean = System.Boolean;
+#endif
- public enum Channel {
- Right,
- Left,
- }
-
- public enum WaveChannel : int {
- Monoral = 1,
- Stereo = 2
- }
-
+#if !JAVA
///
/// Parameters of first formanto detection algorithm
///
@@ -62,21 +60,37 @@ namespace Boare.Lib.Media {
}
}
}
+#endif
+
+#if JAVA
+ public class Wave
+#else
+ public class Wave : IDisposable
+#endif
+ {
+ public enum Channel {
+ Right,
+ Left,
+ }
+
+ public enum WaveChannel {
+ Monoral,
+ Stereo
+ }
- public class Wave : IDisposable {
private WaveChannel m_channel;
- private ushort m_bit_per_sample;
- private uint m_sample_rate;
- private uint m_total_samples;
+ private int m_bit_per_sample;
+ private long m_sample_rate;
+ private long m_total_samples;
private byte[] L8;
private byte[] R8;
private short[] L16;
private short[] R16;
- //public void
+#if !JAVA
#if DEBUG
- private static bool s_test = false;
- public static bool TestEnabled {
+ private static boolean s_test = false;
+ public static boolean TestEnabled {
get {
return s_test;
}
@@ -85,14 +99,28 @@ namespace Boare.Lib.Media {
}
}
#endif
+#endif
+
+#if !JAVA
public unsafe double TEST_GetF0( uint time, double[] window_function ) {
int window_size = window_function.Length;
double[] formanto = GetFormanto( time, window_function );
#if DEBUG
if ( s_test ) {
- using ( StreamWriter sw = new StreamWriter( @"C:\TEST_GetF0_formanto.txt" ) ) {
+ BufferedWriter sw = null;
+ try {
+ sw = new BufferedWriter( new FileWriter( @"C:\TEST_GetF0_formanto.txt" ) );
for ( int i = 0; i < formanto.Length; i++ ) {
- sw.WriteLine( Math.Abs( formanto[i] ) );
+ sw.write( Math.Abs( formanto[i] ) + "" );
+ sw.newLine();
+ }
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sw != null ) {
+ try {
+ sw.close();
+ } catch ( Exception ex2 ) {
+ }
}
}
}
@@ -114,27 +142,42 @@ namespace Boare.Lib.Media {
}
#if DEBUG
if ( s_test ) {
- using ( StreamWriter sw = new StreamWriter( @"C:\TEST_GetF0_fft_formanto.txt" ) ) {
+ BufferedWriter sw = null;
+ try {
+ sw = new BufferedWriter( new FileWriter( @"C:\TEST_GetF0_fft_formanto.txt" ) );
for ( int i = 0; i < wv.Length; i++ ) {
- sw.WriteLine( Math.Abs( wv[i] ) );
+ sw.write( Math.Abs( wv[i] ) + "" );
+ sw.newLine();
+ }
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sw != null ) {
+ try {
+ sw.close();
+ } catch {
+ }
}
}
}
#endif
return 0;
}
+#endif
+#if !JAVA
public double GetF0( uint time, double[] window_function ) {
return GetF0( time, window_function, new FormantoDetectionArguments() );
}
+#endif
+#if !JAVA
///
/// 第timeサンプルにおけるフォルマントを取得する
///
///
///
///
- public double GetF0( uint time, double[] window_function, FormantoDetectionArguments argument ) {
+ public double GetF0( uint time, double[] window_function, FormantoDetectionArguments argument ) {
int window_size = window_function.Length;
double[] formanto = GetFormanto( time, window_function );
int length = formanto.Length;
@@ -152,9 +195,20 @@ namespace Boare.Lib.Media {
#if DEBUG
Console.WriteLine( "Wave+GetF0" );
if ( s_test ) {
- using ( StreamWriter sw = new StreamWriter( "formanto.txt" ) ) {
+ BufferedWriter sw = null;
+ try {
+ sw = new BufferedWriter( new FileWriter( "formanto.txt" ) );
for ( int i = 0; i < length; i++ ) {
- sw.WriteLine( (i * hz_from_index) + "\t" + formanto[i] );
+ sw.write( (i * hz_from_index) + "\t" + formanto[i] );
+ sw.newLine();
+ }
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sw != null ) {
+ try {
+ sw.close();
+ } catch ( Exception ex2 ) {
+ }
}
}
}
@@ -182,9 +236,20 @@ namespace Boare.Lib.Media {
}
#if DEBUG
if ( s_test ) {
- using ( StreamWriter sw = new StreamWriter( "ma.txt" ) ) {
+ BufferedWriter sw = null;
+ try {
+ sw = new BufferedWriter( new FileWriter( "ma.txt" ) );
for ( int i = 0; i < length; i++ ) {
- sw.WriteLine( (i * hz_from_index) + "\t" + ma[i] );
+ sw.write( (i * hz_from_index) + "\t" + ma[i] );
+ sw.newLine();
+ }
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sw != null ) {
+ try {
+ sw.close();
+ } catch ( Exception ex2 ) {
+ }
}
}
}
@@ -194,7 +259,7 @@ namespace Boare.Lib.Media {
double last_slope = 0.0;
int index = -1;
List peak_positions = new List();
- bool first = true;
+ boolean first = true;
for ( int i = 1; i < window_size - 1; i++ ) {
double slope = ma[i + 1] - ma[i - 1];
if ( ma[i] > threshold && slope <= 0.0 && 0.0 < last_slope ) {
@@ -209,9 +274,20 @@ namespace Boare.Lib.Media {
}
#if DEBUG
if ( s_test ) {
- using ( StreamWriter sw = new StreamWriter( "peak_positions.txt" ) ) {
+ BufferedWriter sw = null;
+ try {
+ sw = new BufferedWriter( new FileWriter( "peak_positions.txt" ) );
for ( int i = 0; i < peak_positions.Count; i++ ) {
- sw.WriteLine( peak_positions[i].ToString() );
+ sw.write( peak_positions[i].ToString() );
+ sw.newLine();
+ }
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sw != null ) {
+ try {
+ sw.close();
+ } catch ( Exception ex2 ) {
+ }
}
}
}
@@ -229,9 +305,20 @@ namespace Boare.Lib.Media {
}
#if DEBUG
if ( s_test ) {
- using ( StreamWriter sw = new StreamWriter( "peaks.txt" ) ) {
+ BufferedWriter sw = null;
+ try {
+ sw = new BufferedWriter( new FileWriter( "peaks.txt" ) );
for ( int i = 0; i < peaks.Count; i++ ) {
- sw.WriteLine( peaks[i] );
+ sw.write( peaks[i] + "" );
+ sw.newLine();
+ }
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sw != null ) {
+ try {
+ sw.close();
+ } catch ( Exception ex2 ) {
+ }
}
}
}
@@ -243,9 +330,20 @@ namespace Boare.Lib.Media {
#if DEBUG
Console.WriteLine( "min_peak_distance=" + min_peak_distance );
if ( s_test ) {
- using ( StreamWriter sw = new StreamWriter( "evaluation.txt" ) ) {
+ BufferedWriter sw = null;
+ try {
+ sw = new BufferedWriter( new FileWriter( "evaluation.txt" ) );
for ( int i = (int)min_peak_distance; i < (int)(4 * min_peak_distance); i++ ) {
- sw.WriteLine( i + "\t" + GetFormantoGetEvaluationValue( peaks, i ) );
+ sw.write( i + "\t" + GetFormantoGetEvaluationValue( peaks, i ) );
+ sw.newLine();
+ }
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sw != null ) {
+ try {
+ sw.close();
+ } catch ( Exception ex2 ) {
+ }
}
}
}
@@ -264,7 +362,9 @@ namespace Boare.Lib.Media {
return 0;
}
}
+#endif
+#if !JAVA
private static double GetFormantoGetEvaluationValue( List peaks, double t ) {
double ret = 0.0;
for ( int i = 0; i < peaks.Count; i++ ) {
@@ -274,36 +374,9 @@ namespace Boare.Lib.Media {
}
return ret / t;
}
+#endif
- /*public unsafe double[,] GetFormanto( uint time, uint count, double[] window_function ) {
- int size = window_function.Length;
- double[] buffer = new double[size]; // 波形のバッファ
- int nmaxsqrt = (int)Math.Sqrt( size );
- int[] ip_ = new int[nmaxsqrt + 2];
- double[] w_ = new double[size * 5 / 4];
- ip_[0] = 0;
-
- double[,] ret = new double[count, size];
-
- for ( uint j = time; j < time + count; j++ ) {
- GetNormalizedWave( (uint)(time - size / 2), ref buffer );
- // 窓関数をかける
- for ( int i = 0; i < size; i++ ) {
- buffer[i] *= window_function[i];
- }
-
- fixed ( int* ip = &ip_[0] )
- fixed ( double* w = &w_[0] )
- fixed ( double* a = &buffer[0] ) {
- fft.rdft( size, 1, a, ip, w );
- }
- for ( int i = 0; i < size; i++ ) {
- ret[j - time, i] = buffer[i];
- }
- }
- return ret;
- }*/
-
+#if !JAVA
///
/// 第timeサンプルにおけるフォルマントを取得する
///
@@ -312,7 +385,7 @@ namespace Boare.Lib.Media {
///
public unsafe double[] GetFormanto( uint time, double[] window_function ) {
int size = window_function.Length;
- double[] wv = GetNormalizedWave( (int)(time - size / 2), (uint)(size + 1) );
+ double[] wv = getNormalizedWave( (int)(time - size / 2), (uint)(size + 1) );
// 窓関数をかける
for ( int i = 0; i < size; i++ ) {
wv[i] = wv[i] * window_function[i];
@@ -329,20 +402,22 @@ namespace Boare.Lib.Media {
}
return wv;
}
+#endif
-
+#if !JAVA
public double GetVolume( int start_sample, double[] window_function ) {
int window_size = window_function.Length;
double[] conv = new double[window_size];
- GetNormalizedWave( start_sample - window_size / 2, ref conv );
+ getNormalizedWave( start_sample - window_size / 2, conv );
double ret = 0.0;
for ( int i = 0; i < window_size; i++ ) {
ret += Math.Abs( conv[i] ) * window_function[i];
}
return ret / (double)window_size;
}
+#endif
-
+#if !JAVA
///
/// 指定したサンプル位置における音量を計算します
///
@@ -352,7 +427,7 @@ namespace Boare.Lib.Media {
///
public double GetVolume( int start_sample, int window_size, math.WindowFunctionType window_function_type ) {
double[] conv = new double[window_size];
- GetNormalizedWave( start_sample - window_size / 2, ref conv );
+ getNormalizedWave( start_sample - window_size / 2, conv );
double ret = 0.0;
for ( int i = 0; i < window_size; i++ ) {
double x = i / (double)window_size;
@@ -360,8 +435,9 @@ namespace Boare.Lib.Media {
}
return ret / (double)window_size;
}
+#endif
-
+#if !JAVA
///
/// 音量の時間変化を取得します
///
@@ -370,7 +446,7 @@ namespace Boare.Lib.Media {
/// 解像度(サンプル数)
///
public double[] GetVolume( int window_size, math.WindowFunctionType window_function_type ) {
- double[] conv = GetNormalizedWave();
+ double[] conv = getNormalizedWave();
for ( int i = 0; i < conv.Length; i++ ) {
conv[i] = Math.Abs( conv[i] );
}
@@ -380,7 +456,7 @@ namespace Boare.Lib.Media {
double x = i / (double)window_size;
w[i] = math.window_func( window_function_type, x );
}
- double[] ret = new double[m_total_samples];
+ double[] ret = new double[(int)m_total_samples];
double inv = 1.0 / (double)window_size;
int ws2 = window_size / 2;
for ( int i = 0; i < m_total_samples; i++ ) {
@@ -404,9 +480,9 @@ namespace Boare.Lib.Media {
}
return ret;
}
+#endif
-
- public void GetNormalizedWave( int start_index, ref double[] conv ) {
+ public void getNormalizedWave( int start_index, double[] conv ) {
int count = conv.Length;
int cp_start = start_index;
int cp_end = start_index + count;
@@ -428,99 +504,77 @@ namespace Boare.Lib.Media {
conv[i - start_index] = (L8[i] - 64.0) / 64.0;
}
} else {
- for (int i = cp_start; i < cp_end; i++ ) {
+ for ( int i = cp_start; i < cp_end; i++ ) {
conv[i - start_index] = L16[i] / 32768.0;
}
}
} else {
if ( m_bit_per_sample == 8 ) {
- for (int i = cp_start; i < cp_end; i++ ) {
+ for ( int i = cp_start; i < cp_end; i++ ) {
conv[i - start_index] = ((L8[i] + R8[i]) * 0.5 - 64.0) / 64.0;
}
} else {
- for (int i = cp_start; i < cp_end; i++ ) {
+ for ( int i = cp_start; i < cp_end; i++ ) {
conv[i - start_index] = (L16[i] + R16[i]) * 0.5 / 32768.0;
}
}
}
}
-
- public double[] GetNormalizedWave() {
- return GetNormalizedWave( 0, m_total_samples );
+ public double[] getNormalizedWave() {
+ return getNormalizedWave( 0, m_total_samples );
}
-
-
///
/// -1から1までに規格化された波形を取得します
///
///
- public double[] GetNormalizedWave( int start_index, uint count ) {
- double[] conv = new double[count];
- GetNormalizedWave( start_index, ref conv );
+ public double[] getNormalizedWave( int start_index, long count ) {
+ double[] conv = new double[(int)count];
+ getNormalizedWave( start_index, conv );
return conv;
}
-
- public int this[int index, Channel channel] {
- get {
- if ( m_channel == WaveChannel.Monoral || channel == Channel.Left ) {
- if ( m_bit_per_sample == 8 ) {
- return L8[index];
- } else {
- return L16[index];
- }
+ private void set( int index, Channel channel, int value ) {
+ if ( m_channel == WaveChannel.Monoral || channel == Channel.Left ) {
+ if ( m_bit_per_sample == 8 ) {
+ L8[index] = (byte)value;
} else {
- if ( m_bit_per_sample == 8 ) {
- return R8[index];
- } else {
- return R16[index];
- }
+ L16[index] = (short)value;
}
- }
- set {
- if ( m_channel == WaveChannel.Monoral || channel == Channel.Left ) {
- if ( m_bit_per_sample == 8 ) {
- L8[index] = (byte)value;
- } else {
- L16[index] = (short)value;
- }
+ } else {
+ if ( m_bit_per_sample == 8 ) {
+ R8[index] = (byte)value;
} else {
- if ( m_bit_per_sample == 8 ) {
- R8[index] = (byte)value;
- } else {
- R16[index] = (short)value;
- }
+ R16[index] = (short)value;
}
}
}
-
- public int this[int index] {
- get {
+ private int get( int index, Channel channel ) {
+ if ( m_channel == WaveChannel.Monoral || channel == Channel.Left ) {
if ( m_bit_per_sample == 8 ) {
return L8[index];
} else {
return L16[index];
}
- }
- set {
+ } else {
if ( m_bit_per_sample == 8 ) {
- L8[index] = (byte)value;
- if ( m_channel == WaveChannel.Stereo ) {
- R8[index] = (byte)value;
- }
+ return R8[index];
} else {
- L16[index] = (short)value;
- if ( m_channel == WaveChannel.Stereo ) {
- R16[index] = (short)value;
- }
+ return R16[index];
}
}
}
- public double Get( int index ) {
+ private void set( int index, int value ) {
+ set( index, Channel.Left, value );
+ if ( m_channel == WaveChannel.Stereo ) {
+ set( index, Channel.Right, value );
+ }
+ }
+
+ public double getDouble( int index ) {
if ( m_channel == WaveChannel.Monoral ) {
if ( m_bit_per_sample == 8 ) {
return (L8[index] - 64.0) / 64.0;
@@ -536,57 +590,52 @@ namespace Boare.Lib.Media {
}
}
- public uint SampleRate {
- get {
- return m_sample_rate;
- }
+ public long getSampleRate() {
+ return m_sample_rate;
}
-
- public uint TotalSamples {
- get {
- return m_total_samples;
- }
- set {
- m_total_samples = value;
- if ( m_channel == WaveChannel.Monoral ) {
- if ( m_bit_per_sample == 8 ) {
- if ( L8 == null ) {
- L8 = new byte[m_total_samples];
- } else {
- Array.Resize( ref L8, (int)m_total_samples );
- }
+ private void setTotalSamples( long value ) {
+ m_total_samples = value;
+ if ( m_channel == WaveChannel.Monoral ) {
+ if ( m_bit_per_sample == 8 ) {
+ if ( L8 == null ) {
+ L8 = new byte[(int)m_total_samples];
} else {
- if ( L16 == null ) {
- L16 = new short[m_total_samples];
- } else {
- Array.Resize( ref L16, (int)m_total_samples );
- }
+ L8 = resizeArray( L8, (int)m_total_samples );
}
} else {
- if ( m_bit_per_sample == 8 ) {
- if ( L8 == null ) {
- L8 = new byte[m_total_samples];
- R8 = new byte[m_total_samples];
- } else {
- Array.Resize( ref L8, (int)m_total_samples );
- Array.Resize( ref R8, (int)m_total_samples );
- }
+ if ( L16 == null ) {
+ L16 = new short[(int)m_total_samples];
} else {
- if ( L16 == null ) {
- L16 = new short[m_total_samples];
- R16 = new short[m_total_samples];
- } else {
- Array.Resize( ref L16, (int)m_total_samples );
- Array.Resize( ref R16, (int)m_total_samples );
- }
+ L16 = resizeArray( L16, (int)m_total_samples );
+ }
+ }
+ } else {
+ if ( m_bit_per_sample == 8 ) {
+ if ( L8 == null ) {
+ L8 = new byte[(int)m_total_samples];
+ R8 = new byte[(int)m_total_samples];
+ } else {
+ L8 = resizeArray( L8, (int)m_total_samples );
+ R8 = resizeArray( R8, (int)m_total_samples );
+ }
+ } else {
+ if ( L16 == null ) {
+ L16 = new short[(int)m_total_samples];
+ R16 = new short[(int)m_total_samples];
+ } else {
+ L16 = resizeArray( L16, (int)m_total_samples );
+ R16 = resizeArray( R16, (int)m_total_samples );
}
}
}
}
+ public long getTotalSamples() {
+ return m_total_samples;
+ }
- public void Replace( Wave srcWave, uint srcStart, uint destStart, uint count ) {
+ public void replace( Wave srcWave, int srcStart, int destStart, int count ) {
#if DEBUG
Console.WriteLine( "Wave.Replace(Wave,uint,uint,uint)" );
#endif
@@ -615,51 +664,51 @@ namespace Boare.Lib.Media {
}
}
- count = (count > srcWave.TotalSamples - srcStart) ? srcWave.TotalSamples - srcStart : count;
- uint new_last_index = destStart + count;
+ count = (int)((count > srcWave.getTotalSamples() - srcStart) ? srcWave.getTotalSamples() - srcStart : count);
+ long new_last_index = destStart + count;
if ( m_total_samples < new_last_index ) {
if ( m_channel == WaveChannel.Monoral ) {
if ( m_bit_per_sample == 8 ) {
- Array.Resize( ref L8, (int)new_last_index );
+ L8 = resizeArray( L8, (int)new_last_index );
} else {
- Array.Resize( ref L16, (int)new_last_index );
+ L16 = resizeArray( L16, (int)new_last_index );
}
} else {
if ( m_bit_per_sample == 8 ) {
- Array.Resize( ref L8, (int)new_last_index );
- Array.Resize( ref R8, (int)new_last_index );
+ L8 = resizeArray( L8, (int)new_last_index );
+ R8 = resizeArray( R8, (int)new_last_index );
} else {
- Array.Resize( ref L16, (int)new_last_index );
- Array.Resize( ref R16, (int)new_last_index );
+ L16 = resizeArray( L16, (int)new_last_index );
+ R16 = resizeArray( R16, (int)new_last_index );
}
}
m_total_samples = new_last_index;
}
if ( m_channel == WaveChannel.Monoral ) {
if ( m_bit_per_sample == 8 ) {
- Array.Copy( srcWave.L8, srcStart, L8, destStart, count );
+ copyArray( srcWave.L8, srcStart, L8, destStart, count );
} else {
- Array.Copy( srcWave.L16, srcStart, L16, destStart, count );
+ copyArray( srcWave.L16, srcStart, L16, destStart, count );
}
} else {
if ( m_bit_per_sample == 8 ) {
- Array.Copy( srcWave.L8, srcStart, L8, destStart, count );
- Array.Copy( srcWave.R8, srcStart, R8, destStart, count );
+ copyArray( srcWave.L8, srcStart, L8, destStart, count );
+ copyArray( srcWave.R8, srcStart, R8, destStart, count );
} else {
- Array.Copy( srcWave.L16, srcStart, L16, destStart, count );
- Array.Copy( srcWave.R16, srcStart, R16, destStart, count );
+ copyArray( srcWave.L16, srcStart, L16, destStart, count );
+ copyArray( srcWave.R16, srcStart, R16, destStart, count );
}
}
}
- public void Replace( byte[] data, uint start_index ) {
+ public void replace( byte[] data, int start_index ) {
if ( m_channel != WaveChannel.Monoral || m_bit_per_sample != 8 || L8 == null ) {
return;
}
- uint new_last_index = (uint)(start_index + data.Length);
+ long new_last_index = (long)(start_index + data.Length);
if ( m_total_samples < new_last_index ) {
- Array.Resize( ref L8, (int)new_last_index );
+ L8 = resizeArray( L8, (int)new_last_index );
m_total_samples = new_last_index;
}
for ( int i = 0; i < data.Length; i++ ) {
@@ -668,13 +717,13 @@ namespace Boare.Lib.Media {
}
- public void Replace( short[] data, uint start_index ) {
+ public void replace( short[] data, int start_index ) {
if ( m_channel != WaveChannel.Monoral || m_bit_per_sample != 16 || L16 == null ) {
return;
}
- uint new_last_index = (uint)(start_index + data.Length);
+ long new_last_index = (long)(start_index + data.Length);
if ( m_total_samples < new_last_index ) {
- Array.Resize( ref L16, (int)new_last_index );
+ L16 = resizeArray( L16, (int)new_last_index );
m_total_samples = new_last_index;
}
for ( int i = 0; i < data.Length; i++ ) {
@@ -683,14 +732,14 @@ namespace Boare.Lib.Media {
}
- public void Replace( byte[] left, byte[] right, uint start_index ) {
+ public void replace( byte[] left, byte[] right, int start_index ) {
if ( m_channel != WaveChannel.Stereo || m_bit_per_sample != 8 || L8 == null || R8 == null ) {
return;
}
- uint new_last_index = (uint)(start_index + left.Length);
+ long new_last_index = (long)(start_index + left.Length);
if ( m_total_samples < new_last_index ) {
- Array.Resize( ref L8, (int)new_last_index );
- Array.Resize( ref R8, (int)new_last_index );
+ L8 = resizeArray( L8, (int)new_last_index );
+ R8 = resizeArray( R8, (int)new_last_index );
m_total_samples = new_last_index;
}
for ( int i = 0; i < left.Length; i++ ) {
@@ -700,14 +749,14 @@ namespace Boare.Lib.Media {
}
- public void Replace( short[] left, short[] right, uint start_index ) {
+ public void replace( short[] left, short[] right, int start_index ) {
if ( m_channel != WaveChannel.Stereo || m_bit_per_sample != 16 || L16 == null || R16 == null ) {
return;
}
- uint new_last_index = (uint)(start_index + left.Length);
+ long new_last_index = (long)(start_index + left.Length);
if ( m_total_samples < new_last_index ) {
- Array.Resize( ref L16, (int)new_last_index );
- Array.Resize( ref R16, (int)new_last_index );
+ L16 = resizeArray( L16, (int)new_last_index );
+ R16 = resizeArray( R16, (int)new_last_index );
m_total_samples = new_last_index;
}
for ( int i = 0; i < left.Length; i++ ) {
@@ -716,41 +765,41 @@ namespace Boare.Lib.Media {
}
}
- public void Replace( float[] left, float[] right, uint start_index ) {
- uint new_last_index = (uint)(start_index + left.Length);
+ public void replace( float[] left, float[] right, int start_index ) {
+ long new_last_index = (long)(start_index + left.Length);
if ( m_total_samples < new_last_index ) {
if ( m_channel == WaveChannel.Monoral ) {
if ( m_bit_per_sample == 8 ) {
if ( L8 == null ) {
return;
}
- Array.Resize( ref L8, (int)new_last_index );
+ L8 = resizeArray( L8, (int)new_last_index );
} else {
if ( L16 == null ) {
return;
}
- Array.Resize( ref L16, (int)new_last_index );
+ L16 = resizeArray( L16, (int)new_last_index );
}
} else {
if ( m_bit_per_sample == 8 ) {
if ( L8 == null || R8 == null ) {
return;
}
- Array.Resize( ref L8, (int)new_last_index );
- Array.Resize( ref R8, (int)new_last_index );
+ L8 = resizeArray( L8, (int)new_last_index );
+ R8 = resizeArray( R8, (int)new_last_index );
} else {
if ( L16 == null || R16 == null ) {
return;
}
- Array.Resize( ref L16, (int)new_last_index );
- Array.Resize( ref R16, (int)new_last_index );
+ L16 = resizeArray( L16, (int)new_last_index );
+ R16 = resizeArray( R16, (int)new_last_index );
}
}
m_total_samples = new_last_index;
}
if ( m_channel == WaveChannel.Monoral ) {
float[] mono = new float[left.Length];
- for( int i = 0; i < left.Length; i++ ){
+ for ( int i = 0; i < left.Length; i++ ) {
mono[i] = (left[i] + right[i]) / 2f;
}
if ( m_bit_per_sample == 8 ) {
@@ -777,29 +826,43 @@ namespace Boare.Lib.Media {
}
}
- public void PrintToText( string path ) {
- using ( StreamWriter sw = new StreamWriter( path ) ) {
+ public void printToText( String path ) {
+ BufferedWriter sw = null;
+ try {
+ sw = new BufferedWriter( new FileWriter( path ) );
if ( m_channel == WaveChannel.Monoral ) {
if ( m_bit_per_sample == 8 ) {
for ( int i = 0; i < m_total_samples; i++ ) {
- sw.WriteLine( L8[i] );
+ sw.write( L8[i] + "" );
+ sw.newLine();
}
} else {
for ( int i = 0; i < m_total_samples; i++ ) {
- sw.WriteLine( L16[i] );
+ sw.write( L16[i] + "" );
+ sw.newLine();
}
}
} else {
if ( m_bit_per_sample == 8 ) {
for ( int i = 0; i < m_total_samples; i++ ) {
- sw.WriteLine( L8[i] + "\t" + R8[i] );
+ sw.write( L8[i] + "\t" + R8[i] );
+ sw.newLine();
}
} else {
for ( int i = 0; i < m_total_samples; i++ ) {
- sw.WriteLine( L16[i] + "\t" + R16[i] );
+ sw.write( L16[i] + "\t" + R16[i] );
+ sw.newLine();
}
}
}
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sw != null ) {
+ try {
+ sw.close();
+ } catch ( Exception ex2 ) {
+ }
+ }
}
}
@@ -808,13 +871,17 @@ namespace Boare.Lib.Media {
R8 = null;
L16 = null;
R16 = null;
+#if JAVA
+ System.gc();
+#else
GC.Collect();
+#endif
}
///
/// サンプルあたりのビット数を8に変更する
///
- public void ConvertTo8Bit() {
+ public void convertTo8Bit() {
if ( m_bit_per_sample == 8 ) {
return;
}
@@ -844,114 +911,129 @@ namespace Boare.Lib.Media {
/// ファイルに保存
///
///
- public void Write( string file ) {
- using ( FileStream fs = new FileStream( file, FileMode.Create ) ) {
+ public void write( String file ) {
+ RandomAccessFile fs = null;
+ try {
+ fs = new RandomAccessFile( file, "rw" );
// RIFF
- fs.WriteByte( 0x52 );
- fs.WriteByte( 0x49 );
- fs.WriteByte( 0x46 );
- fs.WriteByte( 0x46 );
+ fs.write( 0x52 );
+ fs.write( 0x49 );
+ fs.write( 0x46 );
+ fs.write( 0x46 );
// ファイルサイズ - 8最後に記入
- fs.WriteByte( 0x00 );
- fs.WriteByte( 0x00 );
- fs.WriteByte( 0x00 );
- fs.WriteByte( 0x00 );
+ fs.write( 0x00 );
+ fs.write( 0x00 );
+ fs.write( 0x00 );
+ fs.write( 0x00 );
// WAVE
- fs.WriteByte( 0x57 );
- fs.WriteByte( 0x41 );
- fs.WriteByte( 0x56 );
- fs.WriteByte( 0x45 );
+ fs.write( 0x57 );
+ fs.write( 0x41 );
+ fs.write( 0x56 );
+ fs.write( 0x45 );
// fmt
- fs.WriteByte( 0x66 );
- fs.WriteByte( 0x6d );
- fs.WriteByte( 0x74 );
- fs.WriteByte( 0x20 );
+ fs.write( 0x66 );
+ fs.write( 0x6d );
+ fs.write( 0x74 );
+ fs.write( 0x20 );
// fmt チャンクのサイズ
- fs.WriteByte( 0x12 );
- fs.WriteByte( 0x00 );
- fs.WriteByte( 0x00 );
- fs.WriteByte( 0x00 );
+ fs.write( 0x12 );
+ fs.write( 0x00 );
+ fs.write( 0x00 );
+ fs.write( 0x00 );
// format ID
- fs.WriteByte( 0x01 );
- fs.WriteByte( 0x00 );
+ fs.write( 0x01 );
+ fs.write( 0x00 );
// チャンネル数
if ( m_channel == WaveChannel.Monoral ) {
- fs.WriteByte( 0x01 );
- fs.WriteByte( 0x00 );
+ fs.write( 0x01 );
+ fs.write( 0x00 );
} else {
- fs.WriteByte( 0x02 );
- fs.WriteByte( 0x00 );
+ fs.write( 0x02 );
+ fs.write( 0x00 );
}
// サンプリングレート
- byte[] buf = BitConverter.GetBytes( m_sample_rate );
- WriteByteArray( fs, buf, 4 );
+ byte[] buf = PortUtil.getbytes_uint32_le( m_sample_rate );
+ writeByteArray( fs, buf, 4 );
// データ速度
- ushort block_size = (ushort)(m_bit_per_sample / 8 * (int)m_channel);
- uint data_rate = m_sample_rate * block_size;
- buf = BitConverter.GetBytes( data_rate );
- WriteByteArray( fs, buf, 4 );
+ int ichannel = (m_channel == WaveChannel.Monoral) ? 1 : 2;
+ int block_size = (int)(m_bit_per_sample / 8 * ichannel);
+ long data_rate = m_sample_rate * block_size;
+ buf = PortUtil.getbytes_uint32_le( data_rate );
+ writeByteArray( fs, buf, 4 );
// ブロックサイズ
- buf = BitConverter.GetBytes( block_size );
- WriteByteArray( fs, buf, 2 );
+ buf = PortUtil.getbytes_uint16_le( block_size );
+ writeByteArray( fs, buf, 2 );
// サンプルあたりのビット数
- buf = BitConverter.GetBytes( m_bit_per_sample );
- WriteByteArray( fs, buf, 2 );
+ buf = PortUtil.getbytes_uint16_le( m_bit_per_sample );
+ writeByteArray( fs, buf, 2 );
// 拡張部分
- fs.WriteByte( 0x00 );
- fs.WriteByte( 0x00 );
+ fs.write( 0x00 );
+ fs.write( 0x00 );
// data
- fs.WriteByte( 0x64 );
- fs.WriteByte( 0x61 );
- fs.WriteByte( 0x74 );
- fs.WriteByte( 0x61 );
+ fs.write( 0x64 );
+ fs.write( 0x61 );
+ fs.write( 0x74 );
+ fs.write( 0x61 );
// size of data chunk
- uint size = block_size * m_total_samples;
- buf = BitConverter.GetBytes( size );
- WriteByteArray( fs, buf, 4 );
+ long size = block_size * m_total_samples;
+ buf = PortUtil.getbytes_uint32_le( size );
+ writeByteArray( fs, buf, 4 );
// 波形データ
for ( int i = 0; i < m_total_samples; i++ ) {
if ( m_bit_per_sample == 8 ) {
- fs.WriteByte( L8[i] );
+ fs.write( L8[i] );
if ( m_channel == WaveChannel.Stereo ) {
- fs.WriteByte( R8[i] );
+ fs.write( R8[i] );
}
} else {
- buf = BitConverter.GetBytes( L16[i] );
- WriteByteArray( fs, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( L16[i] );
+ writeByteArray( fs, buf, 2 );
if ( m_channel == WaveChannel.Stereo ) {
- buf = BitConverter.GetBytes( R16[i] );
- WriteByteArray( fs, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( R16[i] );
+ writeByteArray( fs, buf, 2 );
}
}
}
// 最後にWAVEチャンクのサイズ
- uint position = (uint)fs.Position;
- fs.Seek( 4, SeekOrigin.Begin );
- buf = BitConverter.GetBytes( position - 8 );
- WriteByteArray( fs, buf, 4 );
+ long position = fs.getFilePointer();
+ fs.seek( 4 );
+ buf = PortUtil.getbytes_uint32_le( position - 8 );
+ writeByteArray( fs, buf, 4 );
+ } catch ( Exception ex ) {
+ } finally {
+ if ( fs != null ) {
+ try {
+ fs.close();
+ } catch ( Exception ex2 ) {
+ }
+ }
}
}
- private static void WriteByteArray( FileStream fs, byte[] dat, int limit ) {
- fs.Write( dat, 0, (dat.Length > limit) ? limit : dat.Length );
+ private static void writeByteArray( RandomAccessFile fs, byte[] dat, int limit )
+#if JAVA
+ throws IOException
+#endif
+ {
+ fs.write( dat, 0, (dat.Length > limit) ? limit : dat.Length );
if ( dat.Length < limit ) {
for ( int i = 0; i < limit - dat.Length; i++ ) {
- fs.WriteByte( 0x00 );
+ fs.write( 0x00 );
}
}
}
@@ -959,7 +1041,7 @@ namespace Boare.Lib.Media {
///
/// ステレオをモノラル化
///
- public void Monoralize() {
+ public void monoralize() {
if ( m_channel != WaveChannel.Stereo ) {
return;
}
@@ -982,7 +1064,7 @@ namespace Boare.Lib.Media {
///
/// 前後の無音部分を削除します
///
- public void TrimSilence() {
+ public void trimSilence() {
#if DEBUG
Console.WriteLine( "Wave.TrimSilence" );
#endif
@@ -1004,10 +1086,10 @@ namespace Boare.Lib.Media {
}
int count = non_silence_end - non_silence_begin + 1;
R8 = new byte[count];
- Array.Copy( L8, non_silence_begin, R8, 0, count );
+ copyArray( L8, non_silence_begin, R8, 0, count );
L8 = null;
L8 = new byte[count];
- Array.Copy( R8, L8, count );
+ copyArray( R8, 0, L8, 0, count );
R8 = null;
} else {
int non_silence_begin = 1;
@@ -1026,14 +1108,14 @@ namespace Boare.Lib.Media {
}
int count = non_silence_end - non_silence_begin + 1;
byte[] buf = new byte[count];
- Array.Copy( L8, non_silence_begin, buf, 0, count );
+ copyArray( L8, non_silence_begin, buf, 0, count );
L8 = null;
L8 = new byte[count];
- Array.Copy( buf, L8, count );
- Array.Copy( R8, non_silence_begin, buf, 0, count );
+ copyArray( buf, 0, L8, 0, count );
+ copyArray( R8, non_silence_begin, buf, 0, count );
R8 = null;
R8 = new byte[count];
- Array.Copy( buf, R8, count );
+ copyArray( buf, 0, R8, 0, count );
buf = null;
}
} else {
@@ -1054,9 +1136,9 @@ namespace Boare.Lib.Media {
}
int count = non_silence_end - non_silence_begin + 1;
R16 = new short[count];
- Array.Copy( L16, non_silence_begin, R16, 0, count );
- Array.Resize( ref L16, count );
- Array.Copy( R16, L16, count );
+ copyArray( L16, non_silence_begin, R16, 0, count );
+ L16 = resizeArray( L16, count );
+ copyArray( R16, 0, L16, 0, count );
R16 = null;
} else {
int non_silence_begin = 1;
@@ -1079,21 +1161,21 @@ namespace Boare.Lib.Media {
#endif
int count = non_silence_end - non_silence_begin + 1;
short[] buf = new short[count];
- Array.Copy( L16, non_silence_begin, buf, 0, count );
- Array.Resize( ref L16, count );
- Array.Copy( buf, 0, L16, 0, count );
-
- Array.Copy( R16, non_silence_begin, buf, 0, count );
- Array.Resize( ref R16, count );
- Array.Copy( buf, 0, R16, 0, count );
+ copyArray( L16, non_silence_begin, buf, 0, count );
+ L16 = resizeArray( L16, count );
+ copyArray( buf, 0, L16, 0, count );
+
+ copyArray( R16, non_silence_begin, buf, 0, count );
+ R16 = resizeArray( R16, count );
+ copyArray( buf, 0, R16, 0, count );
buf = null;
}
}
if ( m_bit_per_sample == 8 ) {
- m_total_samples = (uint)L8.Length;
+ m_total_samples = (long)L8.Length;
} else {
- m_total_samples = (uint)L16.Length;
+ m_total_samples = (long)L16.Length;
}
}
@@ -1103,31 +1185,31 @@ namespace Boare.Lib.Media {
m_sample_rate = 44100;
}
- public Wave( WaveChannel channels, ushort bit_per_sample, uint sample_rate, uint initial_capacity ) {
+ public Wave( WaveChannel channels, int bit_per_sample, int sample_rate, int initial_capacity ) {
m_channel = channels;
m_bit_per_sample = bit_per_sample;
m_sample_rate = sample_rate;
m_total_samples = initial_capacity;
if ( m_bit_per_sample == 8 ) {
- L8 = new byte[m_total_samples];
+ L8 = new byte[(int)m_total_samples];
if ( m_channel == WaveChannel.Stereo ) {
- R8 = new byte[m_total_samples];
+ R8 = new byte[(int)m_total_samples];
}
} else if ( m_bit_per_sample == 16 ) {
- L16 = new short[m_total_samples];
+ L16 = new short[(int)m_total_samples];
if ( m_channel == WaveChannel.Stereo ) {
- R16 = new short[m_total_samples];
+ R16 = new short[(int)m_total_samples];
}
}
}
- public void Append( double[] L, double[] R ) {
+ public void append( double[] L, double[] R ) {
int length = Math.Min( L.Length, R.Length );
int old_length = L16.Length;
if ( m_bit_per_sample == 16 && m_channel == WaveChannel.Stereo ) {
- Array.Resize( ref L16, (int)(m_total_samples + length) );
- Array.Resize( ref R16, (int)(m_total_samples + length) );
- m_total_samples += (uint)length;
+ L16 = resizeArray( L16, (int)(m_total_samples + length) );
+ R16 = resizeArray( R16, (int)(m_total_samples + length) );
+ m_total_samples += (long)length;
for ( int i = old_length; i < m_total_samples; i++ ) {
L16[i] = (short)(L[i - old_length] * 32768f);
R16[i] = (short)(R[i - old_length] * 32768f);
@@ -1135,53 +1217,124 @@ namespace Boare.Lib.Media {
} //else ... TODO: Wave+Append他のbitpersec, channelのとき
}
- /*public void Append( short[] L, short[] R ) {
- int length = Math.Min( L.Length, R.Length );
- int old_length = L16.Length;
- if ( m_bit_per_sample == 16 && m_channel == WaveChannel.Stereo ) {
- Array.Resize( ref L16, (int)(m_total_samples + length) );
- Array.Resize( ref R16, (int)(m_total_samples + length) );
- m_total_samples += (uint)length;
- for ( int i = old_length; i < m_total_samples; i++ ) {
- L16[i] = L[i - old_length];
- R16[i] = R[i - old_length];
- }
- } //else ... TODO: Wave+Append他のbitpersec, channelのとき
- }*/
-
- public Wave( string path ) {
- Read( path );
+ public Wave( String path ) {
+ read( path );
}
-
- public bool Read( string path ) {
- FileStream fs = null;
+ private boolean parseAiffHeader( RandomAccessFile fs ) {
try {
- fs = new FileStream( path, FileMode.Open );
- // check RIFF header
byte[] buf = new byte[4];
- fs.Read( buf, 0, 4 );
- if ( buf[0] != 0x52 ||
- buf[1] != 0x49 ||
- buf[2] != 0x46 ||
- buf[3] != 0x46 ) {
+ fs.read( buf, 0, 4 );
+ long chunk_size_form = PortUtil.make_uint32_be( buf );
+ fs.read( buf, 0, 4 ); // AIFF
+ String tag = new String( new char[] { (char)buf[0], (char)buf[1], (char)buf[2], (char)buf[3] } );
+ if ( !tag.Equals( "AIFF" ) ) {
#if DEBUG
- System.Diagnostics.Debug.WriteLine( "invalid header" );
+ Console.WriteLine( "Wave#parseAiffHeader; error; tag=" + tag + " and must be AIFF" );
#endif
- fs.Close();
return false;
}
+ fs.read( buf, 0, 4 ); // COMM
+ tag = new String( new char[] { (char)buf[0], (char)buf[1], (char)buf[2], (char)buf[3] } );
+ if ( !tag.Equals( "COMM" ) ) {
+#if DEBUG
+ Console.WriteLine( "Wave#parseAiffHeader; error; tag=" + tag + " and must be COMM" );
+#endif
+ return false;
+ }
+ fs.read( buf, 0, 4 ); // COMM chunk size
+ long chunk_size_comm = PortUtil.make_uint32_be( buf );
+ long chunk_loc_comm = fs.getFilePointer();
+ fs.read( buf, 0, 2 ); // number of channel
+ int num_channel = PortUtil.make_uint16_be( buf );
+ if ( num_channel == 1 ) {
+ m_channel = WaveChannel.Monoral;
+ } else {
+ m_channel = WaveChannel.Stereo;
+ }
+ fs.read( buf, 0, 4 ); // number of samples
+ m_total_samples = PortUtil.make_uint32_be( buf );
+#if DEBUG
+ Console.WriteLine( "Wave#parseAiffHeader; m_total_samples=" + m_total_samples );
+#endif
+ fs.read( buf, 0, 2 ); // block size
+ m_bit_per_sample = PortUtil.make_uint16_be( buf );
+ byte[] buf10 = new byte[10];
+ fs.read( buf10, 0, 10 ); // sample rate
+ m_sample_rate = (long)make_double_from_extended( buf10 );
+#if DEBUG
+ Console.WriteLine( "Wave#parseAiffHeader; m_sample_rate=" + m_sample_rate );
+#endif
+ fs.seek( chunk_loc_comm + (long)chunk_size_comm );
+ fs.read( buf, 0, 4 ); // SSND
+ tag = new String( new char[] { (char)buf[0], (char)buf[1], (char)buf[2], (char)buf[3] } );
+ if ( !tag.Equals( "SSND" ) ) {
+#if DEBUG
+ Console.WriteLine( "Wave#parseAiffHeader; error; tag=" + tag + " and must be SSND" );
+#endif
+ return false;
+ }
+ fs.read( buf, 0, 4 ); // SSND chunk size
+ long chunk_size_ssnd = PortUtil.make_uint32_be( buf );
+ } catch ( Exception ex ) {
+ return false;
+ }
+ return true;
+ }
+
+ private static double make_double_from_extended( byte[] bytes ) {
+ double f;
+ long hiMant, loMant;
+
+ int expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF);
+ hiMant = ((long)(bytes[2] & 0xFF) << 24)
+ | ((long)(bytes[3] & 0xFF) << 16)
+ | ((long)(bytes[4] & 0xFF) << 8)
+ | ((long)(bytes[5] & 0xFF));
+ loMant = ((long)(bytes[6] & 0xFF) << 24)
+ | ((long)(bytes[7] & 0xFF) << 16)
+ | ((long)(bytes[8] & 0xFF) << 8)
+ | ((long)(bytes[9] & 0xFF));
+
+ if ( expon == 0 && hiMant == 0 && loMant == 0 ) {
+ f = 0;
+ } else {
+ if ( expon == 0x7FFF ) {
+ f = double.MaxValue;
+ } else {
+ expon -= 16383;
+ //f = ldexp( double_from_uint( hiMant ), expon -= 31 );
+ f = Math.Pow( 2.0, expon - 31 ) * double_from_uint( hiMant );
+ //f += ldexp( double_from_uint( loMant ), expon -= 32 );
+ f += Math.Pow( 2.0, expon - 32 ) * double_from_uint( loMant );
+ }
+ }
+
+ if ( (bytes[0] & 0x80) != 0 ) {
+ return -f;
+ } else {
+ return f;
+ }
+ }
+
+ private static double double_from_uint( long u ) {
+ return (((double)((int)(u - 2147483647 - 1))) + 2147483648.0);
+ }
+
+ private boolean parseWaveHeader( RandomAccessFile fs ) {
+ try {
+ byte[] buf = new byte[4];
// detect size of RIFF chunk
- fs.Read( buf, 0, 4 );
- uint riff_chunk_size = GetUIntFrom4Bytes( buf );
+ fs.read( buf, 0, 4 );
+ long riff_chunk_size = PortUtil.make_uint32_le( buf );
#if DEBUG
System.Diagnostics.Debug.WriteLine( "riff_chunk_size=" + riff_chunk_size );
#endif
// check wave header
- fs.Seek( 8, SeekOrigin.Begin );
- fs.Read( buf, 0, 4 );
+ fs.seek( 8 );
+ fs.read( buf, 0, 4 );
if ( buf[0] != 0x57 ||
buf[1] != 0x41 ||
buf[2] != 0x56 ||
@@ -1189,12 +1342,12 @@ namespace Boare.Lib.Media {
#if DEBUG
System.Diagnostics.Debug.WriteLine( "invalid wave header" );
#endif
- fs.Close();
+ fs.close();
return false;
}
// check fmt chunk header
- fs.Read( buf, 0, 4 );
+ fs.read( buf, 0, 4 );
if ( buf[0] != 0x66 ||
buf[1] != 0x6d ||
buf[2] != 0x74 ||
@@ -1202,23 +1355,23 @@ namespace Boare.Lib.Media {
#if DEBUG
System.Diagnostics.Debug.WriteLine( "invalid fmt header" );
#endif
- fs.Close();
+ fs.close();
return false;
}
// detect size of fmt chunk
- uint fmt_chunk_bytes;
- fs.Read( buf, 0, 4 );
- fmt_chunk_bytes = GetUIntFrom4Bytes( buf );
+ long fmt_chunk_bytes;
+ fs.read( buf, 0, 4 );
+ fmt_chunk_bytes = PortUtil.make_uint32_le( buf );
#if DEBUG
System.Diagnostics.Debug.WriteLine( "fmt_chunk_bytes=" + fmt_chunk_bytes );
#endif
// get format ID
- fs.Read( buf, 0, 2 );
- ushort format_id = GetUShortFrom2Bytes( buf );
+ fs.read( buf, 0, 2 );
+ int format_id = PortUtil.make_uint16_le( buf );
if ( format_id != 1 ) {
- fs.Close();
+ fs.close();
return false;
}
#if DEBUG
@@ -1226,14 +1379,14 @@ namespace Boare.Lib.Media {
#endif
// get the number of channel(s)
- fs.Read( buf, 0, 2 );
- ushort num_channels = GetUShortFrom2Bytes( buf );
+ fs.read( buf, 0, 2 );
+ int num_channels = PortUtil.make_uint16_le( buf );
if ( num_channels == 1 ) {
m_channel = WaveChannel.Monoral;
} else if ( num_channels == 2 ) {
m_channel = WaveChannel.Stereo;
} else {
- fs.Close();
+ fs.close();
return false;
}
#if DEBUG
@@ -1241,115 +1394,173 @@ namespace Boare.Lib.Media {
#endif
// get sampling rate
- fs.Read( buf, 0, 4 );
- m_sample_rate = GetUIntFrom4Bytes( buf );
+ fs.read( buf, 0, 4 );
+ m_sample_rate = PortUtil.make_uint32_le( buf );
#if DEBUG
System.Diagnostics.Debug.WriteLine( "m_sample_rate=" + m_sample_rate );
#endif
// get bit per sample
- fs.Seek( 0x22, SeekOrigin.Begin );
- fs.Read( buf, 0, 2 );
- m_bit_per_sample = GetUShortFrom2Bytes( buf );
+ fs.seek( 0x22 );
+ fs.read( buf, 0, 2 );
+ m_bit_per_sample = PortUtil.make_uint16_le( buf );
#if DEBUG
System.Diagnostics.Debug.WriteLine( "m_bit_per_sample=" + m_bit_per_sample );
#endif
if ( m_bit_per_sample != 0x08 && m_bit_per_sample != 0x10 ) {
- fs.Close();
+ fs.close();
return false;
}
// move to the end of fmt chunk
- fs.Seek( 0x14 + fmt_chunk_bytes, SeekOrigin.Begin );
+ fs.seek( 0x14 + fmt_chunk_bytes );
// move to the top of data chunk
- fs.Read( buf, 0, 4 );
- string tag = new string( new char[] { (char)buf[0], (char)buf[1], (char)buf[2], (char)buf[3] } );
+ fs.read( buf, 0, 4 );
+ String tag = new String( new char[] { (char)buf[0], (char)buf[1], (char)buf[2], (char)buf[3] } );
#if DEBUG
System.Diagnostics.Debug.WriteLine( "tag=" + tag );
#endif
while ( tag != "data" ) {
- fs.Read( buf, 0, 4 );
- uint size = GetUIntFrom4Bytes( buf );
- fs.Seek( size, SeekOrigin.Current );
- fs.Read( buf, 0, 4 );
- tag = new string( new char[] { (char)buf[0], (char)buf[1], (char)buf[2], (char)buf[3] } );
+ fs.read( buf, 0, 4 );
+ long size = PortUtil.make_uint32_le( buf );
+ fs.seek( fs.getFilePointer() + size );
+ fs.read( buf, 0, 4 );
+ tag = new String( new char[] { (char)buf[0], (char)buf[1], (char)buf[2], (char)buf[3] } );
#if DEBUG
System.Diagnostics.Debug.WriteLine( "tag=" + tag );
#endif
}
// get size of data chunk
- fs.Read( buf, 0, 4 );
- uint data_chunk_bytes = GetUIntFrom4Bytes( buf );
- m_total_samples = (uint)(data_chunk_bytes / (num_channels * m_bit_per_sample / 8));
+ fs.read( buf, 0, 4 );
+ long data_chunk_bytes = PortUtil.make_uint32_le( buf );
+ m_total_samples = (long)(data_chunk_bytes / (num_channels * m_bit_per_sample / 8));
#if DEBUG
System.Diagnostics.Debug.WriteLine( "m_total_samples=" + m_total_samples );
#endif
- // prepare data
- if ( m_bit_per_sample == 8 ) {
- L8 = new byte[m_total_samples];
- if ( m_channel == WaveChannel.Stereo ) {
- R8 = new byte[m_total_samples];
- }
- } else {
- L16 = new short[m_total_samples];
- if ( m_channel == WaveChannel.Stereo ) {
- R16 = new short[m_total_samples];
- }
- }
-
- // read data
- byte[] buf2 = new byte[2];
- for ( int i = 0; i < m_total_samples; i++ ) {
- if ( m_bit_per_sample == 8 ) {
- fs.Read( buf, 0, 1 );
- L8[i] = buf[0];
- if ( m_channel == WaveChannel.Stereo ) {
- fs.Read( buf, 0, 1 );
- R8[i] = buf[0];
- }
- } else {
- fs.Read( buf2, 0, 2 );
- /*if ( BitConverter.IsLittleEndian ) {
- byte b = buf2[0];
- buf2[0] = buf2[1];
- buf2[1] = b;
- }*/
- L16[i] = BitConverter.ToInt16( buf2, 0 );
- if ( m_channel == WaveChannel.Stereo ) {
- fs.Read( buf2, 0, 2 );
- /*if ( BitConverter.IsLittleEndian ) {
- byte b = buf2[0];
- buf2[0] = buf2[1];
- buf2[1] = b;
- }*/
- R16[i] = BitConverter.ToInt16( buf2, 0 );
- }
- }
- }
} catch ( Exception ex ) {
#if DEBUG
System.Diagnostics.Debug.Write( ex.StackTrace );
#endif
- } finally {
- if ( fs != null ) {
- fs.Close();
- }
}
return true;
}
+ public boolean read( String path ) {
+ RandomAccessFile fs = null;
+ boolean ret = false;
+ try {
+ fs = new RandomAccessFile( path, "r" );
+ // check RIFF header
+ byte[] buf = new byte[4];
+ fs.read( buf, 0, 4 );
+ boolean change_byte_order = false;
+ if ( buf[0] == 0x52 && buf[1] == 0x49 && buf[2] == 0x46 && buf[3] == 0x46 ) {
+ ret = parseWaveHeader( fs );
+ } else if ( buf[0] == 0x46 && buf[1] == 0x4f && buf[2] == 0x52 && buf[3] == 0x4d ) {
+ ret = parseAiffHeader( fs );
+ change_byte_order = true;
+ } else {
+ ret = false;
+ }
+ // prepare data
+ if ( m_bit_per_sample == 8 ) {
+ L8 = new byte[(int)m_total_samples];
+ if ( m_channel == WaveChannel.Stereo ) {
+ R8 = new byte[(int)m_total_samples];
+ }
+ } else {
+ L16 = new short[(int)m_total_samples];
+ if ( m_channel == WaveChannel.Stereo ) {
+ R16 = new short[(int)m_total_samples];
+ }
+ }
- private uint GetUIntFrom4Bytes( byte[] dat ) {
- return (uint)(dat[3] << 24) + (uint)(dat[2] << 16) + (uint)(dat[1] << 8) + (uint)dat[0];
+ // read data
+ // TODO: big endianのときの読込み。
+ byte[] buf2 = new byte[2];
+ for ( int i = 0; i < m_total_samples; i++ ) {
+ if ( m_bit_per_sample == 8 ) {
+ fs.read( buf, 0, 1 );
+ L8[i] = buf[0];
+ if ( m_channel == WaveChannel.Stereo ) {
+ fs.read( buf, 0, 1 );
+ R8[i] = buf[0];
+ }
+ } else {
+ fs.read( buf2, 0, 2 );
+ if ( change_byte_order ) {
+ byte b = buf2[0];
+ buf2[0] = buf2[1];
+ buf2[1] = b;
+ }
+ L16[i] = PortUtil.make_int16_le( buf2 );
+ if ( m_channel == WaveChannel.Stereo ) {
+ fs.read( buf2, 0, 2 );
+ if ( change_byte_order ) {
+ byte b = buf2[0];
+ buf2[0] = buf2[1];
+ buf2[1] = b;
+ }
+ R16[i] = PortUtil.make_int16_le( buf2 );
+ }
+ }
+ }
+ } catch ( Exception ex ) {
+ } finally {
+ if ( fs != null ) {
+ try {
+ fs.close();
+ } catch ( Exception ex2 ) {
+ }
+ }
+ }
+ return ret;
}
+ private static short[] resizeArray( short[] src, int length ) {
+ short[] ret = new short[length];
+ if ( src.Length <= length ) {
+ for ( int i = 0; i < src.Length; i++ ) {
+ ret[i] = src[i];
+ }
+ } else {
+ for ( int i = 0; i < length; i++ ) {
+ ret[i] = src[i];
+ }
+ }
+ return ret;
+ }
- private ushort GetUShortFrom2Bytes( byte[] dat ) {
- return (ushort)((dat[1] << 8) | dat[0]);
+ private static byte[] resizeArray( byte[] src, int length ) {
+ byte[] ret = new byte[length];
+ if ( src.Length <= length ) {
+ for ( int i = 0; i < src.Length; i++ ) {
+ ret[i] = src[i];
+ }
+ } else {
+ for ( int i = 0; i < length; i++ ) {
+ ret[i] = src[i];
+ }
+ }
+ return ret;
+ }
+
+ private static void copyArray( short[] src, int src_start, short[] dest, int dest_start, int length ) {
+ for ( int i = 0; i < length; i++ ) {
+ dest[i + dest_start] = src[i + src_start];
+ }
+ }
+
+ private static void copyArray( byte[] src, int src_start, byte[] dest, int dest_start, int length ) {
+ for ( int i = 0; i < length; i++ ) {
+ dest[i + dest_start] = src[i + src_start];
+ }
}
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Media/WavePlay.cs b/trunk/Boare.Lib.Media/WavePlay.cs
index 64306bb..70fa090 100644
--- a/trunk/Boare.Lib.Media/WavePlay.cs
+++ b/trunk/Boare.Lib.Media/WavePlay.cs
@@ -62,7 +62,7 @@ namespace Boare.Lib.Media {
#if DEBUG
Console.WriteLine( "WavePlay.wave_callback; uMsg=" + uMsg );
#endif
- if ( uMsg == windows.MM_WOM_DONE ) {
+ if ( uMsg == win32.MM_WOM_DONE ) {
int index_done = 0;
WAVEHDR whdr = (WAVEHDR)Marshal.PtrToStructure( new IntPtr( dwParam1 ), typeof( WAVEHDR ) );
int dwuser = whdr.dwUser.ToInt32();
@@ -163,7 +163,7 @@ namespace Boare.Lib.Media {
#if DEBUG
bocoree.debug.push_log( "calling waveOutWrite...; s_hawve_out=0x" + Convert.ToString( s_hwave_out.ToInt32(), 16 ) );
#endif
- uint ret = windows.waveOutWrite( s_hwave_out, ref s_wave_header[0], (uint)sizeof( WAVEHDR ) );
+ uint ret = win32.waveOutWrite( s_hwave_out, ref s_wave_header[0], (uint)sizeof( WAVEHDR ) );
#if DEBUG
bocoree.debug.push_log( "...done; ret=" + ret );
#endif
@@ -181,7 +181,7 @@ namespace Boare.Lib.Media {
#if DEBUG
bocoree.debug.push_log( "calling waveOutWrite...; s_hawve_out=0x" + Convert.ToString( s_hwave_out.ToInt32(), 16 ) );
#endif
- uint ret2 = windows.waveOutWrite( s_hwave_out, ref s_wave_header[buffer_index], (uint)sizeof( WAVEHDR ) );
+ uint ret2 = win32.waveOutWrite( s_hwave_out, ref s_wave_header[buffer_index], (uint)sizeof( WAVEHDR ) );
#if DEBUG
bocoree.debug.push_log( "...done; ret2=" + ret2 );
#endif
@@ -192,7 +192,7 @@ namespace Boare.Lib.Media {
#if DEBUG
bocoree.debug.push_log( "calling waveOutWrite...; s_hawve_out=0x" + Convert.ToString( s_hwave_out.ToInt32(), 16 ) );
#endif
- uint ret3 = windows.waveOutWrite( s_hwave_out, ref s_wave_header[s_current_buffer], (uint)sizeof( WAVEHDR ) );
+ uint ret3 = win32.waveOutWrite( s_hwave_out, ref s_wave_header[s_current_buffer], (uint)sizeof( WAVEHDR ) );
#if DEBUG
bocoree.debug.push_log( "...done; ret3=" + ret3 );
#endif
@@ -229,7 +229,7 @@ namespace Boare.Lib.Media {
#if DEBUG
bocoree.debug.push_log( "calling waveOutWrite...; s_hawve_out=0x" + Convert.ToString( s_hwave_out.ToInt32(), 16 ) );
#endif
- uint ret35 = windows.waveOutWrite( s_hwave_out, ref s_wave_header[0], (uint)sizeof( WAVEHDR ) );
+ uint ret35 = win32.waveOutWrite( s_hwave_out, ref s_wave_header[0], (uint)sizeof( WAVEHDR ) );
#if DEBUG
bocoree.debug.push_log( "...done; ret35=" + ret35 );
bocoree.debug.push_log( "(s_first_buffer_written_callback==null)=" + (s_first_buffer_written_callback == null) );
@@ -247,7 +247,7 @@ namespace Boare.Lib.Media {
#if DEBUG
bocoree.debug.push_log( "calling waveOutWrite...; s_hawve_out=0x" + Convert.ToString( s_hwave_out.ToInt32(), 16 ) );
#endif
- uint ret36 = windows.waveOutWrite( s_hwave_out, ref s_wave_header[i], (uint)sizeof( WAVEHDR ) );
+ uint ret36 = win32.waveOutWrite( s_hwave_out, ref s_wave_header[i], (uint)sizeof( WAVEHDR ) );
#if DEBUG
bocoree.debug.push_log( "...done; ret36=" + ret36 );
#endif
@@ -276,7 +276,7 @@ namespace Boare.Lib.Media {
#if DEBUG
bocoree.debug.push_log( "calling waveOutWrite...; s_hawve_out=0x" + Convert.ToString( s_hwave_out.ToInt32(), 16 ) );
#endif
- uint ret4 = windows.waveOutWrite( s_hwave_out, ref s_wave_header[s_current_buffer], (uint)sizeof( WAVEHDR ) );
+ uint ret4 = win32.waveOutWrite( s_hwave_out, ref s_wave_header[s_current_buffer], (uint)sizeof( WAVEHDR ) );
#if DEBUG
bocoree.debug.push_log( "...done; ret4=" + ret4 );
#endif
@@ -295,10 +295,10 @@ namespace Boare.Lib.Media {
void mix( int processed_count, float amp_left, float amp_right ) {
int current_buffer = (processed_count - 1) % _NUM_BUF;
for ( int k = 0; k < s_num_wave_reader; k++ ) {
- s_wave_reader[k].Read( s_block_size * (processed_count - 1) + (int)s_wave_read_offset_samples,
+ s_wave_reader[k].read( s_block_size * (processed_count - 1) + (int)s_wave_read_offset_samples,
s_block_size,
- out s_ptr_another_wave_l[k],
- out s_ptr_another_wave_r[k] );
+ ref s_ptr_another_wave_l[k],
+ ref s_ptr_another_wave_r[k] );
}
for ( int i = 0; i < s_block_size; i++ ) {
float l = s_wave_buffer_l[i] * amp_left;
@@ -316,7 +316,7 @@ namespace Boare.Lib.Media {
//byte* err = (byte*)ptr_err.ToPointer();
//System.Text.StringBuilder sb = new System.Text.StringBuilder( 260 );
string ret = "";
- windows.mciGetErrorStringA( msg, ret, 260 );
+ win32.mciGetErrorStringA( msg, ret, 260 );
/*int len = 260;
for ( int i = 1; i < 260; i++ ) {
if ( err[i] == '\0' ) {
@@ -349,7 +349,7 @@ namespace Boare.Lib.Media {
Console.WriteLine( " s_wave_fomratx.cbSize=" + s_wave_formatx.cbSize );
Console.WriteLine( " sizeof( WAVEHDR )=" + sizeof( WAVEHDR ) );
#endif
- s_wave_formatx.wFormatTag = windows.WAVE_FORMAT_PCM;
+ s_wave_formatx.wFormatTag = win32.WAVE_FORMAT_PCM;
s_wave_formatx.nChannels = 2;
s_wave_formatx.wBitsPerSample = 16;
s_wave_formatx.nBlockAlign = (ushort)(s_wave_formatx.nChannels * s_wave_formatx.wBitsPerSample / 8);
@@ -359,12 +359,12 @@ namespace Boare.Lib.Media {
s_wave_callback = new delegateWaveOutProc( wave_callback );
s_hwave_out = IntPtr.Zero;
Console.WriteLine( " calling waveOutOpen..." );
- uint ret = windows.waveOutOpen( ref s_hwave_out,
- windows.WAVE_MAPPER,
+ uint ret = win32.waveOutOpen( ref s_hwave_out,
+ win32.WAVE_MAPPER,
ref s_wave_formatx,
s_wave_callback,
- IntPtr.Zero,
- (uint)windows.CALLBACK_FUNCTION );
+ IntPtr.Zero,
+ (uint)win32.CALLBACK_FUNCTION );
Console.WriteLine( " ...done; ret=" + ret );
#if DEBUG
bocoree.debug.push_log( " s_hwave_out=0x" + Convert.ToString( s_hwave_out.ToInt32(), 16 ) );
@@ -377,13 +377,13 @@ namespace Boare.Lib.Media {
s_wave_header[k] = (WAVEHDR)Marshal.PtrToStructure( s_ptr_wave_header[k], typeof( WAVEHDR ) );
s_wave_header[k].lpData = s_ptr_wave[k];
s_wave_header[k].dwBufferLength = (uint)(sizeof( uint ) * s_block_size);
- s_wave_header[k].dwFlags = windows.WHDR_BEGINLOOP | windows.WHDR_ENDLOOP;
+ s_wave_header[k].dwFlags = win32.WHDR_BEGINLOOP | win32.WHDR_ENDLOOP;
s_wave_header[k].dwLoops = 1;
#if DEBUG
Console.WriteLine( "calling waveOutPrepareHeader..." );
#endif
- uint ret2 = windows.waveOutPrepareHeader( s_hwave_out, ref s_wave_header[k], (uint)sizeof( WAVEHDR ) );
+ uint ret2 = win32.waveOutPrepareHeader( s_hwave_out, ref s_wave_header[k], (uint)sizeof( WAVEHDR ) );
#if DEBUG
Console.WriteLine( "...done; ret2=" + ret2 );
#endif
@@ -428,18 +428,18 @@ namespace Boare.Lib.Media {
if ( s_playing ) {
MMTIME mmt = new MMTIME();
mmt.cb = (uint)sizeof( MMTIME );
- mmt.wType = windows.TIME_MS;
- uint ret = windows.waveOutGetPosition( s_hwave_out, ref mmt, (uint)sizeof( MMTIME ) );
+ mmt.wType = win32.TIME_MS;
+ uint ret = win32.waveOutGetPosition( s_hwave_out, ref mmt, (uint)sizeof( MMTIME ) );
#if DEBUG
bocoree.debug.push_log( " ret=" + ret );
#endif
float ms = 0.0f;
switch ( mmt.wType ) {
- case windows.TIME_MS:
+ case win32.TIME_MS:
return mmt.ms * 0.001f;
- case windows.TIME_SAMPLES:
+ case win32.TIME_SAMPLES:
return (float)mmt.sample / (float)s_wave_formatx.nSamplesPerSec;
- case windows.TIME_BYTES:
+ case win32.TIME_BYTES:
return (float)mmt.cb / (float)s_wave_formatx.nAvgBytesPerSec;
default:
return -1.0f;
@@ -456,7 +456,7 @@ namespace Boare.Lib.Media {
for ( int k = 0; k < _NUM_BUF; k++ ) {
s_wave_header[k].dwUser = new IntPtr( _NUM_BUF + k );
}
- windows.waveOutReset( s_hwave_out );
+ win32.waveOutReset( s_hwave_out );
uint zero = MAKELONG( 0, 0 );
for ( int k = 0; k < _NUM_BUF; k++ ) {
for ( int i = 0; i < s_block_size; i++ ) {
@@ -465,7 +465,7 @@ namespace Boare.Lib.Media {
}
}
for ( int i = 0; i < s_num_wave_reader; i++ ) {
- s_wave_reader[i].Close();
+ s_wave_reader[i].close();
}
}
@@ -500,7 +500,7 @@ namespace Boare.Lib.Media {
if ( s_wave_reader != null ) {
for ( int i = 0; i < s_num_wave_reader; i++ ) {
- s_wave_reader[i].Close();
+ s_wave_reader[i].close();
}
//delete [] s_wave_reader;
}
@@ -530,8 +530,8 @@ namespace Boare.Lib.Media {
name[k] = buf[k];
}
name[len] = '\0';*/
- s_wave_reader[i].Open( files[i] );
- int samples = s_wave_reader[i].TotalSamples;
+ s_wave_reader[i].open( files[i] );
+ int samples = s_wave_reader[i].getTotalSamples();
if ( samples > max_samples ) {
max_samples = samples;
}
@@ -560,14 +560,14 @@ namespace Boare.Lib.Media {
public void terminate() {
if ( s_hwave_out.ToInt32() != 0 ) {
- windows.waveOutReset( s_hwave_out );
+ win32.waveOutReset( s_hwave_out );
#if DEBUG
bocoree.debug.push_log( "waveplay::terminate; waveOutReset" );
#endif
for ( int k = 0; k < _NUM_BUF; k++ ) {
- windows.waveOutUnprepareHeader( s_hwave_out, ref s_wave_header[k], (uint)sizeof( WAVEHDR ) );
+ win32.waveOutUnprepareHeader( s_hwave_out, ref s_wave_header[k], (uint)sizeof( WAVEHDR ) );
}
- windows.waveOutClose( s_hwave_out );
+ win32.waveOutClose( s_hwave_out );
}
for ( int i = 0; i < _NUM_BUF; i++ ) {
if ( s_ptr_wave[i].ToInt32() != 0 ) {
diff --git a/trunk/Boare.Lib.Media/WaveReader.cs b/trunk/Boare.Lib.Media/WaveReader.cs
index 7f0bfcc..9394017 100644
--- a/trunk/Boare.Lib.Media/WaveReader.cs
+++ b/trunk/Boare.Lib.Media/WaveReader.cs
@@ -11,125 +11,254 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
+#if JAVA
+package org.kbinani.media;
+
+import java.io.*;
+import java.util.*;
+import org.kbinani.*;
+#else
using System;
-using System.IO;
-using System.Runtime.InteropServices;
+using bocoree;
+using bocoree.java.io;
namespace Boare.Lib.Media {
+ using boolean = System.Boolean;
+#endif
- public class WaveReader : IDisposable{
+#if JAVA
+ public class WaveReader {
+#else
+ public class WaveReader : IDisposable {
+#endif
private int m_channel;
private int m_byte_per_sample;
- private bool m_opened;
- private FileStream m_stream;
+ private boolean m_opened;
+ private RandomAccessFile m_stream;
private int m_total_samples;
+ private double m_amplify_left = 1.0;
+ private double m_amplify_right = 1.0;
+ ///
+ /// ファイル先頭から,dataチャンクまでのオフセット
+ ///
+ private int m_header_offset = 0x2e;
+ private Object m_tag = null;
+ private double m_offset_seconds = 0.0;
+ private int m_sample_per_sec;
public WaveReader() {
m_opened = false;
}
- public WaveReader( string file ) {
- Open( file );
+ public WaveReader( String file )
+#if JAVA
+ throws IOException, FileNotFoundException
+#endif
+ {
+ boolean ret = open( file );
+#if DEBUG
+ Console.WriteLine( "WaveReader#.ctor; file=" + file + "; ret=" + ret );
+#endif
}
+ public double getOffsetSeconds() {
+ return m_offset_seconds;
+ }
+
+ public void setOffsetSeconds( double value ) {
+ m_offset_seconds = value;
+ }
+
+ public Object getTag() {
+ return m_tag;
+ }
+
+ public void setTag( Object value ) {
+ m_tag = value;
+ }
+
+ public double getAmplifyLeft() {
+ return m_amplify_left;
+ }
+
+ public void setAmplifyLeft( double value ) {
+ m_amplify_left = value;
+ }
+
+ public double getAmplifyRight() {
+ return m_amplify_right;
+ }
+
+ public void setAmplifyRight( double value ) {
+ m_amplify_right = value;
+ }
+
+#if !JAVA
public void Dispose() {
- Close();
+ close();
}
+#endif
- public bool Open( string file ) {
+ public boolean open( String file )
+#if JAVA
+ throws IOException, FileNotFoundException
+#endif
+ {
if ( m_opened ) {
- m_stream.Close();
+ m_stream.close();
}
- m_stream = new FileStream( file, FileMode.Open, FileAccess.Read );
+ m_stream = new RandomAccessFile( file, "r" );
// RIFF
byte[] buf = new byte[4];
- m_stream.Read( buf, 0, 4 );
+ m_stream.read( buf, 0, 4 );
if ( buf[0] != 'R' || buf[1] != 'I' || buf[2] != 'F' || buf[3] != 'F' ) {
- m_stream.Close();
+ m_stream.close();
+#if DEBUG
+ Console.WriteLine( "WaveReader#Open; header error(RIFF)" );
+#endif
return false;
}
// ファイルサイズ - 8最後に記入
- m_stream.Read( buf, 0, 4 );
+ m_stream.read( buf, 0, 4 );
// WAVE
- m_stream.Read( buf, 0, 4 );
+ m_stream.read( buf, 0, 4 );
if ( buf[0] != 'W' || buf[1] != 'A' || buf[2] != 'V' || buf[3] != 'E' ) {
- m_stream.Close();
+ m_stream.close();
+#if DEBUG
+ Console.WriteLine( "WaveReader#Open; header error(WAVE)" );
+#endif
return false;
}
// fmt
- m_stream.Read( buf, 0, 4 );
+ m_stream.read( buf, 0, 4 );
if ( buf[0] != 'f' || buf[1] != 'm' || buf[2] != 't' || buf[3] != ' ' ) {
- m_stream.Close();
+ m_stream.close();
+#if DEBUG
+ Console.WriteLine( "WaveReader#Open; header error(fmt )" );
+#endif
return false;
}
// fmt チャンクのサイズ
- m_stream.Read( buf, 0, 4 );
+ m_stream.read( buf, 0, 4 );
+ int chunksize = (int)PortUtil.make_uint32_le( buf );
+ long fmt_chunk_end_location = m_stream.getFilePointer() + chunksize;
// format ID
- m_stream.Read( buf, 0, 2 );
+ m_stream.read( buf, 0, 2 );
// チャンネル数
- m_stream.Read( buf, 0, 2 );
+ m_stream.read( buf, 0, 2 );
m_channel = buf[1] << 8 | buf[0];
// サンプリングレート
- m_stream.Read( buf, 0, 4 );
+ m_stream.read( buf, 0, 4 );
+ m_sample_per_sec = (int)PortUtil.make_uint32_le( buf );
// データ速度
- m_stream.Read( buf, 0, 4 );
+ m_stream.read( buf, 0, 4 );
// ブロックサイズ
- m_stream.Read( buf, 0, 2 );
+ m_stream.read( buf, 0, 2 );
// サンプルあたりのビット数
- m_stream.Read( buf, 0, 2 );
+ m_stream.read( buf, 0, 2 );
int bit_per_sample = buf[1] << 8 | buf[0];
m_byte_per_sample = bit_per_sample / 8;
// 拡張部分
- m_stream.Read( buf, 0, 2 );
+ m_stream.seek( fmt_chunk_end_location );
+ //m_stream.Read( buf, 0, 2 );
// data
- m_stream.Read( buf, 0, 4 );
+ m_stream.read( buf, 0, 4 );
if ( buf[0] != 'd' || buf[1] != 'a' || buf[2] != 't' || buf[3] != 'a' ) {
- m_stream.Close();
+ m_stream.close();
+#if DEBUG
+ Console.WriteLine( "WaveReader#Open; header error (data)" );
+#endif
return false;
}
// size of data chunk
- m_stream.Read( buf, 0, 4 );
- int size = BitConverter.ToInt32( buf, 0 );
+ m_stream.read( buf, 0, 4 );
+ int size = (int)PortUtil.make_uint32_le( buf );
m_total_samples = size / (m_channel * m_byte_per_sample);
m_opened = true;
+ m_header_offset = (int)m_stream.getFilePointer();
return true;
}
- public int TotalSamples {
- get {
- return m_total_samples;
- }
+ public int getTotalSamples() {
+ return m_total_samples;
}
- public void Read( long start, int length, out double[] left, out double[] right ) {
- left = new double[length];
- right = new double[length];
+ public void read( long start, int length, double[] left, double[] right )
+#if JAVA
+ throws IOException
+#endif
+ {
+ //left = new double[length];
+ //right = new double[length];
if ( !m_opened ) {
return;
}
- long loc = 0x2e + m_byte_per_sample * m_channel * start;
- m_stream.Seek( loc, SeekOrigin.Begin );
+ int i_start = 0;
+ int i_end = length - 1;
+ long required_sample_start = start + (long)(m_offset_seconds * m_sample_per_sec);
+ long required_sample_end = required_sample_start + length;
+ // 第required_sample_startサンプルから,第required_sample_endサンプルまでの読み込みが要求された.
+ if ( required_sample_start < 0 ) {
+ i_start = -(int)required_sample_start + 1;
+ // 0 -> i_start - 1までは0で埋める
+ if ( i_start >= length ) {
+ // 全部0で埋める必要のある場合.
+ for ( int i = 0; i < length; i++ ) {
+ left[i] = 0.0;
+ right[i] = 0.0;
+ }
+ return;
+ } else {
+ for ( int i = 0; i < i_start; i++ ) {
+ left[i] = 0.0;
+ right[i] = 0.0;
+ }
+ }
+ m_stream.seek( m_header_offset );
+ } else {
+ long loc = m_header_offset + m_byte_per_sample * m_channel * required_sample_start;
+ m_stream.seek( loc );
+ }
+ if ( m_total_samples < required_sample_end ) {
+ i_end = length - 1 - (int)required_sample_end + m_total_samples;
+ // i_end + 1 -> length - 1までは0で埋める
+ if ( i_end < 0 ) {
+ // 全部0で埋める必要のある場合
+ for ( int i = 0; i < length; i++ ) {
+ left[i] = 0.0;
+ right[i] = 0.0;
+ }
+ return;
+ } else {
+ for ( int i = i_end + 1; i < length; i++ ) {
+ left[i] = 0.0;
+ right[i] = 0.0;
+ }
+ }
+ }
if ( m_byte_per_sample == 2 ) {
if ( m_channel == 2 ) {
byte[] buf = new byte[4];
- for ( int i = 0; i < length; i++ ) {
- int ret = m_stream.Read( buf, 0, 4 );
+ double coeff_left = m_amplify_left / 32768.0;
+ double coeff_right = m_amplify_right / 32768.0;
+ for ( int i = i_start; i <= i_end; i++ ) {
+ int ret = m_stream.read( buf, 0, 4 );
if ( ret < 4 ) {
for ( int j = i; j < length; j++ ) {
left[j] = 0.0f;
@@ -139,13 +268,14 @@ namespace Boare.Lib.Media {
}
short l = (short)(buf[0] | buf[1] << 8);
short r = (short)(buf[2] | buf[3] << 8);
- left[i] = l / 32768.0f;
- right[i] = r / 32768.0f;
+ left[i] = l * coeff_left;
+ right[i] = r * coeff_right;
}
} else {
byte[] buf = new byte[2];
- for ( int i = 0; i < length; i++ ) {
- int ret = m_stream.Read( buf, 0, 2 );
+ double coeff_left = m_amplify_left / 32768.0;
+ for ( int i = i_start; i <= i_end; i++ ) {
+ int ret = m_stream.read( buf, 0, 2 );
if ( ret < 2 ) {
for ( int j = i; j < length; j++ ) {
left[j] = 0.0f;
@@ -154,15 +284,17 @@ namespace Boare.Lib.Media {
break;
}
short l = (short)(buf[0] | buf[1] << 8);
- left[i] = l / 32768.0f;
+ left[i] = l * coeff_left;
right[i] = left[i];
}
}
} else {
if ( m_channel == 2 ) {
byte[] buf = new byte[2];
- for ( int i = 0; i < length; i++ ) {
- int ret = m_stream.Read( buf, 0, 2 );
+ double coeff_left = m_amplify_left / 64.0;
+ double coeff_right = m_amplify_right / 64.0;
+ for ( int i = i_start; i <= i_end; i++ ) {
+ int ret = m_stream.read( buf, 0, 2 );
if ( ret < 2 ) {
for ( int j = i; j < length; j++ ) {
left[j] = 0.0f;
@@ -170,13 +302,14 @@ namespace Boare.Lib.Media {
}
break;
}
- left[i] = (buf[0] - 64.0f) / 64.0f;
- right[i] = (buf[1] - 64.0f) / 64.0f;
+ left[i] = (buf[0] - 64.0f) * coeff_left;
+ right[i] = (buf[1] - 64.0f) * coeff_right;
}
} else {
byte[] buf = new byte[1];
- for ( int i = 0; i < length; i++ ) {
- int ret = m_stream.Read( buf, 0, 1 );
+ double coeff_left = m_amplify_left / 64.0;
+ for ( int i = i_start; i <= i_end; i++ ) {
+ int ret = m_stream.read( buf, 0, 1 );
if ( ret < 1 ) {
for ( int j = i; j < length; j++ ) {
left[j] = 0.0f;
@@ -184,104 +317,161 @@ namespace Boare.Lib.Media {
}
break;
}
- left[i] = (buf[0] - 64.0f) / 64.0f;
+ left[i] = (buf[0] - 64.0f) * coeff_left;
right[i] = left[i];
}
}
}
}
- public void Read( long start, int length, out float[] left, out float[] right ) {
- left = new float[length];
- right = new float[length];
+ public void read( long start, int length, ByRef left, ByRef right )
+#if JAVA
+ throws IOException
+#endif
+ {
+ left.value = new float[length];
+ right.value = new float[length];
if ( !m_opened ) {
return;
}
- long loc = 0x2e + m_byte_per_sample * m_channel * start;
- m_stream.Seek( loc, SeekOrigin.Begin );
+ int i_start = 0;
+ int i_end = length;
+ long required_sample_start = start + (long)(m_offset_seconds * m_sample_per_sec);
+ long required_sample_end = required_sample_start + length;
+ // 第required_sample_startサンプルから,第required_sample_endサンプルまでの読み込みが要求された.
+ if ( required_sample_start < 0 ) {
+ i_start = -(int)required_sample_start + 1;
+ // 0 -> i_start - 1までは0で埋める
+ for ( int i = 0; i < i_start; i++ ) {
+ left.value[i] = 0.0f;
+ right.value[i] = 0.0f;
+ }
+ m_stream.seek( m_header_offset );
+ } else {
+ long loc = m_header_offset + m_byte_per_sample * m_channel * required_sample_start;
+ m_stream.seek( loc );
+ }
+ if ( m_total_samples < required_sample_end ) {
+ i_end = length - 1 - (int)required_sample_end + m_total_samples;
+ // i_end + 1 -> length - 1までは0で埋める
+ for ( int i = i_end + 1; i < length; i++ ) {
+ left.value[i] = 0.0f;
+ right.value[i] = 0.0f;
+ }
+ }
if ( m_byte_per_sample == 2 ) {
if ( m_channel == 2 ) {
byte[] buf = new byte[4];
+ float coeff_left = (float)(m_amplify_left / 32768.0f);
+ float coeff_right = (float)(m_amplify_right / 32768.0f);
for ( int i = 0; i < length; i++ ) {
- int ret = m_stream.Read( buf, 0, 4 );
+ int ret = m_stream.read( buf, 0, 4 );
if ( ret < 4 ) {
for ( int j = i; j < length; j++ ) {
- left[j] = 0.0f;
- right[j] = 0.0f;
+ left.value[j] = 0.0f;
+ right.value[j] = 0.0f;
}
break;
}
short l = (short)(buf[0] | buf[1] << 8);
short r = (short)(buf[2] | buf[3] << 8);
- left[i] = l / 32768.0f;
- right[i] = r / 32768.0f;
+ left.value[i] = l * coeff_left;
+ right.value[i] = r * coeff_right;
}
} else {
byte[] buf = new byte[2];
+ float coeff_left = (float)(m_amplify_left / 32768.0f);
for ( int i = 0; i < length; i++ ) {
- int ret = m_stream.Read( buf, 0, 2 );
+ int ret = m_stream.read( buf, 0, 2 );
if ( ret < 2 ) {
for ( int j = i; j < length; j++ ) {
- left[j] = 0.0f;
- right[j] = 0.0f;
+ left.value[j] = 0.0f;
+ right.value[j] = 0.0f;
}
break;
}
short l = (short)(buf[0] | buf[1] << 8);
- left[i] = l / 32768.0f;
- right[i] = left[i];
+ left.value[i] = l * coeff_left;
+ right.value[i] = left.value[i];
}
}
} else {
if ( m_channel == 2 ) {
byte[] buf = new byte[2];
+ float coeff_left = (float)(m_amplify_left / 64.0f);
+ float coeff_right = (float)(m_amplify_right / 64.0f);
for ( int i = 0; i < length; i++ ) {
- int ret = m_stream.Read( buf, 0, 2 );
+ int ret = m_stream.read( buf, 0, 2 );
if ( ret < 2 ) {
for ( int j = i; j < length; j++ ) {
- left[j] = 0.0f;
- right[j] = 0.0f;
+ left.value[j] = 0.0f;
+ right.value[j] = 0.0f;
}
break;
}
- left[i] = (buf[0] - 64.0f) / 64.0f;
- right[i] = (buf[1] - 64.0f) / 64.0f;
+ left.value[i] = (buf[0] - 64.0f) * coeff_left;
+ right.value[i] = (buf[1] - 64.0f) * coeff_right;
}
} else {
byte[] buf = new byte[1];
+ float coeff_left = (float)(m_amplify_left / 64.0f);
for ( int i = 0; i < length; i++ ) {
- int ret = m_stream.Read( buf, 0, 1 );
+ int ret = m_stream.read( buf, 0, 1 );
if ( ret < 1 ) {
for ( int j = i; j < length; j++ ) {
- left[j] = 0.0f;
- right[j] = 0.0f;
+ left.value[j] = 0.0f;
+ right.value[j] = 0.0f;
}
break;
}
- left[i] = (buf[0] - 64.0f) / 64.0f;
- right[i] = left[i];
+ left.value[i] = (buf[0] - 64.0f) * coeff_left;
+ right.value[i] = left.value[i];
}
}
}
}
- public unsafe void Read( long start, int length, out IntPtr ptr_left, out IntPtr ptr_right ) {
- ptr_left = Marshal.AllocHGlobal( sizeof( float ) * length );
- ptr_right = Marshal.AllocHGlobal( sizeof( float ) * length );
+#if !JAVA
+ public unsafe void read( long start, int length, ref IntPtr ptr_left, ref IntPtr ptr_right ) {
float* left = (float*)ptr_left.ToPointer();
float* right = (float*)ptr_right.ToPointer();
if ( !m_opened ) {
return;
}
- long loc = 0x2e + m_byte_per_sample * m_channel * start;
- m_stream.Seek( loc, SeekOrigin.Begin );
+ int i_start = 0;
+ int i_end = length;
+ long required_sample_start = start + (long)(m_offset_seconds * m_sample_per_sec);
+ long required_sample_end = required_sample_start + length;
+ // 第required_sample_startサンプルから,第required_sample_endサンプルまでの読み込みが要求された.
+ if ( required_sample_start < 0 ) {
+ i_start = -(int)required_sample_start + 1;
+ // 0 -> i_start - 1までは0で埋める
+ for ( int i = 0; i < i_start; i++ ) {
+ left[i] = 0.0f;
+ right[i] = 0.0f;
+ }
+ m_stream.seek( m_header_offset );
+ } else {
+ long loc = m_header_offset + m_byte_per_sample * m_channel * required_sample_start;
+ m_stream.seek( loc );
+ }
+ if ( m_total_samples < required_sample_end ) {
+ i_end = length - 1 - (int)required_sample_end + m_total_samples;
+ // i_end + 1 -> length - 1までは0で埋める
+ for ( int i = i_end + 1; i < length; i++ ) {
+ left[i] = 0.0f;
+ right[i] = 0.0f;
+ }
+ }
if ( m_byte_per_sample == 2 ) {
if ( m_channel == 2 ) {
byte[] buf = new byte[4];
+ float coeff_left = (float)(m_amplify_left / 32768.0f);
+ float coeff_right = (float)(m_amplify_right / 32768.0f);
for ( int i = 0; i < length; i++ ) {
- int ret = m_stream.Read( buf, 0, 4 );
+ int ret = m_stream.read( buf, 0, 4 );
if ( ret < 4 ) {
for ( int j = i; j < length; j++ ) {
left[j] = 0.0f;
@@ -291,13 +481,14 @@ namespace Boare.Lib.Media {
}
short l = (short)(buf[0] | buf[1] << 8);
short r = (short)(buf[2] | buf[3] << 8);
- left[i] = l / 32768.0f;
- right[i] = r / 32768.0f;
+ left[i] = l * coeff_left;
+ right[i] = r * coeff_right;
}
} else {
byte[] buf = new byte[2];
+ float coeff_left = (float)(m_amplify_left / 32768.0f);
for ( int i = 0; i < length; i++ ) {
- int ret = m_stream.Read( buf, 0, 2 );
+ int ret = m_stream.read( buf, 0, 2 );
if ( ret < 2 ) {
for ( int j = i; j < length; j++ ) {
left[j] = 0.0f;
@@ -306,15 +497,17 @@ namespace Boare.Lib.Media {
break;
}
short l = (short)(buf[0] | buf[1] << 8);
- left[i] = l / 32768.0f;
+ left[i] = l * coeff_left;
right[i] = left[i];
}
}
} else {
if ( m_channel == 2 ) {
byte[] buf = new byte[2];
+ float coeff_left = (float)(m_amplify_left / 64.0f);
+ float coeff_right = (float)(m_amplify_right / 64.0f);
for ( int i = 0; i < length; i++ ) {
- int ret = m_stream.Read( buf, 0, 2 );
+ int ret = m_stream.read( buf, 0, 2 );
if ( ret < 2 ) {
for ( int j = i; j < length; j++ ) {
left[j] = 0.0f;
@@ -322,13 +515,14 @@ namespace Boare.Lib.Media {
}
break;
}
- left[i] = (buf[0] - 64.0f) / 64.0f;
- right[i] = (buf[1] - 64.0f) / 64.0f;
+ left[i] = (buf[0] - 64.0f) * coeff_left;
+ right[i] = (buf[1] - 64.0f) * coeff_right;
}
} else {
byte[] buf = new byte[1];
+ float coeff_left = (float)(m_amplify_left / 64.0f);
for ( int i = 0; i < length; i++ ) {
- int ret = m_stream.Read( buf, 0, 1 );
+ int ret = m_stream.read( buf, 0, 1 );
if ( ret < 1 ) {
for ( int j = i; j < length; j++ ) {
left[j] = 0.0f;
@@ -336,24 +530,33 @@ namespace Boare.Lib.Media {
}
break;
}
- left[i] = (buf[0] - 64.0f) / 64.0f;
+ left[i] = (buf[0] - 64.0f) * coeff_left;
right[i] = left[i];
}
}
}
}
+#endif
- public void Close() {
+ public void close()
+#if JAVA
+ throws IOException
+#endif
+ {
m_opened = false;
if ( m_stream != null ) {
- m_stream.Close();
+ m_stream.close();
m_stream = null;
}
}
+#if !JAVA
~WaveReader() {
- Close();
+ close();
}
+#endif
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Media/WaveWriter.cs b/trunk/Boare.Lib.Media/WaveWriter.cs
index e94795d..52a3101 100644
--- a/trunk/Boare.Lib.Media/WaveWriter.cs
+++ b/trunk/Boare.Lib.Media/WaveWriter.cs
@@ -11,374 +11,404 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
+#if JAVA
+package org.kbinani.media;
+
+import java.io.*;
+import org.kbinani.*;
+#else
using System;
-using System.IO;
+using bocoree;
+using bocoree.java.io;
namespace Boare.Lib.Media {
+#endif
- public class WaveWriter : IDisposable {
- private WaveChannel m_channel;
- private ushort m_bit_per_sample;
- private uint m_sample_rate;
- private uint m_total_samples = 0;
- private FileStream m_stream = null;
- private string m_path = "";
+#if JAVA
+ public class WaveWriter{
+#else
+ public class WaveWriter : IDisposable{
+#endif
+ private int m_channel = 1;
+ private int m_bit_per_sample;
+ private int m_sample_rate;
+ private int m_total_samples = 0;
+ private RandomAccessFile m_stream = null;
+ private String m_path = "";
- public WaveWriter( string path ) :
- this ( path, WaveChannel.Stereo, 16, 44100 ) {
+ public WaveWriter( String path )
+#if JAVA
+
+ throws IOException
+ {
+ this ( path, 2, 16, 44100 );
+#else
+ : this( path, 2, 16, 44100 ) {
+#endif
}
- public WaveWriter( string path, WaveChannel channel, ushort bit_per_sample, uint sample_rate ) {
+ public WaveWriter( String path, int channel, int bit_per_sample, int sample_rate )
+#if JAVA
+ throws IOException
+#endif
+ {
m_path = path;
- m_stream = new FileStream( m_path, FileMode.Create, FileAccess.Write );
+ m_stream = new RandomAccessFile( m_path, "rw" );
m_channel = channel;
m_bit_per_sample = bit_per_sample;
m_sample_rate = sample_rate;
m_total_samples = 0;
- WriteHeader();
+ writeHeader();
}
+#if !JAVA
+ public void Dispose() {
+ close();
+ }
+#endif
+
///
/// Writes header of WAVE file
///
- private void WriteHeader() {
+ private void writeHeader()
+#if JAVA
+ throws IOException
+#endif
+ {
// RIFF
- m_stream.WriteByte( 0x52 ); // loc=0x00
- m_stream.WriteByte( 0x49 );
- m_stream.WriteByte( 0x46 );
- m_stream.WriteByte( 0x46 );
+ m_stream.writeByte( 0x52 ); // loc=0x00
+ m_stream.writeByte( 0x49 );
+ m_stream.writeByte( 0x46 );
+ m_stream.writeByte( 0x46 );
// ファイルサイズ - 8最後に記入
- m_stream.WriteByte( 0x00 ); // loc=0x04
- m_stream.WriteByte( 0x00 );
- m_stream.WriteByte( 0x00 );
- m_stream.WriteByte( 0x00 );
+ m_stream.writeByte( 0x00 ); // loc=0x04
+ m_stream.writeByte( 0x00 );
+ m_stream.writeByte( 0x00 );
+ m_stream.writeByte( 0x00 );
// WAVE
- m_stream.WriteByte( 0x57 ); // loc=0x08
- m_stream.WriteByte( 0x41 );
- m_stream.WriteByte( 0x56 );
- m_stream.WriteByte( 0x45 );
+ m_stream.writeByte( 0x57 ); // loc=0x08
+ m_stream.writeByte( 0x41 );
+ m_stream.writeByte( 0x56 );
+ m_stream.writeByte( 0x45 );
// fmt
- m_stream.WriteByte( 0x66 ); // loc=0x0c
- m_stream.WriteByte( 0x6d );
- m_stream.WriteByte( 0x74 );
- m_stream.WriteByte( 0x20 );
+ m_stream.writeByte( 0x66 ); // loc=0x0c
+ m_stream.writeByte( 0x6d );
+ m_stream.writeByte( 0x74 );
+ m_stream.writeByte( 0x20 );
// fmt チャンクのサイズ
- m_stream.WriteByte( 0x12 ); // loc=0x10
- m_stream.WriteByte( 0x00 );
- m_stream.WriteByte( 0x00 );
- m_stream.WriteByte( 0x00 );
+ m_stream.writeByte( 0x12 ); // loc=0x10
+ m_stream.writeByte( 0x00 );
+ m_stream.writeByte( 0x00 );
+ m_stream.writeByte( 0x00 );
// format ID
- m_stream.WriteByte( 0x01 ); // loc=0x14
- m_stream.WriteByte( 0x00 );
+ m_stream.writeByte( 0x01 ); // loc=0x14
+ m_stream.writeByte( 0x00 );
// チャンネル数
- if ( m_channel == WaveChannel.Monoral ) {
- m_stream.WriteByte( 0x01 ); // loc=0x16
- m_stream.WriteByte( 0x00 );
+ if ( m_channel == 1 ) {
+ m_stream.writeByte( 0x01 ); // loc=0x16
+ m_stream.writeByte( 0x00 );
} else {
- m_stream.WriteByte( 0x02 ); //loc=0x16
- m_stream.WriteByte( 0x00 );
+ m_stream.writeByte( 0x02 ); //loc=0x16
+ m_stream.writeByte( 0x00 );
}
// サンプリングレート
- byte[] buf = BitConverter.GetBytes( m_sample_rate );
- WriteByteArray( m_stream, buf, 4 ); // 0x18
+ byte[] buf = PortUtil.getbytes_uint32_le( m_sample_rate );
+ writeByteArray( m_stream, buf, 4 ); // 0x18
// データ速度
- ushort block_size = (ushort)(m_bit_per_sample / 8 * (int)m_channel);
- uint data_rate = m_sample_rate * block_size;
- buf = BitConverter.GetBytes( data_rate );
- WriteByteArray( m_stream, buf, 4 );//loc=0x1c
+ int block_size = (int)(m_bit_per_sample / 8 * (int)m_channel);
+ int data_rate = m_sample_rate * block_size;
+ buf = PortUtil.getbytes_uint32_le( data_rate );
+ writeByteArray( m_stream, buf, 4 );//loc=0x1c
// ブロックサイズ
- buf = BitConverter.GetBytes( block_size );
- WriteByteArray( m_stream, buf, 2 ); //0x20
+ buf = PortUtil.getbytes_uint16_le( block_size );
+ writeByteArray( m_stream, buf, 2 ); //0x20
// サンプルあたりのビット数
- buf = BitConverter.GetBytes( m_bit_per_sample );
- WriteByteArray( m_stream, buf, 2 ); //loc=0x22
+ buf = PortUtil.getbytes_uint16_le( m_bit_per_sample );
+ writeByteArray( m_stream, buf, 2 ); //loc=0x22
// 拡張部分
- m_stream.WriteByte( 0x00 ); //loc=0x24
- m_stream.WriteByte( 0x00 );
+ m_stream.writeByte( 0x00 ); //loc=0x24
+ m_stream.writeByte( 0x00 );
// data
- m_stream.WriteByte( 0x64 ); //loc=0x26
- m_stream.WriteByte( 0x61 );
- m_stream.WriteByte( 0x74 );
- m_stream.WriteByte( 0x61 );
+ m_stream.writeByte( 0x64 ); //loc=0x26
+ m_stream.writeByte( 0x61 );
+ m_stream.writeByte( 0x74 );
+ m_stream.writeByte( 0x61 );
// size of data chunk
- uint size = block_size * m_total_samples;
- buf = BitConverter.GetBytes( size );
- WriteByteArray( m_stream, buf, 4 );
+ int size = block_size * m_total_samples;
+ buf = PortUtil.getbytes_uint32_le( size );
+ writeByteArray( m_stream, buf, 4 );
}
- public void Close(){
+ public void close()
+#if JAVA
+ throws IOException
+#endif
+ {
if ( m_stream != null ) {
// 最後にWAVEチャンクのサイズ
- uint position = (uint)m_stream.Position;
- m_stream.Seek( 4, SeekOrigin.Begin );
- byte[] buf = BitConverter.GetBytes( position - 8 );
- WriteByteArray( m_stream, buf, 4 );
+ int position = (int)m_stream.getFilePointer();
+ m_stream.seek( 4 );
+ byte[] buf = PortUtil.getbytes_uint32_le( position - 8 );
+ writeByteArray( m_stream, buf, 4 );
// size of data chunk
- ushort block_size = (ushort)(m_bit_per_sample / 8 * (int)m_channel);
- uint size = block_size * m_total_samples;
- m_stream.Seek( 42, SeekOrigin.Begin );
- buf = BitConverter.GetBytes( size );
- WriteByteArray( m_stream, buf, 4 );
+ int block_size = (int)(m_bit_per_sample / 8 * (int)m_channel);
+ int size = block_size * m_total_samples;
+ m_stream.seek( 42 );
+ buf = PortUtil.getbytes_uint32_le( size );
+ writeByteArray( m_stream, buf, 4 );
- m_stream.Close();
+ m_stream.close();
}
}
- public uint SampleRate {
- get {
- return m_sample_rate;
- }
+ public int getSampleRate(){
+ return m_sample_rate;
}
- public void Dispose() {
- Close();
- }
-
- public void Append( float[] L ) {
+ public void append( float[] L )
+#if JAVA
+ throws IOException
+#endif
+ {
int total = L.Length;
if ( m_bit_per_sample == 8 ) {
- if ( m_channel == WaveChannel.Monoral ) {
+ if ( m_channel == 1 ) {
for ( int i = 0; i < total; i++ ) {
- m_stream.WriteByte( (byte)((L[i] + 1.0f) * 127.5f) );
+ m_stream.writeByte( (int)((L[i] + 1.0f) * 127.5f) );
}
} else {
for ( int i = 0; i < total; i++ ) {
- byte b = (byte)((L[i] + 1.0f) * 127.5f);
- m_stream.WriteByte( b );
- m_stream.WriteByte( b );
+ int b = (int)((L[i] + 1.0f) * 127.5f);
+ m_stream.writeByte( b );
+ m_stream.writeByte( b );
}
}
} else {
byte[] buf;
- if ( m_channel == WaveChannel.Monoral ) {
+ if ( m_channel == 1 ) {
for ( int i = 0; i < total; i++ ) {
- buf = BitConverter.GetBytes( (short)(L[i] * 32768f) );
- WriteByteArray( m_stream, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( (short)(L[i] * 32768f) );
+ writeByteArray( m_stream, buf, 2 );
}
} else {
for ( int i = 0; i < total; i++ ) {
- buf = BitConverter.GetBytes( (short)(L[i] * 32768f) );
- WriteByteArray( m_stream, buf, 2 );
- WriteByteArray( m_stream, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( (short)(L[i] * 32768f) );
+ writeByteArray( m_stream, buf, 2 );
+ writeByteArray( m_stream, buf, 2 );
}
}
}
- m_total_samples += (uint)total;
+ m_total_samples += (int)total;
}
- public void Append( double[] L ) {
+ public void append( double[] L )
+#if JAVA
+ throws IOException
+#endif
+ {
int total = L.Length;
if ( m_bit_per_sample == 8 ) {
- if ( m_channel == WaveChannel.Monoral ) {
+ if ( m_channel == 1 ) {
for ( int i = 0; i < total; i++ ) {
- m_stream.WriteByte( (byte)((L[i] + 1.0) * 127.5) );
+ m_stream.writeByte( (int)((L[i] + 1.0) * 127.5) );
}
} else {
for ( int i = 0; i < total; i++ ) {
- byte b = (byte)((L[i] + 1.0) * 127.5);
- m_stream.WriteByte( b );
- m_stream.WriteByte( b );
+ int b = (int)((L[i] + 1.0) * 127.5);
+ m_stream.writeByte( b );
+ m_stream.writeByte( b );
}
}
} else {
byte[] buf;
- if ( m_channel == WaveChannel.Monoral ) {
+ if ( m_channel == 1 ) {
for ( int i = 0; i < total; i++ ) {
- buf = BitConverter.GetBytes( (short)(L[i] * 32768.0) );
- WriteByteArray( m_stream, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( (short)(L[i] * 32768.0) );
+ writeByteArray( m_stream, buf, 2 );
}
} else {
for ( int i = 0; i < total; i++ ) {
- buf = BitConverter.GetBytes( (short)(L[i] * 32768.0) );
- WriteByteArray( m_stream, buf, 2 );
- WriteByteArray( m_stream, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( (short)(L[i] * 32768.0) );
+ writeByteArray( m_stream, buf, 2 );
+ writeByteArray( m_stream, buf, 2 );
}
}
}
- m_total_samples += (uint)total;
+ m_total_samples += (int)total;
}
- public void Append( float[] L, float[] R ) {
+ public void append( float[] L, float[] R )
+#if JAVA
+ throws IOException
+#endif
+ {
int total = Math.Min( L.Length, R.Length );
if ( m_bit_per_sample == 8 ) {
- if ( m_channel == WaveChannel.Monoral ) {
+ if ( m_channel == 1 ) {
for ( int i = 0; i < total; i++ ) {
- m_stream.WriteByte( (byte)((L[i] + R[i] + 2.0f) * 63.75f) );
+ m_stream.writeByte( (byte)((L[i] + R[i] + 2.0f) * 63.75f) );
}
} else {
for ( int i = 0; i < total; i++ ) {
- m_stream.WriteByte( (byte)((L[i] + 1.0f) * 127.5f) );
- m_stream.WriteByte( (byte)((R[i] + 1.0f) * 127.5f) );
+ m_stream.writeByte( (byte)((L[i] + 1.0f) * 127.5f) );
+ m_stream.writeByte( (byte)((R[i] + 1.0f) * 127.5f) );
}
}
} else {
byte[] buf;
- if ( m_channel == WaveChannel.Monoral ) {
+ if ( m_channel == 1 ) {
for ( int i = 0; i < total; i++ ) {
- buf = BitConverter.GetBytes( (short)((L[i] + R[i]) * 16384f) );
- WriteByteArray( m_stream, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( (short)((L[i] + R[i]) * 16384f) );
+ writeByteArray( m_stream, buf, 2 );
}
} else {
for ( int i = 0; i < total; i++ ) {
- buf = BitConverter.GetBytes( (short)(L[i] * 32768f) );
- WriteByteArray( m_stream, buf, 2 );
- buf = BitConverter.GetBytes( (short)(R[i] * 32768f) );
- WriteByteArray( m_stream, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( (short)(L[i] * 32768f) );
+ writeByteArray( m_stream, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( (short)(R[i] * 32768f) );
+ writeByteArray( m_stream, buf, 2 );
}
}
}
- m_total_samples += (uint)total;
+ m_total_samples += (int)total;
}
- public unsafe void Append( float* L, float* R, int length ) {
- if ( m_bit_per_sample == 8 ) {
- if ( m_channel == WaveChannel.Monoral ) {
- for ( int i = 0; i < length; i++ ) {
- m_stream.WriteByte( (byte)((L[i] + R[i] + 2.0f) * 63.75f) );
- }
- } else {
- for ( int i = 0; i < length; i++ ) {
- m_stream.WriteByte( (byte)((L[i] + 1.0f) * 127.5f) );
- m_stream.WriteByte( (byte)((R[i] + 1.0f) * 127.5f) );
- }
- }
- } else {
- byte[] buf;
- if ( m_channel == WaveChannel.Monoral ) {
- for ( int i = 0; i < length; i++ ) {
- buf = BitConverter.GetBytes( (short)((L[i] + R[i]) * 16384f) );
- WriteByteArray( m_stream, buf, 2 );
- }
- } else {
- for ( int i = 0; i < length; i++ ) {
- buf = BitConverter.GetBytes( (short)(L[i] * 32768f) );
- WriteByteArray( m_stream, buf, 2 );
- buf = BitConverter.GetBytes( (short)(R[i] * 32768f) );
- WriteByteArray( m_stream, buf, 2 );
- }
- }
- }
- m_total_samples += (uint)length;
- }
-
- public void Append( double[] L, double[] R ) {
+ public void append( double[] L, double[] R )
+#if JAVA
+ throws IOException
+#endif
+ {
int total = Math.Min( L.Length, R.Length );
if ( m_bit_per_sample == 8 ) {
- if ( m_channel == WaveChannel.Monoral ) {
+ if ( m_channel == 1 ) {
for ( int i = 0; i < total; i++ ) {
- m_stream.WriteByte( (byte)((L[i] + R[i] + 2.0) * 63.75) );
+ m_stream.writeByte( (int)((L[i] + R[i] + 2.0) * 63.75) );
}
} else {
for ( int i = 0; i < total; i++ ) {
- m_stream.WriteByte( (byte)((L[i] + 1.0) * 127.5) );
- m_stream.WriteByte( (byte)((R[i] + 1.0) * 127.5) );
+ m_stream.writeByte( (int)((L[i] + 1.0) * 127.5) );
+ m_stream.writeByte( (int)((R[i] + 1.0) * 127.5) );
}
}
} else {
byte[] buf;
- if ( m_channel == WaveChannel.Monoral ) {
+ if ( m_channel == 1 ) {
for ( int i = 0; i < total; i++ ) {
- buf = BitConverter.GetBytes( (short)((L[i] + R[i]) * 16384.0) );
- WriteByteArray( m_stream, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( (short)((L[i] + R[i]) * 16384.0) );
+ writeByteArray( m_stream, buf, 2 );
}
} else {
for ( int i = 0; i < total; i++ ) {
- buf = BitConverter.GetBytes( (short)(L[i] * 32768.0) );
- WriteByteArray( m_stream, buf, 2 );
- buf = BitConverter.GetBytes( (short)(R[i] * 32768.0) );
- WriteByteArray( m_stream, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( (short)(L[i] * 32768.0) );
+ writeByteArray( m_stream, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( (short)(R[i] * 32768.0) );
+ writeByteArray( m_stream, buf, 2 );
}
}
}
- m_total_samples += (uint)total;
+ m_total_samples += (int)total;
}
- public void Append( byte[] L, byte[] R ) {
+ public void append( byte[] L, byte[] R )
+#if JAVA
+ throws IOException
+#endif
+ {
int total = Math.Min( L.Length, R.Length );
if ( m_bit_per_sample == 8 ) {
- if ( m_channel == WaveChannel.Monoral ) {
+ if ( m_channel == 1 ) {
for ( int i = 0; i < total; i++ ) {
- m_stream.WriteByte( (byte)((L[i] + R[i]) / 2) );
+ m_stream.writeByte( 0xff & ((L[i] + R[i]) / 2) );
}
} else {
for ( int i = 0; i < total; i++ ) {
- m_stream.WriteByte( L[i] );
- m_stream.WriteByte( R[i] );
+ m_stream.writeByte( 0xff & L[i] );
+ m_stream.writeByte( 0xff & R[i] );
}
}
} else {
byte[] buf;
- if ( m_channel == WaveChannel.Monoral ) {
+ if ( m_channel == 1 ) {
for ( int i = 0; i < total; i++ ) {
- buf = BitConverter.GetBytes( (short)((L[i] + R[i]) * 128.5f - 32768f) );
- WriteByteArray( m_stream, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( (short)((L[i] + R[i]) * 128.5f - 32768f) );
+ writeByteArray( m_stream, buf, 2 );
}
} else {
for ( int i = 0; i < total; i++ ) {
- buf = BitConverter.GetBytes( (short)(L[i] * 257f - 32768f) );
- WriteByteArray( m_stream, buf, 2 );
- buf = BitConverter.GetBytes( (short)(R[i] * 257f - 32768f) );
- WriteByteArray( m_stream, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( (short)(L[i] * 257f - 32768f) );
+ writeByteArray( m_stream, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( (short)(R[i] * 257f - 32768f) );
+ writeByteArray( m_stream, buf, 2 );
}
}
}
- m_total_samples += (uint)total;
+ m_total_samples += (int)total;
}
- public void Append( short[] L, short[] R ) {
+ public void append( short[] L, short[] R )
+#if JAVA
+ throws IOException
+#endif
+ {
int total = Math.Min( L.Length, R.Length );
if ( m_bit_per_sample == 8 ) {
- if ( m_channel == WaveChannel.Monoral ) {
+ if ( m_channel == 1 ) {
for ( int i = 0; i < total; i++ ) {
- m_stream.WriteByte( (byte)(((L[i] + R[i]) / 2f + 32768f) / 255f) );
+ m_stream.writeByte( (int)(((L[i] + R[i]) / 2f + 32768f) / 255f) );
}
} else {
for ( int i = 0; i < total; i++ ) {
- m_stream.WriteByte( (byte)((L[i] + 32768f) / 255f) );
- m_stream.WriteByte( (byte)((R[i] + 32768f) / 255f) );
+ m_stream.writeByte( (int)((L[i] + 32768f) / 255f) );
+ m_stream.writeByte( (int)((R[i] + 32768f) / 255f) );
}
}
} else {
byte[] buf;
- if ( m_channel == WaveChannel.Monoral ) {
+ if ( m_channel == 1 ) {
for ( int i = 0; i < total; i++ ) {
- buf = BitConverter.GetBytes( (L[i] + R[i]) / 2 );
- WriteByteArray( m_stream, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( (short)((L[i] + R[i]) / 2) );
+ writeByteArray( m_stream, buf, 2 );
}
} else {
for ( int i = 0; i < total; i++ ) {
- buf = BitConverter.GetBytes( L[i] );
- WriteByteArray( m_stream, buf, 2 );
- buf = BitConverter.GetBytes( R[i] );
- WriteByteArray( m_stream, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( L[i] );
+ writeByteArray( m_stream, buf, 2 );
+ buf = PortUtil.getbytes_int16_le( R[i] );
+ writeByteArray( m_stream, buf, 2 );
}
}
}
- m_total_samples += (uint)total;
+ m_total_samples += (int)total;
}
- private static void WriteByteArray( FileStream fs, byte[] dat, int limit ) {
- fs.Write( dat, 0, (dat.Length > limit) ? limit : dat.Length );
+ private static void writeByteArray( RandomAccessFile fs, byte[] dat, int limit )
+#if JAVA
+ throws IOException
+#endif
+ {
+ fs.write( dat, 0, (dat.Length > limit) ? limit : dat.Length );
if ( dat.Length < limit ) {
for ( int i = 0; i < limit - dat.Length; i++ ) {
- fs.WriteByte( 0x00 );
+ fs.writeByte( 0x00 );
}
}
}
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/AttackConfig.cs b/trunk/Boare.Lib.Vsq/AttackConfig.cs
index 58fb615..f18f6f3 100644
--- a/trunk/Boare.Lib.Vsq/AttackConfig.cs
+++ b/trunk/Boare.Lib.Vsq/AttackConfig.cs
@@ -12,13 +12,14 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#if JAVA
-package com.boare.vsq;
+package org.kbinani.vsq;
+
import java.io.*;
+import org.kbinani.*;
#else
using System;
-using System.IO;
-
using bocoree;
+using bocoree.java.io;
namespace Boare.Lib.Vsq {
#endif
@@ -34,12 +35,30 @@ namespace Boare.Lib.Vsq {
contents = new NoteHeadHandle();
}
+#if JAVA
+ public String toString(){
+#else
+ public override string ToString() {
+#endif
+ if ( contents != null ) {
+ return contents.Caption;
+ } else {
+#if JAVA
+ return super.toString();
+#else
+ return base.ToString();
+#endif
+ }
+ }
+
public void parseAic( String aic_file ) {
- using ( StreamReader sr = new StreamReader( aic_file ) ) {
+ BufferedReader sr = null;
+ try {
+ sr = new BufferedReader( new FileReader( aic_file ) );
String line;
String current_entry = "";
String articulation = "";
- while ( (line = sr.ReadLine()) != null ) {
+ while ( (line = sr.readLine()) != null ) {
if ( line.StartsWith( "[" ) ) {
current_entry = line;
continue;
@@ -47,7 +66,7 @@ namespace Boare.Lib.Vsq {
continue;
}
- String[] spl = line.Split( new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries );
+ String[] spl = PortUtil.splitString( line, new char[] { '=' }, true );
if ( spl.Length < 2 ) {
continue;
}
@@ -60,21 +79,33 @@ namespace Boare.Lib.Vsq {
} else if ( current_entry.Equals( "[Parameter]" ) ) {
if ( spl[0].Equals( "Length" ) ) {
try {
- this.contents.Length = int.Parse( spl[1] );
- } catch { }
+ this.contents.setLength( PortUtil.parseInt( spl[1] ) );
+ } catch ( Exception ex ) {
+ }
} else if ( spl[0].Equals( "Duration" ) ) {
try {
- this.contents.Duration = int.Parse( spl[1] );
- } catch { }
+ this.contents.Duration = PortUtil.parseInt( spl[1] );
+ } catch ( Exception ex ) {
+ }
} else if ( spl[0].Equals( "Depth" ) ) {
try {
- this.contents.Depth = int.Parse( spl[1] );
- } catch { }
+ this.contents.Depth = PortUtil.parseInt( spl[1] );
+ } catch ( Exception ex ) {
+ }
}
}
}
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sr != null ) {
+ try {
+ sr.close();
+ } catch ( Exception ex2 ) {
+ }
+ }
}
}
}
-
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/BPPair.cs b/trunk/Boare.Lib.Vsq/BPPair.cs
index 8ef236c..c2d80c8 100644
--- a/trunk/Boare.Lib.Vsq/BPPair.cs
+++ b/trunk/Boare.Lib.Vsq/BPPair.cs
@@ -12,7 +12,9 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#if JAVA
-package com.boare.vsq;
+package org.kbinani.vsq;
+
+import java.io.*;
#else
using System;
@@ -23,10 +25,10 @@ namespace Boare.Lib.Vsq {
/// Stores the paired value of "Clock" and integer. Mainly used in VsqBPList
///
#if JAVA
- class BPPair implements Comparable {
+ public class BPPair implements Comparable, Serializable{
#else
[Serializable]
- public class BPPair : IComparable {
+ public class BPPair : IComparable{
#endif
public int Clock;
public int Value;
@@ -46,9 +48,11 @@ namespace Boare.Lib.Vsq {
}
}
+#if !JAVA
public int CompareTo( BPPair item ) {
return compareTo( item );
}
+#endif
public BPPair( int clock_, int value_ ) {
Clock = clock_;
@@ -56,4 +60,6 @@ namespace Boare.Lib.Vsq {
}
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/Boare.Lib.Vsq.csproj b/trunk/Boare.Lib.Vsq/Boare.Lib.Vsq.csproj
index afa6219..f9b0e81 100644
--- a/trunk/Boare.Lib.Vsq/Boare.Lib.Vsq.csproj
+++ b/trunk/Boare.Lib.Vsq/Boare.Lib.Vsq.csproj
@@ -2,7 +2,7 @@
Debug
AnyCPU
- 9.0.21022
+ 9.0.30729
2.0
{673347F3-6FC2-4F82-9273-BF158E0F8CB1}
Library
@@ -61,28 +61,47 @@
-
+
+
+
+
+
+
+
+
-
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
@@ -95,17 +114,11 @@
-
-
-
-
-
-
-
+
diff --git a/trunk/Boare.Lib.Vsq/ExpressionConfigSys.cs b/trunk/Boare.Lib.Vsq/ExpressionConfigSys.cs
index b43a300..9acdc45 100644
--- a/trunk/Boare.Lib.Vsq/ExpressionConfigSys.cs
+++ b/trunk/Boare.Lib.Vsq/ExpressionConfigSys.cs
@@ -12,64 +12,719 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#if JAVA
-package com.boare.vsq;
+package org.kbinani.vsq;
+
+import java.util.*;
+import java.io.*;
+import org.kbinani.*;
#else
using System;
-using System.Collections.Generic;
-using System.IO;
using System.Text;
-
using bocoree;
+using bocoree.java.util;
+using bocoree.java.io;
namespace Boare.Lib.Vsq {
#endif
public class ExpressionConfigSys {
+#if JAVA
+ private final int MAX_VIBRATO = 0x400;
+#else
private const int MAX_VIBRATO = 0x400;
+#endif
private Vector m_vibrato_configs;
private Vector m_attack_configs;
+ private void printTo( String file ) {
+ BufferedWriter sw = null;
+ try {
+ sw = new BufferedWriter( new FileWriter( file ) );
+ int count = 0;
+ for ( Iterator itr = m_vibrato_configs.iterator(); itr.hasNext(); ) {
+ count++;
+ VibratoConfig vconfig = (VibratoConfig)itr.next();
+ String name = "v" + count;
+ sw.write( "VibratoConfig " + name + " = new VibratoConfig();" );
+ sw.newLine();
+ sw.write( name + ".author = \"" + vconfig.author + "\";" );
+ sw.newLine();
+ sw.write( name + ".file = \"" + vconfig.file + "\";" );
+ sw.newLine();
+ sw.write( name + ".number = " + vconfig.number + ";" );
+ sw.newLine();
+ sw.write( name + ".vendor = \"" + vconfig.vendor + "\";" );
+ sw.newLine();
+ sw.write( name + ".contents.IconID = \"" + vconfig.contents.IconID + "\";" );
+ sw.newLine();
+ sw.write( name + ".contents.IDS = \"" + vconfig.contents.IDS + "\";" );
+ sw.newLine();
+ sw.write( name + ".contents.Original = " + vconfig.contents.Original + ";" );
+ sw.newLine();
+ sw.write( name + ".contents.Caption = \"" + vconfig.contents.Caption + "\";" );
+ sw.newLine();
+ sw.write( name + ".contents.Length = " + vconfig.contents.getLength() + ";" );
+ sw.newLine();
+ sw.write( name + ".contents.StartDepth = " + vconfig.contents.StartDepth + ";" );
+ sw.write( name + ".contents.DepthBP = new VibratoBPList( new float[]{ " );
+ for ( int i = 0; i < vconfig.contents.DepthBP.getCount(); i++ ) {
+ sw.write( ((i > 0) ? ", " : "") + vconfig.contents.DepthBP.getElement( i ).X + "f" );
+ }
+ sw.write( " }, new int[]{ " );
+ for ( int i = 0; i < vconfig.contents.DepthBP.getCount(); i++ ) {
+ sw.write( ((i > 0) ? ", " : "") + vconfig.contents.DepthBP.getElement( i ).Y );
+ }
+ sw.write( " } );" );
+ sw.newLine();
+ sw.write( name + ".contents.StartRate = " + vconfig.contents.StartRate + ";" );
+ sw.newLine();
+ sw.write( name + ".contents.RateBP = new VibratoBPList( new float[]{ " );
+ for ( int i = 0; i < vconfig.contents.RateBP.getCount(); i++ ) {
+ sw.write( ((i > 0) ? ", " : "") + vconfig.contents.RateBP.getElement( i ).X + "f" );
+ }
+ sw.write( " }, new int[]{ " );
+ for ( int i = 0; i < vconfig.contents.RateBP.getCount(); i++ ) {
+ sw.write( ((i > 0) ? ", " : "") + vconfig.contents.RateBP.getElement( i ).Y );
+ }
+ sw.write( " } );" );
+ sw.newLine();
+ sw.write( "ret.m_vibrato_configs.add( " + name + " );" );
+ sw.newLine();
+ sw.newLine();
+ }
+ count = 0;
+
+ for ( Iterator itr = m_attack_configs.iterator(); itr.hasNext(); ) {
+ count++;
+ AttackConfig aconfig = (AttackConfig)itr.next();
+ String name = "a" + count;
+ sw.write( "AttackConfig " + name + " = new AttackConfig();" );
+ sw.newLine();
+ sw.write( name + ".author = \"" + aconfig.author + "\";" );
+ sw.newLine();
+ sw.write( name + ".file = \"" + aconfig.file + "\";" );
+ sw.newLine();
+ sw.write( name + ".number = " + aconfig.number + ";" );
+ sw.newLine();
+ sw.write( name + ".vendor = \"" + aconfig.vendor + "\";" );
+ sw.newLine();
+ sw.write( name + ".contents.IconID = \"" + aconfig.contents.IconID + "\";" );
+ sw.newLine();
+ sw.write( name + ".contents.IDS = \"" + aconfig.contents.IDS + "\";" );
+ sw.newLine();
+ sw.write( name + ".contents.Original = " + aconfig.contents.Original + ";" );
+ sw.newLine();
+ sw.write( name + ".contents.Caption = \"" + aconfig.contents.Caption + "\";" );
+ sw.newLine();
+ sw.write( name + ".contents.Length = " + aconfig.contents.getLength() + ";" );
+ sw.newLine();
+ sw.write( name + ".contents.Duration = " + aconfig.contents.Duration + ";" );
+ sw.newLine();
+ sw.write( name + ".contents.Depth = " + aconfig.contents.Depth + ";" );
+ sw.newLine();
+ sw.write( "ret.m_attack_configs.add( " + name + " );" );
+ sw.newLine();
+ sw.newLine();
+ }
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sw != null ) {
+ try {
+ sw.close();
+ } catch ( Exception ex2 ) {
+ }
+ }
+ }
+ }
+
+ public static ExpressionConfigSys getVocaloid1Default() {
+ ExpressionConfigSys ret = new ExpressionConfigSys();
+ ret.m_vibrato_configs = new Vector();
+ ret.m_attack_configs = new Vector();
+ VibratoConfig v1 = new VibratoConfig();
+ v1.author = "Taro";
+ v1.file = "normal.aic";
+ v1.number = 1;
+ v1.vendor = "YAMAHA";
+ v1.contents.IconID = "$04040001";
+ v1.contents.IDS = "normal";
+ v1.contents.Original = 0;
+ v1.contents.Caption = "Normal Vibrato";
+ v1.contents.setLength( 480 );
+ v1.contents.StartDepth = 64;
+ v1.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v1.contents.StartRate = 64;
+ v1.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v1 );
+
+ VibratoConfig v2 = new VibratoConfig();
+ v2.author = "Taro";
+ v2.file = "subtle.aic";
+ v2.number = 2;
+ v2.vendor = "YAMAHA";
+ v2.contents.IconID = "$04040002";
+ v2.contents.IDS = "normal";
+ v2.contents.Original = 0;
+ v2.contents.Caption = "Subtle Vibrato";
+ v2.contents.setLength( 480 );
+ v2.contents.StartDepth = 32;
+ v2.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v2.contents.StartRate = 56;
+ v2.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v2 );
+
+ VibratoConfig v3 = new VibratoConfig();
+ v3.author = "Taro";
+ v3.file = "slight.aic";
+ v3.number = 3;
+ v3.vendor = "YAMAHA";
+ v3.contents.IconID = "$04040003";
+ v3.contents.IDS = "slight";
+ v3.contents.Original = 0;
+ v3.contents.Caption = "Slight Vibrato";
+ v3.contents.setLength( 480 );
+ v3.contents.StartDepth = 32;
+ v3.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v3.contents.StartRate = 64;
+ v3.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v3 );
+
+ VibratoConfig v4 = new VibratoConfig();
+ v4.author = "Taro";
+ v4.file = "deep.aic";
+ v4.number = 4;
+ v4.vendor = "YAMAHA";
+ v4.contents.IconID = "$04040004";
+ v4.contents.IDS = "deep";
+ v4.contents.Original = 0;
+ v4.contents.Caption = "Deep Vibrato";
+ v4.contents.setLength( 480 );
+ v4.contents.StartDepth = 64;
+ v4.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v4.contents.StartRate = 64;
+ v4.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v4 );
+
+ VibratoConfig v5 = new VibratoConfig();
+ v5.author = "Taro";
+ v5.file = "verydeep.aic";
+ v5.number = 5;
+ v5.vendor = "YAMAHA";
+ v5.contents.IconID = "$04040005";
+ v5.contents.IDS = "extreme";
+ v5.contents.Original = 0;
+ v5.contents.Caption = "Very Deep Vibrato";
+ v5.contents.setLength( 480 );
+ v5.contents.StartDepth = 64;
+ v5.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v5.contents.StartRate = 120;
+ v5.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v5 );
+
+ VibratoConfig v6 = new VibratoConfig();
+ v6.author = "Taro";
+ v6.file = "extreme.aic";
+ v6.number = 6;
+ v6.vendor = "YAMAHA";
+ v6.contents.IconID = "$04040006";
+ v6.contents.IDS = "extreme";
+ v6.contents.Original = 0;
+ v6.contents.Caption = "Extreme Vibrato (like Japanese Enka)";
+ v6.contents.setLength( 480 );
+ v6.contents.StartDepth = 64;
+ v6.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v6.contents.StartRate = 64;
+ v6.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v6 );
+
+ AttackConfig a1 = new AttackConfig();
+ a1.author = "Taro";
+ a1.file = "na_tenuto.aic";
+ a1.number = 1;
+ a1.vendor = "YAMAHA";
+ a1.contents.IconID = "$01010001";
+ a1.contents.IDS = "tenuto";
+ a1.contents.Original = 0;
+ a1.contents.Caption = "Tenuto";
+ a1.contents.setLength( 120 );
+ a1.contents.Duration = 64;
+ a1.contents.Depth = 64;
+ ret.m_attack_configs.add( a1 );
+
+ AttackConfig a2 = new AttackConfig();
+ a2.author = "Taro";
+ a2.file = "na_accent.aic";
+ a2.number = 2;
+ a2.vendor = "YAMAHA";
+ a2.contents.IconID = "$01010002";
+ a2.contents.IDS = "accent";
+ a2.contents.Original = 0;
+ a2.contents.Caption = "Accent";
+ a2.contents.setLength( 120 );
+ a2.contents.Duration = 64;
+ a2.contents.Depth = 64;
+ ret.m_attack_configs.add( a2 );
+
+ AttackConfig a3 = new AttackConfig();
+ a3.author = "Taro";
+ a3.file = "na_extreme_accent.aic";
+ a3.number = 3;
+ a3.vendor = "YAMAHA";
+ a3.contents.IconID = "$01010003";
+ a3.contents.IDS = "accent_extreme";
+ a3.contents.Original = 0;
+ a3.contents.Caption = "Extreme Accent";
+ a3.contents.setLength( 120 );
+ a3.contents.Duration = 64;
+ a3.contents.Depth = 64;
+ ret.m_attack_configs.add( a3 );
+
+ AttackConfig a4 = new AttackConfig();
+ a4.author = "Taro";
+ a4.file = "na_legato.aic";
+ a4.number = 4;
+ a4.vendor = "YAMAHA";
+ a4.contents.IconID = "$01010004";
+ a4.contents.IDS = "legato";
+ a4.contents.Original = 0;
+ a4.contents.Caption = "Legato";
+ a4.contents.setLength( 120 );
+ a4.contents.Duration = 64;
+ a4.contents.Depth = 64;
+ ret.m_attack_configs.add( a4 );
+
+ AttackConfig a5 = new AttackConfig();
+ a5.author = "Taro";
+ a5.file = "na_fast_bendup.aic";
+ a5.number = 5;
+ a5.vendor = "YAMAHA";
+ a5.contents.IconID = "$01010005";
+ a5.contents.IDS = "bendup_fast";
+ a5.contents.Original = 0;
+ a5.contents.Caption = "Fast Bendu";
+ a5.contents.setLength( 120 );
+ a5.contents.Duration = 64;
+ a5.contents.Depth = 64;
+ ret.m_attack_configs.add( a5 );
+
+ AttackConfig a6 = new AttackConfig();
+ a6.author = "Taro";
+ a6.file = "na_slow_bendup.aic";
+ a6.number = 6;
+ a6.vendor = "YAMAHA";
+ a6.contents.IconID = "$01010006";
+ a6.contents.IDS = "bendup_slow";
+ a6.contents.Original = 0;
+ a6.contents.Caption = "Slow Bendup";
+ a6.contents.setLength( 120 );
+ a6.contents.Duration = 64;
+ a6.contents.Depth = 64;
+ ret.m_attack_configs.add( a6 );
+
+ AttackConfig a7 = new AttackConfig();
+ a7.author = "Taro";
+ a7.file = "na_trill_semi.aic";
+ a7.number = 7;
+ a7.vendor = "YAMAHA";
+ a7.contents.IconID = "$01010007";
+ a7.contents.IDS = "trill_semi";
+ a7.contents.Original = 0;
+ a7.contents.Caption = "Trill Semitone";
+ a7.contents.setLength( 120 );
+ a7.contents.Duration = 64;
+ a7.contents.Depth = 64;
+ ret.m_attack_configs.add( a7 );
+
+ AttackConfig a8 = new AttackConfig();
+ a8.author = "Taro";
+ a8.file = "na_trill_whole.aic";
+ a8.number = 8;
+ a8.vendor = "YAMAHA";
+ a8.contents.IconID = "$01010008";
+ a8.contents.IDS = "trill_whole";
+ a8.contents.Original = 0;
+ a8.contents.Caption = "Trill Wholetone";
+ a8.contents.setLength( 120 );
+ a8.contents.Duration = 64;
+ a8.contents.Depth = 64;
+ ret.m_attack_configs.add( a8 );
+
+ AttackConfig a9 = new AttackConfig();
+ a9.author = "Taro";
+ a9.file = "na_mordent_semi.aic";
+ a9.number = 9;
+ a9.vendor = "YAMAHA";
+ a9.contents.IconID = "$01010009";
+ a9.contents.IDS = "mordent_semi";
+ a9.contents.Original = 0;
+ a9.contents.Caption = "Mordent Semitone";
+ a9.contents.setLength( 120 );
+ a9.contents.Duration = 64;
+ a9.contents.Depth = 64;
+ ret.m_attack_configs.add( a9 );
+
+ AttackConfig a10 = new AttackConfig();
+ a10.author = "Taro";
+ a10.file = "na_mordent_whole.aic";
+ a10.number = 10;
+ a10.vendor = "YAMAHA";
+ a10.contents.IconID = "$0101000a";
+ a10.contents.IDS = "mordent_whole";
+ a10.contents.Original = 0;
+ a10.contents.Caption = "Mordent Wholetone";
+ a10.contents.setLength( 120 );
+ a10.contents.Duration = 64;
+ a10.contents.Depth = 64;
+ ret.m_attack_configs.add( a10 );
+
+ return ret;
+ }
+
+ public static ExpressionConfigSys getVocaloid2Default() {
+ ExpressionConfigSys ret = new ExpressionConfigSys();
+ ret.m_vibrato_configs = new Vector();
+ ret.m_attack_configs = new Vector();
+ VibratoConfig v1 = new VibratoConfig();
+ v1.author = "Standard";
+ v1.file = "normal2_type1.aic";
+ v1.number = 1;
+ v1.vendor = "YAMAHA";
+ v1.contents.IconID = "$04040001";
+ v1.contents.IDS = "normal";
+ v1.contents.Original = 0;
+ v1.contents.Caption = "[Normal] Type 1";
+ v1.contents.setLength( 480 );
+ v1.contents.StartDepth = 64;
+ v1.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v1.contents.StartRate = 50;
+ v1.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v1 );
+
+ VibratoConfig v2 = new VibratoConfig();
+ v2.author = "Standard";
+ v2.file = "normal2_type2.aic";
+ v2.number = 2;
+ v2.vendor = "YAMAHA";
+ v2.contents.IconID = "$04040002";
+ v2.contents.IDS = "normal";
+ v2.contents.Original = 0;
+ v2.contents.Caption = "[Normal] Type 2";
+ v2.contents.setLength( 480 );
+ v2.contents.StartDepth = 40;
+ v2.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v2.contents.StartRate = 50;
+ v2.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v2 );
+
+ VibratoConfig v3 = new VibratoConfig();
+ v3.author = "Standard";
+ v3.file = "normal2_type3.aic";
+ v3.number = 3;
+ v3.vendor = "YAMAHA";
+ v3.contents.IconID = "$04040003";
+ v3.contents.IDS = "normal";
+ v3.contents.Original = 0;
+ v3.contents.Caption = "[Normal] Type 3";
+ v3.contents.setLength( 480 );
+ v3.contents.StartDepth = 127;
+ v3.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v3.contents.StartRate = 50;
+ v3.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v3 );
+
+ VibratoConfig v4 = new VibratoConfig();
+ v4.author = "Standard";
+ v4.file = "normal2_type4.aic";
+ v4.number = 4;
+ v4.vendor = "YAMAHA";
+ v4.contents.IconID = "$04040004";
+ v4.contents.IDS = "normal";
+ v4.contents.Original = 0;
+ v4.contents.Caption = "[Normal] Type 4";
+ v4.contents.setLength( 480 );
+ v4.contents.StartDepth = 64;
+ v4.contents.DepthBP = new VibratoBPList( new float[] { 0.6042f, 0.6125f, 0.6167f, 0.6208f, 0.625f, 0.6333f, 0.6375f, 0.6417f, 0.6458f, 0.6542f, 0.6583f, 0.6667f, 0.6708f, 0.675f, 0.6792f, 0.6833f, 0.6917f, 0.6958f, 0.7042f, 0.7083f, 0.7125f, 0.7167f, 0.7208f, 0.725f, 0.7292f, 0.7375f, 0.7458f, 0.75f, 0.7583f, 0.7625f, 0.7667f, 0.7708f, 0.775f, 0.7833f, 0.7917f, 0.7958f, 0.8f, 0.8042f, 0.8083f, 0.8125f, 0.8208f, 0.8292f, 0.8375f, 0.8417f, 0.8458f, 0.85f, 0.8542f, 0.8625f, 0.8667f, 0.875f, 0.8792f, 0.8833f, 0.8875f, 0.8917f, 0.8958f, 0.9f, 1f }, new int[] { 64, 63, 62, 61, 59, 58, 57, 56, 55, 54, 52, 51, 50, 49, 48, 47, 45, 44, 43, 42, 41, 40, 39, 38, 37, 35, 34, 32, 31, 30, 29, 28, 27, 25, 24, 23, 22, 21, 20, 19, 17, 15, 14, 13, 12, 11, 10, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0 } );
+ v4.contents.StartRate = 50;
+ v4.contents.RateBP = new VibratoBPList( new float[] { 0.6f, 0.6125f, 0.6167f, 0.6208f, 0.6292f, 0.6333f, 0.6375f, 0.6417f, 0.6542f, 0.6583f, 0.6625f, 0.6667f, 0.675f, 0.6833f, 0.6875f, 0.6917f, 0.7f, 0.7042f, 0.7083f, 0.7125f, 0.725f, 0.7292f, 0.7333f, 0.7375f, 0.7458f, 0.75f, 0.7583f, 0.7625f, 0.7708f, 0.775f, 0.7792f, 0.7833f, 0.7958f, 0.8f, 0.8042f, 0.8083f, 0.8167f, 0.8208f, 0.8292f, 0.8333f, 0.8417f, 0.8458f, 0.85f, 0.8542f, 0.8667f, 0.8708f, 0.875f, 0.8792f, 0.8875f, 0.8917f, 0.9f, 1f }, new int[] { 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0 } );
+ ret.m_vibrato_configs.add( v4 );
+
+ VibratoConfig v5 = new VibratoConfig();
+ v5.author = "Standard";
+ v5.file = "extreme2_type1.aic";
+ v5.number = 5;
+ v5.vendor = "YAMAHA";
+ v5.contents.IconID = "$04040005";
+ v5.contents.IDS = "extreme";
+ v5.contents.Original = 0;
+ v5.contents.Caption = "[Extreme] Type 1";
+ v5.contents.setLength( 480 );
+ v5.contents.StartDepth = 64;
+ v5.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v5.contents.StartRate = 64;
+ v5.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v5 );
+
+ VibratoConfig v6 = new VibratoConfig();
+ v6.author = "Standard";
+ v6.file = "extreme2_type2.aic";
+ v6.number = 6;
+ v6.vendor = "YAMAHA";
+ v6.contents.IconID = "$04040006";
+ v6.contents.IDS = "extreme";
+ v6.contents.Original = 0;
+ v6.contents.Caption = "[Extreme] Type 2";
+ v6.contents.setLength( 480 );
+ v6.contents.StartDepth = 32;
+ v6.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v6.contents.StartRate = 32;
+ v6.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v6 );
+
+ VibratoConfig v7 = new VibratoConfig();
+ v7.author = "Standard";
+ v7.file = "extreme2_type3.aic";
+ v7.number = 7;
+ v7.vendor = "YAMAHA";
+ v7.contents.IconID = "$04040007";
+ v7.contents.IDS = "extreme";
+ v7.contents.Original = 0;
+ v7.contents.Caption = "[Extreme] Type 3";
+ v7.contents.setLength( 480 );
+ v7.contents.StartDepth = 100;
+ v7.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v7.contents.StartRate = 50;
+ v7.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v7 );
+
+ VibratoConfig v8 = new VibratoConfig();
+ v8.author = "Standard";
+ v8.file = "extreme2_type4.aic";
+ v8.number = 8;
+ v8.vendor = "YAMAHA";
+ v8.contents.IconID = "$04040008";
+ v8.contents.IDS = "extreme";
+ v8.contents.Original = 0;
+ v8.contents.Caption = "[Extreme] Type 4";
+ v8.contents.setLength( 480 );
+ v8.contents.StartDepth = 64;
+ v8.contents.DepthBP = new VibratoBPList( new float[] { 0.6042f, 0.6125f, 0.6167f, 0.6208f, 0.625f, 0.6333f, 0.6375f, 0.6417f, 0.6458f, 0.6542f, 0.6583f, 0.6667f, 0.6708f, 0.675f, 0.6792f, 0.6833f, 0.6917f, 0.6958f, 0.7042f, 0.7083f, 0.7125f, 0.7167f, 0.7208f, 0.725f, 0.7292f, 0.7375f, 0.7458f, 0.75f, 0.7583f, 0.7625f, 0.7667f, 0.7708f, 0.775f, 0.7833f, 0.7917f, 0.7958f, 0.8f, 0.8042f, 0.8083f, 0.8125f, 0.8208f, 0.8292f, 0.8375f, 0.8417f, 0.8458f, 0.85f, 0.8542f, 0.8625f, 0.8667f, 0.875f, 0.8792f, 0.8833f, 0.8875f, 0.8917f, 0.8958f, 0.9f, 1f }, new int[] { 64, 63, 62, 61, 59, 58, 57, 56, 55, 54, 52, 51, 50, 49, 48, 47, 45, 44, 43, 42, 41, 40, 39, 38, 37, 35, 34, 32, 31, 30, 29, 28, 27, 25, 24, 23, 22, 21, 20, 19, 17, 15, 14, 13, 12, 11, 10, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0 } );
+ v8.contents.StartRate = 64;
+ v8.contents.RateBP = new VibratoBPList( new float[] { 0.6042f, 0.6125f, 0.6167f, 0.6208f, 0.625f, 0.6333f, 0.6375f, 0.6417f, 0.6458f, 0.6542f, 0.6583f, 0.6667f, 0.6708f, 0.675f, 0.6792f, 0.6833f, 0.6917f, 0.6958f, 0.7042f, 0.7083f, 0.7125f, 0.7167f, 0.7208f, 0.725f, 0.7292f, 0.7375f, 0.7458f, 0.75f, 0.7583f, 0.7625f, 0.7667f, 0.7708f, 0.775f, 0.7833f, 0.7917f, 0.7958f, 0.8f, 0.8042f, 0.8083f, 0.8125f, 0.8208f, 0.8292f, 0.8375f, 0.8417f, 0.8458f, 0.85f, 0.8542f, 0.8625f, 0.8667f, 0.875f, 0.8792f, 0.8833f, 0.8875f, 0.8917f, 0.8958f, 0.9f, 1f }, new int[] { 64, 63, 62, 61, 59, 58, 57, 56, 55, 54, 52, 51, 50, 49, 48, 47, 45, 44, 43, 42, 41, 40, 39, 38, 37, 35, 34, 32, 31, 30, 29, 28, 27, 25, 24, 23, 22, 21, 20, 19, 17, 15, 14, 13, 12, 11, 10, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0 } );
+ ret.m_vibrato_configs.add( v8 );
+
+ VibratoConfig v9 = new VibratoConfig();
+ v9.author = "Standard";
+ v9.file = "fast2_type1.aic";
+ v9.number = 9;
+ v9.vendor = "YAMAHA";
+ v9.contents.IconID = "$04040009";
+ v9.contents.IDS = "fast";
+ v9.contents.Original = 0;
+ v9.contents.Caption = "[Fast] Type 1";
+ v9.contents.setLength( 480 );
+ v9.contents.StartDepth = 64;
+ v9.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v9.contents.StartRate = 64;
+ v9.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v9 );
+
+ VibratoConfig v10 = new VibratoConfig();
+ v10.author = "Standard";
+ v10.file = "fast2_type2.aic";
+ v10.number = 10;
+ v10.vendor = "YAMAHA";
+ v10.contents.IconID = "$0404000a";
+ v10.contents.IDS = "fast";
+ v10.contents.Original = 0;
+ v10.contents.Caption = "[Fast] Type 2";
+ v10.contents.setLength( 480 );
+ v10.contents.StartDepth = 40;
+ v10.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v10.contents.StartRate = 50;
+ v10.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v10 );
+
+ VibratoConfig v11 = new VibratoConfig();
+ v11.author = "Standard";
+ v11.file = "fast2_type3.aic";
+ v11.number = 11;
+ v11.vendor = "YAMAHA";
+ v11.contents.IconID = "$0404000b";
+ v11.contents.IDS = "fast";
+ v11.contents.Original = 0;
+ v11.contents.Caption = "[Fast] Type 3";
+ v11.contents.setLength( 480 );
+ v11.contents.StartDepth = 80;
+ v11.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v11.contents.StartRate = 70;
+ v11.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v11 );
+
+ VibratoConfig v12 = new VibratoConfig();
+ v12.author = "Standard";
+ v12.file = "fast2_type4.aic";
+ v12.number = 12;
+ v12.vendor = "YAMAHA";
+ v12.contents.IconID = "$0404000c";
+ v12.contents.IDS = "fast";
+ v12.contents.Original = 0;
+ v12.contents.Caption = "[Fast] Type 4";
+ v12.contents.setLength( 480 );
+ v12.contents.StartDepth = 64;
+ v12.contents.DepthBP = new VibratoBPList( new float[] { 0.6042f, 0.6125f, 0.6167f, 0.6208f, 0.625f, 0.6333f, 0.6375f, 0.6417f, 0.6458f, 0.6542f, 0.6583f, 0.6667f, 0.6708f, 0.675f, 0.6792f, 0.6833f, 0.6917f, 0.6958f, 0.7042f, 0.7083f, 0.7125f, 0.7167f, 0.7208f, 0.725f, 0.7292f, 0.7375f, 0.7458f, 0.75f, 0.7583f, 0.7625f, 0.7667f, 0.7708f, 0.775f, 0.7833f, 0.7917f, 0.7958f, 0.8f, 0.8042f, 0.8083f, 0.8125f, 0.8208f, 0.8292f, 0.8375f, 0.8417f, 0.8458f, 0.85f, 0.8542f, 0.8625f, 0.8667f, 0.875f, 0.8792f, 0.8833f, 0.8875f, 0.8917f, 0.8958f, 0.9f, 1f }, new int[] { 64, 63, 62, 61, 59, 58, 57, 56, 55, 54, 52, 51, 50, 49, 48, 47, 45, 44, 43, 42, 41, 40, 39, 38, 37, 35, 34, 32, 31, 30, 29, 28, 27, 25, 24, 23, 22, 21, 20, 19, 17, 15, 14, 13, 12, 11, 10, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0 } );
+ v12.contents.StartRate = 64;
+ v12.contents.RateBP = new VibratoBPList( new float[] { 0.6042f, 0.6125f, 0.6167f, 0.6208f, 0.625f, 0.6333f, 0.6375f, 0.6417f, 0.6458f, 0.6542f, 0.6583f, 0.6667f, 0.6708f, 0.675f, 0.6792f, 0.6833f, 0.6917f, 0.6958f, 0.7042f, 0.7083f, 0.7125f, 0.7167f, 0.7208f, 0.725f, 0.7292f, 0.7375f, 0.7458f, 0.75f, 0.7583f, 0.7625f, 0.7667f, 0.7708f, 0.775f, 0.7833f, 0.7917f, 0.7958f, 0.8f, 0.8042f, 0.8083f, 0.8125f, 0.8208f, 0.8292f, 0.8375f, 0.8417f, 0.8458f, 0.85f, 0.8542f, 0.8625f, 0.8667f, 0.875f, 0.8792f, 0.8833f, 0.8875f, 0.8917f, 0.8958f, 0.9f, 1f }, new int[] { 64, 63, 62, 61, 59, 58, 57, 56, 55, 54, 52, 51, 50, 49, 48, 47, 45, 44, 43, 42, 41, 40, 39, 38, 37, 35, 34, 32, 31, 30, 29, 28, 27, 25, 24, 23, 22, 21, 20, 19, 17, 15, 14, 13, 12, 11, 10, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0 } );
+ ret.m_vibrato_configs.add( v12 );
+
+ VibratoConfig v13 = new VibratoConfig();
+ v13.author = "Standard";
+ v13.file = "slight2_type1.aic";
+ v13.number = 13;
+ v13.vendor = "YAMAHA";
+ v13.contents.IconID = "$0404000d";
+ v13.contents.IDS = "slight";
+ v13.contents.Original = 0;
+ v13.contents.Caption = "[Slight] Type 1";
+ v13.contents.setLength( 480 );
+ v13.contents.StartDepth = 64;
+ v13.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v13.contents.StartRate = 64;
+ v13.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v13 );
+
+ VibratoConfig v14 = new VibratoConfig();
+ v14.author = "Standard";
+ v14.file = "slight2_type2.aic";
+ v14.number = 14;
+ v14.vendor = "YAMAHA";
+ v14.contents.IconID = "$0404000e";
+ v14.contents.IDS = "slight";
+ v14.contents.Original = 0;
+ v14.contents.Caption = "[Slight] Type 2";
+ v14.contents.setLength( 480 );
+ v14.contents.StartDepth = 40;
+ v14.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v14.contents.StartRate = 64;
+ v14.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v14 );
+
+ VibratoConfig v15 = new VibratoConfig();
+ v15.author = "Standard";
+ v15.file = "slight2_type3.aic";
+ v15.number = 15;
+ v15.vendor = "YAMAHA";
+ v15.contents.IconID = "$0404000f";
+ v15.contents.IDS = "slight";
+ v15.contents.Original = 0;
+ v15.contents.Caption = "[Slight] Type 3";
+ v15.contents.setLength( 480 );
+ v15.contents.StartDepth = 72;
+ v15.contents.DepthBP = new VibratoBPList( new float[] { }, new int[] { } );
+ v15.contents.StartRate = 64;
+ v15.contents.RateBP = new VibratoBPList( new float[] { }, new int[] { } );
+ ret.m_vibrato_configs.add( v15 );
+
+ VibratoConfig v16 = new VibratoConfig();
+ v16.author = "Standard";
+ v16.file = "slight2_type4.aic";
+ v16.number = 16;
+ v16.vendor = "YAMAHA";
+ v16.contents.IconID = "$04040010";
+ v16.contents.IDS = "slight";
+ v16.contents.Original = 0;
+ v16.contents.Caption = "[Slight] Type 4";
+ v16.contents.setLength( 480 );
+ v16.contents.StartDepth = 64;
+ v16.contents.DepthBP = new VibratoBPList( new float[] { 0.6042f, 0.6125f, 0.6167f, 0.6208f, 0.625f, 0.6333f, 0.6375f, 0.6417f, 0.6458f, 0.6542f, 0.6583f, 0.6667f, 0.6708f, 0.675f, 0.6792f, 0.6833f, 0.6917f, 0.6958f, 0.7042f, 0.7083f, 0.7125f, 0.7167f, 0.7208f, 0.725f, 0.7292f, 0.7375f, 0.7458f, 0.75f, 0.7583f, 0.7625f, 0.7667f, 0.7708f, 0.775f, 0.7833f, 0.7917f, 0.7958f, 0.8f, 0.8042f, 0.8083f, 0.8125f, 0.8208f, 0.8292f, 0.8375f, 0.8417f, 0.8458f, 0.85f, 0.8542f, 0.8625f, 0.8667f, 0.875f, 0.8792f, 0.8833f, 0.8875f, 0.8917f, 0.8958f, 0.9f, 1f }, new int[] { 64, 63, 62, 61, 59, 58, 57, 56, 55, 54, 52, 51, 50, 49, 48, 47, 45, 44, 43, 42, 41, 40, 39, 38, 37, 35, 34, 32, 31, 30, 29, 28, 27, 25, 24, 23, 22, 21, 20, 19, 17, 15, 14, 13, 12, 11, 10, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0 } );
+ v16.contents.StartRate = 64;
+ v16.contents.RateBP = new VibratoBPList( new float[] { 0.6042f, 0.6125f, 0.6167f, 0.6208f, 0.625f, 0.6333f, 0.6375f, 0.6417f, 0.6458f, 0.6542f, 0.6583f, 0.6667f, 0.6708f, 0.675f, 0.6792f, 0.6833f, 0.6917f, 0.6958f, 0.7042f, 0.7083f, 0.7125f, 0.7167f, 0.7208f, 0.725f, 0.7292f, 0.7375f, 0.7458f, 0.75f, 0.7583f, 0.7625f, 0.7667f, 0.7708f, 0.775f, 0.7833f, 0.7917f, 0.7958f, 0.8f, 0.8042f, 0.8083f, 0.8125f, 0.8208f, 0.8292f, 0.8375f, 0.8417f, 0.8458f, 0.85f, 0.8542f, 0.8625f, 0.8667f, 0.875f, 0.8792f, 0.8833f, 0.8875f, 0.8917f, 0.8958f, 0.9f, 1f }, new int[] { 64, 63, 62, 61, 59, 58, 57, 56, 55, 54, 52, 51, 50, 49, 48, 47, 45, 44, 43, 42, 41, 40, 39, 38, 37, 35, 34, 32, 31, 30, 29, 28, 27, 25, 24, 23, 22, 21, 20, 19, 17, 15, 14, 13, 12, 11, 10, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0 } );
+ ret.m_vibrato_configs.add( v16 );
+
+ return ret;
+ }
+
+ public int getVibratoConfigCount() {
+ return m_vibrato_configs.size();
+ }
+
+ public int getAttackConfigCount() {
+ return m_attack_configs.size();
+ }
+
+ public Iterator vibratoConfigIterator() {
+#if JAVA
+ return m_vibrato_configs.iterator();
+#else
+ return new ListIterator( m_vibrato_configs );
+#endif
+ }
+
+ public Iterator attackConfigIterator() {
+#if JAVA
+ return m_attack_configs.iterator();
+#else
+ return new ListIterator( m_attack_configs );
+#endif
+ }
+
+ private ExpressionConfigSys() {
+ }
+
public ExpressionConfigSys( String path_expdb ) {
m_vibrato_configs = new Vector();
m_attack_configs = new Vector();
- String expression = Path.Combine( path_expdb, "expression.map" );
- if ( !File.Exists( expression ) ) {
+ String expression = PortUtil.combinePath( path_expdb, "expression.map" );
+ if ( !PortUtil.isFileExists( expression ) ) {
+#if DEBUG
+ PortUtil.println( "ExpressionConfigSys#.ctor; expression.map does not exist" );
+#endif
return;
}
- FileStream fs = null;
+ RandomAccessFile fs = null;
try {
- new FileStream( expression, FileMode.Open, FileAccess.Read );
+ fs = new RandomAccessFile( expression, "r" );
byte[] dat = new byte[8];
- fs.Seek( 0x20, SeekOrigin.Begin );
+ fs.seek( 0x20 );
for ( int i = 0; i < MAX_VIBRATO; i++ ) {
- fs.Read( dat, 0, 8 );
- ulong value = VocaloSysUtil.makelong_le( dat );
-
+ fs.read( dat, 0, 8 );
+ long value = VocaloSysUtil.makelong_le( dat );
if ( value <= 0 ) {
continue;
}
- String ved = Path.Combine( path_expdb, "vexp" + value + ".ved" );
- if ( !File.Exists( ved ) ) {
+ String ved = PortUtil.combinePath( path_expdb, "vexp" + value + ".ved" );
+ if ( !PortUtil.isFileExists( ved ) ) {
continue;
}
- String vexp_dir = Path.Combine( path_expdb, "vexp" + value );
- if ( !Directory.Exists( vexp_dir ) ) {
+ String vexp_dir = PortUtil.combinePath( path_expdb, "vexp" + value );
+ if ( !PortUtil.isFileExists( vexp_dir ) ) {
continue;
}
+#if DEBUG
+ PortUtil.println( "ExpresionConfigSys#.ctor; ved=" + ved + "; vexp_dir=" + vexp_dir );
+#endif
String NL = (char)0x0D + "" + (char)0x0A;
- FileStream fs_ved = null;
+ RandomAccessFile fs_ved = null;
try {
- fs_ved = new FileStream( ved, FileMode.Open, FileAccess.Read );
- byte[] byte_ved = new byte[fs_ved.Length];
- fs_ved.Read( byte_ved, 0, byte_ved.Length );
- TransCodeUtil.decodeBytes( ref byte_ved );
- String str = new String( Encoding.ASCII.GetChars( byte_ved ) );
- String[] spl = str.Split( new String[] { NL }, StringSplitOptions.RemoveEmptyEntries );
+ fs_ved = new RandomAccessFile( ved, "r" );
+ byte[] byte_ved = new byte[(int)fs_ved.length()];
+ fs_ved.read( byte_ved, 0, byte_ved.Length );
+ TransCodeUtil.decodeBytes( byte_ved );
+ String str = PortUtil.getDecodedString( "ASCII", byte_ved );
+#if DEBUG
+ String txt_file = PortUtil.combinePath( path_expdb, "vexp" + value + ".txt" );
+ using ( System.IO.StreamWriter sw = new System.IO.StreamWriter( txt_file ) ) {
+ sw.Write( str );
+ }
+#endif
+ String[] spl = PortUtil.splitString( str, new String[] { NL }, true );
String current_entry = "";
for ( int j = 0; j < spl.Length; j++ ) {
+#if DEBUG
+ //PortUtil.println( "ExpressionConfigSys#.ctor; line=" + spl[j] );
+#endif
if ( spl[j].StartsWith( "[" ) ) {
current_entry = spl[j];
continue;
@@ -77,63 +732,82 @@ namespace Boare.Lib.Vsq {
continue;
}
if ( current_entry.Equals( "[VIBRATO]" ) ) {
- String[] spl2 = spl[j].Split( ',' );
+ String[] spl2 = PortUtil.splitString( spl[j], ',' );
if ( spl2.Length < 6 ) {
continue;
}
// ex: 1,1,"normal","normal2_type1.aic","[Normal]:Type:1","Standard","YAMAHA",0
VibratoConfig item = new VibratoConfig();
- item.number = int.Parse( spl2[0] );
+ item.number = PortUtil.parseInt( spl2[0] );
item.contents.IDS = spl2[2].Replace( "\"", "" );
item.file = spl2[3].Replace( "\"", "" );
item.contents.Caption = spl2[4].Replace( ":", " " ).Replace( "\"", "" );
item.author = spl2[5].Replace( "\"", "" );
item.vendor = spl2[6].Replace( "\"", "" );
- String aic_file = Path.Combine( vexp_dir, item.file );
- if ( !File.Exists( aic_file ) ) {
+ item.contents.IconID = "$0404" + PortUtil.toHexString( item.number, 4 );
+ String aic_file = PortUtil.combinePath( vexp_dir, item.file );
+ if ( !PortUtil.isFileExists( aic_file ) ) {
continue;
}
item.parseAic( aic_file );
+ m_vibrato_configs.add( item );
} if ( current_entry.Equals( "[NOTEATTACK]" ) ) {
- String[] spl2 = spl[j].Split( ',' );
+ String[] spl2 = PortUtil.splitString( spl[j], ',' );
if ( spl2.Length < 6 ) {
continue;
}
// ex: 1,1,"normal","normal2_type1.aic","[Normal]:Type:1","Standard","YAMAHA",0
AttackConfig item = new AttackConfig();
- item.number = int.Parse( spl2[0] );
+ item.number = PortUtil.parseInt( spl2[0] );
item.contents.IDS = spl2[2].Replace( "\"", "" );
item.file = spl2[3].Replace( "\"", "" );
item.contents.Caption = spl2[4].Replace( ":", " " ).Replace( "\"", "" );
item.author = spl2[5].Replace( "\"", "" );
item.vendor = spl2[6].Replace( "\"", "" );
- String aic_file = Path.Combine( vexp_dir, item.file );
- if ( !File.Exists( aic_file ) ) {
+ item.contents.IconID = "$0101" + PortUtil.toHexString( item.number, 4 );
+ String aic_file = PortUtil.combinePath( vexp_dir, item.file );
+ if ( !PortUtil.isFileExists( aic_file ) ) {
continue;
}
item.parseAic( aic_file );
+ m_attack_configs.add( item );
}
}
} catch ( Exception ex ) {
+#if DEBUG
+ PortUtil.println( "ExpressionConfigSys#.ctor; ex=" + ex );
+#endif
} finally {
if ( fs_ved != null ) {
try {
- fs_ved.Close();
+ fs_ved.close();
} catch ( Exception ex2 ) {
+#if DEBUG
+ PortUtil.println( "ExpressionConfigSys#.ctor; ex2=" + ex2 );
+#endif
}
}
}
}
} catch ( Exception ex ) {
+#if DEBUG
+ PortUtil.println( "ExpressionConfigSys#.ctor; ex=" + ex );
+#endif
} finally {
if ( fs != null ) {
try {
- fs.Close();
+ fs.close();
} catch ( Exception ex2 ) {
+#if DEBUG
+ PortUtil.println( "ExpressionConfigSys#.ctor; ex2=" + ex2 );
+#endif
}
}
}
}
+
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/ITextWriter.cs b/trunk/Boare.Lib.Vsq/ITextWriter.cs
new file mode 100644
index 0000000..a55c42c
--- /dev/null
+++ b/trunk/Boare.Lib.Vsq/ITextWriter.cs
@@ -0,0 +1,38 @@
+/*
+ * ITextWriter.cs
+ * Copyright (c) 2009 kbinani
+ *
+ * This file is part of Boare.Lib.Vsq.
+ *
+ * Boare.Lib.Vsq is free software; you can redistribute it and/or
+ * modify it under the terms of the BSD License.
+ *
+ * Boare.Lib.Vsq 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.vsq;
+
+import java.io.*;
+#else
+using System;
+
+namespace Boare.Lib.Vsq {
+#endif
+
+ public interface ITextWriter {
+#if JAVA
+ void write( String value ) throws IOException;
+ void writeLine( String value ) throws IOException;
+ void close() throws IOException;
+#else
+ void write( String value );
+ void writeLine( String value );
+ void close();
+#endif
+ }
+
+#if !JAVA
+}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/IconHandle.cs b/trunk/Boare.Lib.Vsq/IconHandle.cs
new file mode 100644
index 0000000..e649776
--- /dev/null
+++ b/trunk/Boare.Lib.Vsq/IconHandle.cs
@@ -0,0 +1,94 @@
+/*
+ * IconHandle.cs
+ * Copyright (c) 2008-2009 kbinani
+ *
+ * This file is part of Boare.Lib.Vsq.
+ *
+ * Boare.Lib.Vsq is free software; you can redistribute it and/or
+ * modify it under the terms of the BSD License.
+ *
+ * Boare.Lib.Vsq 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.vsq;
+
+import java.io.*;
+#else
+using System;
+
+namespace Boare.Lib.Vsq {
+ using boolean = System.Boolean;
+#endif
+
+#if JAVA
+ public class IconHandle implements Cloneable, Serializable{
+#else
+ [Serializable]
+ public class IconHandle : ICloneable{
+#endif
+ public String Caption = "";
+ public String IconID = "";
+ public String IDS = "";
+ public int Index;
+ public int Length;
+ public int Original;
+ public int Program;
+ public int Language;
+
+ public IconHandle() {
+ }
+
+ public int getLength() {
+ return Length;
+ }
+
+ public void setLength( int value ) {
+ Length = value;
+ }
+
+ public boolean equals( IconHandle item ) {
+ if ( item == null ) {
+ return false;
+ } else {
+ return IconID.Equals( item.IconID );
+ }
+ }
+
+ public Object clone() {
+ IconHandle ret = new IconHandle();
+ ret.Caption = Caption;
+ ret.IconID = IconID;
+ ret.IDS = IDS;
+ ret.Index = Index;
+ ret.Language = Language;
+ ret.setLength( Length );
+ ret.Original = Original;
+ ret.Program = Program;
+ return ret;
+ }
+
+#if !JAVA
+ public object Clone() {
+ return clone();
+ }
+#endif
+
+ public VsqHandle castToVsqHandle() {
+ VsqHandle ret = new VsqHandle();
+ ret.m_type = VsqHandleType.Singer;
+ ret.Caption = Caption;
+ ret.IconID = IconID;
+ ret.IDS = IDS;
+ ret.Index = Index;
+ ret.Language = Language;
+ ret.setLength( Length );
+ ret.Program = Program;
+ return ret;
+ }
+ }
+
+#if !JAVA
+}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/VsqMetaText/Lyric.cs b/trunk/Boare.Lib.Vsq/Lyric.cs
similarity index 65%
rename from trunk/Boare.Lib.Vsq/VsqMetaText/Lyric.cs
rename to trunk/Boare.Lib.Vsq/Lyric.cs
index c5b89dd..c7f4e01 100644
--- a/trunk/Boare.Lib.Vsq/VsqMetaText/Lyric.cs
+++ b/trunk/Boare.Lib.Vsq/Lyric.cs
@@ -1,5 +1,5 @@
/*
- * VsqMetaText/Lyric.cs
+ * Lyric.cs
* Copyright (c) 2008-2009 kbinani
*
* This file is part of Boare.Lib.Vsq.
@@ -11,23 +11,28 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.IO;
-using System.Windows.Forms;
+#if JAVA
+package org.kbinani.vsq;
+import java.io.*;
+import org.kbinani.*;
+#else
+using System;
using bocoree;
namespace Boare.Lib.Vsq {
-
using boolean = System.Boolean;
+#endif
///
/// VsqHandleに格納される歌詞の情報を扱うクラス。
///
+#if JAVA
+ public class Lyric implements Serializable{
+#else
[Serializable]
public class Lyric {
+#endif
///
/// この歌詞のフレーズ
///
@@ -45,16 +50,28 @@ namespace Boare.Lib.Vsq {
/// このオブジェクトの簡易コピーを取得します。
///
/// このインスタンスの簡易コピー
- public Lyric Clone() {
+ public Object clone() {
Lyric result = new Lyric();
result.Phrase = this.Phrase;
- result.m_phonetic_symbol = (String[])this.m_phonetic_symbol.Clone();
+ result.m_phonetic_symbol = new String[m_phonetic_symbol.Length];
+ for ( int i = 0; i < m_phonetic_symbol.Length; i++ ) {
+ result.m_phonetic_symbol[i] = m_phonetic_symbol[i];
+ }
result.UnknownFloat = this.UnknownFloat;
- result.m_consonant_adjustment = (int[])this.m_consonant_adjustment.Clone();
+ result.m_consonant_adjustment = new int[m_consonant_adjustment.Length];
+ for ( int i = 0; i < m_consonant_adjustment.Length; i++ ) {
+ result.m_consonant_adjustment[i] = m_consonant_adjustment[i];
+ }
result.PhoneticSymbolProtected = PhoneticSymbolProtected;
return result;
}
+#if !JAVA
+ public Object Clone() {
+ return clone();
+ }
+#endif
+
///
/// 歌詞、発音記号を指定したコンストラクタ
///
@@ -85,9 +102,9 @@ namespace Boare.Lib.Vsq {
///
public void setPhoneticSymbol( String value ) {
String s = value.Replace( " ", " " );
- m_phonetic_symbol = s.Split( " ".ToCharArray(), 16 );
+ m_phonetic_symbol = PortUtil.splitString( s, new char[] { ' ' }, 16 );
for ( int i = 0; i < m_phonetic_symbol.Length; i++ ) {
- m_phonetic_symbol[i] = m_phonetic_symbol[i].Replace( @"\\", @"\" );
+ m_phonetic_symbol[i] = m_phonetic_symbol[i].Replace( "\\" + "\\", "\\" );
}
m_consonant_adjustment = new int[m_phonetic_symbol.Length];
for ( int i = 0; i < m_phonetic_symbol.Length; i++ ) {
@@ -99,6 +116,7 @@ namespace Boare.Lib.Vsq {
}
}
+#if !JAVA
///
/// XMLシリアライズ用
///
@@ -110,6 +128,7 @@ namespace Boare.Lib.Vsq {
setPhoneticSymbol( value );
}
}
+#endif
public String[] getPhoneticSymbolList() {
String[] ret = new String[m_phonetic_symbol.Length];
@@ -124,12 +143,7 @@ namespace Boare.Lib.Vsq {
///
/// 生成元の文字列
public Lyric( String _line ) {
- byte[] b = new byte[_line.Length];
- for ( int i = 0; i < _line.Length; i++ ) {
- b[i] = (byte)_line[i];
- }
- String s = cp932.convert( b );
- String[] spl = s.Split( new char[] { ',' } );
+ String[] spl = PortUtil.splitString( _line, ',' );
int c_length = spl.Length - 3;
if ( spl.Length < 4 ) {
Phrase = "a";
@@ -142,57 +156,32 @@ namespace Boare.Lib.Vsq {
Phrase = Phrase.Substring( 1 );
}
if ( Phrase.EndsWith( "\"" ) ) {
- Phrase = Phrase.Substring( 0, Phrase.Length - 1 );
+ Phrase = Phrase.Substring( 0, PortUtil.getStringLength( Phrase ) - 1 );
}
String symbols = spl[1];
if ( symbols.StartsWith( "\"" ) ) {
symbols = symbols.Substring( 1 );
}
if ( symbols.EndsWith( "\"" ) ) {
- symbols = symbols.Substring( 0, symbols.Length - 1 );
+ symbols = symbols.Substring( 0, PortUtil.getStringLength( symbols ) - 1 );
}
setPhoneticSymbol( symbols );
- UnknownFloat = float.Parse( spl[2] );
+ UnknownFloat = PortUtil.parseFloat( spl[2] );
PhoneticSymbolProtected = (spl[spl.Length - 1].Equals( "0" )) ? false : true;
}
}
- ///
- /// 与えられた文字列の中の2バイト文字を\x**の形式にエンコードします。
- ///
- /// エンコード対象
- /// エンコードした文字列
- public static char[] encode( String item ) {
- //Encoding sjis = Encoding.GetEncoding( 932 );
- byte[] bytea = cp932.convert( item );// sjis.GetBytes( item );
- String result = "";
- for ( int i = 0; i < bytea.Length; i++ ) {
- if ( isprint( (char)bytea[i] ) ) {
- result += (char)bytea[i];
- } else {
- result += "\\x" + Convert.ToString( bytea[i], 16 );
- }
- }
- char[] res = result.ToCharArray();
- return res;
- }
-
///
/// このインスタンスを文字列に変換します
///
/// 2バイト文字をエンコードするか否かを指定するフラグ
/// 変換後の文字列
- public String ToString( boolean a_encode ) {
+ public String toString() {
String result;
- if ( a_encode ) {
- String njp = new String( encode( this.Phrase ) );
- result = "\"" + njp + "\",\"" + this.getPhoneticSymbol() + "\"," + UnknownFloat.ToString( "0.000000" );
- } else {
- result = "\"";
- result += this.Phrase;
- result += "\",\"" + this.getPhoneticSymbol() + "\"," + UnknownFloat.ToString( "0.000000" );
- result = result.Replace( @"\\", @"\" );
- }
+ result = "\"";
+ result += this.Phrase;
+ result += "\",\"" + this.getPhoneticSymbol() + "\"," + PortUtil.formatDecimal( "0.000000", UnknownFloat );
+ result = result.Replace( "\\" + "\\", "\\" );
for ( int i = 0; i < m_consonant_adjustment.Length; i++ ) {
result += "," + m_consonant_adjustment[i];
}
@@ -204,18 +193,13 @@ namespace Boare.Lib.Vsq {
return result;
}
- ///
- /// 文字がプリント出力可能かどうかを判定します
- ///
- ///
- ///
- private static boolean isprint( char ch ) {
- if ( 32 <= (int)ch && (int)ch <= 126 ) {
- return true;
- } else {
- return false;
- }
+#if !JAVA
+ public override string ToString() {
+ return toString();
}
+#endif
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/LyricHandle.cs b/trunk/Boare.Lib.Vsq/LyricHandle.cs
new file mode 100644
index 0000000..c2cae5f
--- /dev/null
+++ b/trunk/Boare.Lib.Vsq/LyricHandle.cs
@@ -0,0 +1,99 @@
+/*
+ * LyricHandle.cs
+ * Copyright (c) 2008-2009 kbinani
+ *
+ * This file is part of Boare.Lib.Vsq.
+ *
+ * Boare.Lib.Vsq is free software; you can redistribute it and/or
+ * modify it under the terms of the BSD License.
+ *
+ * Boare.Lib.Vsq 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.vsq;
+
+import java.io.*;
+import java.util.*;
+#else
+using System;
+using bocoree.java.util;
+
+namespace Boare.Lib.Vsq {
+#endif
+
+#if JAVA
+ public class LyricHandle implements Cloneable, Serializable{
+#else
+ [Serializable]
+ public class LyricHandle : ICloneable {
+#endif
+ public Lyric L0;
+ public int Index;
+ public Vector Trailing = new Vector();
+
+ public LyricHandle() {
+ L0 = new Lyric();
+ }
+
+ public Lyric getLyricAt( int index ){
+ if( index == 0 ){
+ return L0;
+ }else{
+ return Trailing.get( index - 1 );
+ }
+ }
+
+ public void setLyricAt( int index, Lyric value ){
+ if( index == 0 ){
+ L0 = value;
+ }else{
+ Trailing.set( index - 1, value );
+ }
+ }
+
+ public int getCount(){
+ return Trailing.size() + 1;
+ }
+
+ ///
+ /// type = Lyric用のhandleのコンストラクタ
+ ///
+ /// 歌詞
+ /// 発音記号
+ public LyricHandle( String phrase, String phonetic_symbol ) {
+ L0 = new Lyric( phrase, phonetic_symbol );
+ }
+
+ public Object clone() {
+ LyricHandle ret = new LyricHandle();
+ ret.Index = Index;
+ ret.L0 = (Lyric)L0.clone();
+ int c = Trailing.size();
+ for( int i = 0; i < c; i++ ){
+ Lyric buf = (Lyric)Trailing.get( i ).clone();
+ ret.Trailing.add( buf );
+ }
+ return ret;
+ }
+
+#if !JAVA
+ public object Clone() {
+ return clone();
+ }
+#endif
+
+ public VsqHandle castToVsqHandle() {
+ VsqHandle ret = new VsqHandle();
+ ret.m_type = VsqHandleType.Lyric;
+ ret.L0 = (Lyric)L0.clone();
+ ret.Trailing = Trailing;
+ ret.Index = Index;
+ return ret;
+ }
+ }
+
+#if !JAVA
+}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/MidiEvent.cs b/trunk/Boare.Lib.Vsq/MidiEvent.cs
new file mode 100644
index 0000000..eedee2c
--- /dev/null
+++ b/trunk/Boare.Lib.Vsq/MidiEvent.cs
@@ -0,0 +1,282 @@
+/*
+ * MidiEvent.cs
+ * Copyright (c) 2009 kbinani
+ *
+ * This file is part of Boare.Lib.Vsq.
+ *
+ * Boare.Lib.Vsq is free software; you can redistribute it and/or
+ * modify it under the terms of the BSD License.
+ *
+ * Boare.Lib.Vsq 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.vsq;
+
+import java.io.*;
+import org.kbinani.*;
+#else
+using System;
+using bocoree;
+using bocoree.java.io;
+
+namespace Boare.Lib.Vsq {
+ using boolean = System.Boolean;
+ using Long = System.Int64;
+#endif
+
+ ///
+ /// midiイベント。メタイベントは、メタイベントのデータ長をData[1]に格納せず、生のデータをDataに格納するので、注意が必要
+ ///
+#if JAVA
+ public class MidiEvent implements Comparable {
+#else
+ public struct MidiEvent : IComparable {
+#endif
+ public long clock;
+ public byte firstByte;
+ public byte[] data;
+
+ private static void writeDeltaClock( RandomAccessFile stream, long number )
+#if JAVA
+ throws IOException
+#endif
+ {
+ boolean[] bits = new boolean[64];
+ long val = 0x1;
+ bits[0] = (number & val) == val;
+ for ( int i = 1; i < 64; i++ ) {
+ val = val << 1;
+ bits[i] = (number & val) == val;
+ }
+ int first = 0;
+ for ( int i = 63; i >= 0; i-- ) {
+ if ( bits[i] ) {
+ first = i;
+ break;
+ }
+ }
+ // 何バイト必要か?
+ int bytes = first / 7 + 1;
+ for ( int i = 1; i <= bytes; i++ ) {
+ long num = 0;
+ long count = 0x80;
+ for ( int j = (bytes - i + 1) * 7 - 1; j >= (bytes - i + 1) * 7 - 6 - 1; j-- ) {
+ count = count >> 1;
+ if ( bits[j] ) {
+ num += count;
+ }
+ }
+ if ( i != bytes ) {
+ num += 0x80;
+ }
+ stream.write( (byte)num );
+ }
+ }
+
+ private static long readDeltaClock( RandomAccessFile stream )
+#if JAVA
+ throws IOException
+#endif
+ {
+ long ret = 0;
+ while ( true ) {
+ int i = stream.read();
+ if ( i < 0 ) {
+ break;
+ }
+ byte d = (byte)i;
+ ret = (ret << 7) | ((long)d & 0x7f);
+ if ( (d & 0x80) == 0x00 ) {
+ break;
+ }
+ }
+ return ret;
+ }
+
+ public static MidiEvent read( RandomAccessFile stream, ByRef last_clock, ByRef last_status_byte )
+#if JAVA
+ throws IOException, Exception
+#endif
+ {
+ long delta_clock = readDeltaClock( stream );
+ last_clock.value += delta_clock;
+ byte first_byte = (byte)stream.read();
+ if ( first_byte < 0x80 ) {
+ // ランニングステータスが適用される
+ long pos = stream.getFilePointer();
+ stream.seek( pos - 1 );
+ first_byte = last_status_byte.value;
+ } else {
+ last_status_byte.value = first_byte;
+ }
+ byte ctrl = (byte)(first_byte & (byte)0xf0);
+ if ( ctrl == 0x80 || ctrl == 0x90 || ctrl == 0xA0 || ctrl == 0xB0 || ctrl == 0xE0 || first_byte == 0xF2 ) {
+ // 3byte使用するチャンネルメッセージ:
+ // 0x8*: ノートオフ
+ // 0x9*: ノートオン
+ // 0xA*: ポリフォニック・キープレッシャ
+ // 0xB*: コントロールチェンジ
+ // 0xE*: ピッチベンドチェンジ
+ // 3byte使用するシステムメッセージ
+ // 0xF2: ソングポジション・ポインタ
+ MidiEvent me = new MidiEvent();
+ me.clock = last_clock.value;
+ me.firstByte = first_byte;
+ me.data = new byte[2];
+ stream.read( me.data, 0, 2 );
+ return me;
+ } else if ( ctrl == 0xC0 || ctrl == 0xD0 || first_byte == 0xF1 || first_byte == 0xF2 ) {
+ // 2byte使用するチャンネルメッセージ
+ // 0xC*: プログラムチェンジ
+ // 0xD*: チャンネルプレッシャ
+ // 2byte使用するシステムメッセージ
+ // 0xF1: クォータフレーム
+ // 0xF3: ソングセレクト
+ MidiEvent me = new MidiEvent();
+ me.clock = last_clock.value;
+ me.firstByte = first_byte;
+ me.data = new byte[1];
+ stream.read( me.data, 0, 1 );
+ return me;
+ } else if ( first_byte == 0xF6 ) {
+ // 1byte使用するシステムメッセージ
+ // 0xF6: チューンリクエスト
+ // 0xF7: エンドオブエクスクルーシブ(このクラスではF0ステータスのSysExの一部として取り扱う)
+ // 0xF8: タイミングクロック
+ // 0xFA: スタート
+ // 0xFB: コンティニュー
+ // 0xFC: ストップ
+ // 0xFE: アクティブセンシング
+ // 0xFF: システムリセット
+ MidiEvent me = new MidiEvent();
+ me.clock = last_clock.value;
+ me.firstByte = first_byte;
+ me.data = new byte[0];
+ return me;
+ } else if ( first_byte == 0xff ) {
+ // メタイベント
+ byte meta_event_type = (byte)stream.read();
+ long meta_event_length = readDeltaClock( stream );
+ MidiEvent me = new MidiEvent();
+ me.clock = last_clock.value;
+ me.firstByte = first_byte;
+ me.data = new byte[(int)meta_event_length + 1];
+ me.data[0] = meta_event_type;
+ stream.read( me.data, 1, (int)meta_event_length );
+ return me;
+ } else if ( first_byte == 0xf0 ) {
+ // f0ステータスのSysEx
+ MidiEvent me = new MidiEvent();
+ me.clock = last_clock.value;
+ me.firstByte = first_byte;
+ long sysex_length = readDeltaClock( stream );
+ me.data = new byte[(int)sysex_length + 1];
+ stream.read( me.data, 0, (int)(sysex_length + 1) );
+ return me;
+ } else if ( first_byte == 0xf7 ) {
+ // f7ステータスのSysEx
+ MidiEvent me = new MidiEvent();
+ me.clock = last_clock.value;
+ me.firstByte = first_byte;
+ long sysex_length = readDeltaClock( stream );
+ me.data = new byte[(int)sysex_length];
+ stream.read( me.data, 0, (int)sysex_length );
+ return me;
+ } else {
+ throw new Exception( "don't know how to process first_byte: 0x" + PortUtil.toHexString( first_byte ) );
+ }
+ }
+
+ public void writeData( RandomAccessFile stream )
+#if JAVA
+ throws IOException
+#endif
+ {
+ stream.write( firstByte );
+ if ( firstByte == 0xff ) {
+ stream.write( data[0] );
+ writeDeltaClock( stream, data.Length - 1 );
+ //stream.WriteByte( (byte)(Data.Length - 1) );
+ stream.write( data, 1, data.Length - 1 );
+ } else {
+ stream.write( data, 0, data.Length );
+ }
+ }
+
+ public int compareTo( MidiEvent item ) {
+ if ( clock != item.clock ) {
+ return (int)(clock - item.clock);
+ } else {
+ int first_this = firstByte & 0xf0;
+ int first_item = item.firstByte & 0xf0;
+
+ if ( (first_this == 0x80 || first_this == 0x90) && (first_item == 0x80 || first_item == 0x90) ) {
+ if ( data != null && data.Length >= 2 && item.data != null && item.data.Length >= 2 ) {
+ if ( first_item == 0x90 && item.data[1] == 0 ) {
+ first_item = 0x80;
+ }
+ if ( first_this == 0x90 && data[1] == 0 ) {
+ first_this = 0x80;
+ }
+ if ( data[0] == item.data[0] ) {
+ if ( first_this == 0x90 ) {
+ if ( first_item == 0x80 ) {
+ // ON -> OFF
+ return 1;
+ } else {
+ // ON -> ON
+ return 0;
+ }
+ } else {
+ if ( first_item == 0x80 ) {
+ // OFF -> OFF
+ return 0;
+ } else {
+ // OFF -> ON
+ return -1;
+ }
+ }
+ }
+ }
+ }
+ return (int)(clock - item.clock);
+ }
+ }
+
+#if !JAVA
+ public int CompareTo( MidiEvent item ) {
+ return compareTo( item );
+ }
+#endif
+
+ public static MidiEvent generateTimeSigEvent( int clock, int numerator, int denominator ) {
+ MidiEvent ret = new MidiEvent();
+ ret.clock = clock;
+ ret.firstByte = (byte)0xff;
+ byte b_numer = (byte)(Math.Log( denominator ) / Math.Log( 2 ) + 0.1);
+#if DEBUG
+ PortUtil.println( "VsqEvent.generateTimeSigEvent; b_number=" + b_numer + "; denominator=" + denominator );
+#endif
+ ret.data = new byte[] { 0x58, (byte)numerator, b_numer, 0x18, 0x08 };
+ return ret;
+ }
+
+ public static MidiEvent generateTempoChangeEvent( int clock, int tempo ) {
+ MidiEvent ret = new MidiEvent();
+ ret.clock = clock;
+ ret.firstByte = (byte)0xff;
+ byte b1 = (byte)(tempo & 0xff);
+ tempo = tempo >> 8;
+ byte b2 = (byte)(tempo & 0xff);
+ tempo = tempo >> 8;
+ byte b3 = (byte)(tempo & 0xff);
+ ret.data = new byte[] { (byte)0x51, b3, b2, b1 };
+ return ret;
+ }
+ }
+
+#if !JAVA
+}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/MidiFile.cs b/trunk/Boare.Lib.Vsq/MidiFile.cs
new file mode 100644
index 0000000..f3bf746
--- /dev/null
+++ b/trunk/Boare.Lib.Vsq/MidiFile.cs
@@ -0,0 +1,203 @@
+/*
+ * MidiFile.cs
+ * Copyright (c) 2009 kbinani
+ *
+ * This file is part of Boare.Lib.Vsq.
+ *
+ * Boare.Lib.Vsq is free software; you can redistribute it and/or
+ * modify it under the terms of the BSD License.
+ *
+ * Boare.Lib.Vsq 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.vsq;
+
+import java.io.*;
+import java.util.*;
+import org.kbinani.*;
+#else
+using System;
+using bocoree;
+using bocoree.java.util;
+using bocoree.java.io;
+
+namespace Boare.Lib.Vsq {
+ using boolean = System.Boolean;
+ using Long = System.Int64;
+#endif
+
+ public class MidiFile {
+ private Vector> m_events;
+ private int m_format;
+ private int m_time_format;
+
+ public MidiFile( String path )
+#if JAVA
+ throws FileNotFoundException
+#endif
+ {
+ RandomAccessFile stream = new RandomAccessFile( path, "r" );
+ try {
+ // ヘッダ
+ byte[] byte4 = new byte[4];
+ stream.read( byte4, 0, 4 );
+ if ( PortUtil.make_uint32_be( byte4 ) != 0x4d546864 ) {
+ throw new Exception( "header error: MThd" );
+ }
+
+ // データ長
+ stream.read( byte4, 0, 4 );
+ long length = PortUtil.make_uint32_be( byte4 );
+
+ // フォーマット
+ stream.read( byte4, 0, 2 );
+ m_format = PortUtil.make_uint16_be( byte4 );
+
+ // トラック数
+ int tracks = 0;
+ stream.read( byte4, 0, 2 );
+ tracks = (int)PortUtil.make_uint16_be( byte4 );
+
+ // 時間分解能
+ stream.read( byte4, 0, 2 );
+ m_time_format = PortUtil.make_uint16_be( byte4 );
+
+ // 各トラックを読込み
+ m_events = new Vector>();
+ for ( int track = 0; track < tracks; track++ ) {
+ Vector track_events = new Vector();
+ // ヘッダー
+ stream.read( byte4, 0, 4 );
+ if ( PortUtil.make_uint32_be( byte4 ) != 0x4d54726b ) {
+ throw new Exception( "header error; MTrk" );
+ }
+
+ // チャンクサイズ
+ stream.read( byte4, 0, 4 );
+ long size = (long)PortUtil.make_uint32_be( byte4 );
+ long startpos = stream.getFilePointer();
+
+ // チャンクの終わりまで読込み
+ ByRef clock = new ByRef( (long)0 );
+ ByRef last_status_byte = new ByRef( (byte)0x00 );
+ while ( stream.getFilePointer() < startpos + size ) {
+ MidiEvent mi = MidiEvent.read( stream, clock, last_status_byte );
+ track_events.add( mi );
+ }
+ if ( m_time_format != 480 ) {
+ int count = track_events.size();
+ for ( int i = 0; i < count; i++ ) {
+ MidiEvent mi = track_events.get( i );
+ mi.clock = mi.clock * 480 / m_time_format;
+ track_events.set( i, mi );
+ }
+ }
+ m_events.add( track_events );
+ }
+ m_time_format = 480;
+#if DEBUG && MIDI_PRINT_TO_FILE
+ String dbg = PortUtil.combinePath( PortUtil.getDirectoryName( path ), PortUtil.getFileNameWithoutExtension( path ) + ".txt" );
+ BufferedWriter sw = null;
+ try {
+ sw = new BufferedWriter( new FileWriter( dbg ) );
+ const String format = " {0,8} 0x{1:X4} {2,-35} 0x{3:X2} 0x{4:X2}";
+ const String format0 = " {0,8} 0x{1:X4} {2,-35} 0x{3:X2}";
+ for ( int track = 1; track < m_events.size(); track++ ) {
+ sw.write( "MidiFile..ctor; track=" + track );
+ sw.newLine();
+ byte msb, lsb, data_msb, data_lsb;
+ msb = lsb = data_msb = data_lsb = 0x0;
+ for ( int i = 0; i < m_events.get( track ).size(); i++ ) {
+ if ( m_events.get( track ).get( i ).firstByte == 0xb0 ) {
+ switch ( m_events.get( track ).get( i ).data[0] ) {
+ case 0x63:
+ msb = m_events.get( track ).get( i ).data[1];
+ lsb = 0x0;
+ break;
+ case 0x62:
+ lsb = m_events.get( track ).get( i ).data[1];
+ break;
+ case 0x06:
+ data_msb = m_events.get( track ).get( i ).data[1];
+ ushort nrpn = (ushort)(msb << 8 | lsb);
+ String name = NRPN.getName( nrpn );
+ if ( name.Equals( "" ) ) {
+ name = "* * UNKNOWN * *";
+ sw.write( String.Format( format0, m_events.get( track ).get( i ).clock, nrpn, name, data_msb ) );
+ sw.newLine();
+ } else {
+ //if ( !NRPN.is_require_data_lsb( nrpn ) ) {
+ sw.write( String.Format( format0, m_events.get( track ).get( i ).clock, nrpn, name, data_msb ) );
+ sw.newLine();
+ //}
+ }
+ break;
+ case 0x26:
+ data_lsb = m_events.get( track ).get( i ).data[1];
+ ushort nrpn2 = (ushort)(msb << 8 | lsb);
+ String name2 = NRPN.getName( nrpn2 );
+ if ( name2.Equals( "" ) ) {
+ name2 = "* * UNKNOWN * *";
+ }
+ sw.write( String.Format( format, m_events.get( track ).get( i ).clock, nrpn2, name2, data_msb, data_lsb ) );
+ sw.newLine();
+ break;
+ }
+ }
+ }
+ }
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sw != null ) {
+ try {
+ sw.close();
+ } catch ( Exception ex2 ) {
+ }
+ }
+ }
+#endif
+ } catch ( Exception ex ) {
+ } finally {
+ if ( stream != null ) {
+ try {
+ stream.close();
+ } catch ( Exception ex2 ) {
+ }
+ }
+ }
+ }
+
+ public Vector getMidiEventList( int track ) {
+ if ( m_events == null ) {
+ return new Vector();
+ } else if ( 0 <= track && track < m_events.size() ) {
+ return m_events.get( track );
+ } else {
+ return new Vector();
+ }
+ }
+
+ public int getTrackCount() {
+ if ( m_events == null ) {
+ return 0;
+ } else {
+ return m_events.size();
+ }
+ }
+
+ public void close() {
+ if ( m_events != null ) {
+ int c = m_events.size();
+ for ( int i = 0; i < c; i++ ) {
+ m_events.get( i ).clear();
+ }
+ m_events.clear();
+ }
+ }
+ }
+
+#if !JAVA
+}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/NRPN.cs b/trunk/Boare.Lib.Vsq/NRPN.cs
index 88c9596..af0a673 100644
--- a/trunk/Boare.Lib.Vsq/NRPN.cs
+++ b/trunk/Boare.Lib.Vsq/NRPN.cs
@@ -11,595 +11,573 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
+#if JAVA
+package org.kbinani.vsq;
+
+import java.util.*;
+import java.lang.reflect.*;
+import org.kbinani.*;
+#else
using System;
using System.Reflection;
-using System.Collections.Generic;
-
using bocoree;
+using bocoree.java.util;
namespace Boare.Lib.Vsq {
-
using boolean = System.Boolean;
+ using Integer = System.Int32;
+#endif
- public static class NRPN {
+ public class NRPN {
///
/// (0x5000) Version number(MSB) &, Device number(LSB)
///
- public const ushort CVM_NM_VERSION_AND_DEVICE = 0x5000;
+ public const int CVM_NM_VERSION_AND_DEVICE = 0x5000;
///
/// (0x5001) Delay in millisec(MSB, LSB)
///
- public const ushort CVM_NM_DELAY = 0x5001;
+ public const int CVM_NM_DELAY = 0x5001;
///
/// (0x5002) Note number(MSB)
///
- public const ushort CVM_NM_NOTE_NUMBER = 0x5002;
+ public const int CVM_NM_NOTE_NUMBER = 0x5002;
///
/// (0x5003) Velocity(MSB)
///
- public const ushort CVM_NM_VELOCITY = 0x5003;
+ public const int CVM_NM_VELOCITY = 0x5003;
///
/// (0x5004) Note Duration in millisec(MSB, LSB)
///
- public const ushort CVM_NM_NOTE_DURATION = 0x5004;
+ public const int CVM_NM_NOTE_DURATION = 0x5004;
///
/// (0x5005) Note Location(MSB)
///
- public const ushort CVM_NM_NOTE_LOCATION = 0x5005;
+ public const int CVM_NM_NOTE_LOCATION = 0x5005;
///
/// (0x5006) Attack Type(MSB, LSB)
///
- public const ushort CVM_NM_ATTACK_TYPE = 0x5006;
+ public const int CVM_NM_ATTACK_TYPE = 0x5006;
///
/// (0x5007) Attack Duration in millisec(MSB, LSB)
///
- public const ushort CVM_NM_ATTACK_DURATION = 0x5007;
+ public const int CVM_NM_ATTACK_DURATION = 0x5007;
///
/// (0x5008) Attack Depth(MSB)
///
- public const ushort CVM_NM_ATTACK_DEPTH = 0x5008;
+ public const int CVM_NM_ATTACK_DEPTH = 0x5008;
///
/// (0x500c) Index of Vibrato DB(MSB: ID_H00, LSB:ID_L00)
///
- public const ushort CVM_NM_INDEX_OF_VIBRATO_DB = 0x500c;
+ public const int CVM_NM_INDEX_OF_VIBRATO_DB = 0x500c;
///
/// (0x500d) Vibrato configuration(MSB: Index of Vibrato Type, LSB: Duration &, Configuration parameter of vibrato)
///
- public const ushort CVM_NM_VIBRATO_CONFIG = 0x500d;
+ public const int CVM_NM_VIBRATO_CONFIG = 0x500d;
///
/// (0x500e) Vibrato Delay(MSB)
///
- public const ushort CVM_NM_VIBRATO_DELAY = 0x500e;
- /*///
- /// (0x5011) Unknonw(MSB), only used in VOCALOID1
- ///
- public const ushort CVM_NM_UNKNOWN1 = 0x5011;*/
+ public const int CVM_NM_VIBRATO_DELAY = 0x500e;
+ // //
+ // // (0x5011) Unknonw(MSB), only used in VOCALOID1
+ // //
+ // public const int CVM_NM_UNKNOWN1 = 0x5011;
///
/// (0x5012) Number of phonetic symbols in bytes(MSB)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL_BYTES = 0x5012;
+ public const int CVM_NM_PHONETIC_SYMBOL_BYTES = 0x5012;
///
/// (0x5013) Phonetic symbol 1(MSB:Phonetic symbol 1, LSB: Consonant adjustment 1)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL1 = 0x5013;
+ public const int CVM_NM_PHONETIC_SYMBOL1 = 0x5013;
///
/// (0x5014) Phonetic symbol 2(MSB:Phonetic symbol 2, LSB: Consonant adjustment 2)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL2 = 0x5014;
+ public const int CVM_NM_PHONETIC_SYMBOL2 = 0x5014;
///
/// (0x5015) Phonetic symbol 3(MSB:Phonetic symbol 3, LSB: Consonant adjustment 3)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL3 = 0x5015;
+ public const int CVM_NM_PHONETIC_SYMBOL3 = 0x5015;
///
/// (0x5016) Phonetic symbol 4(MSB:Phonetic symbol 4, LSB: Consonant adjustment 4)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL4 = 0x5016;
+ public const int CVM_NM_PHONETIC_SYMBOL4 = 0x5016;
///
/// (0x5017) Phonetic symbol 5(MSB:Phonetic symbol 5, LSB: Consonant adjustment 5)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL5 = 0x5017;
+ public const int CVM_NM_PHONETIC_SYMBOL5 = 0x5017;
///
/// (0x5018) Phonetic symbol 6(MSB:Phonetic symbol 6, LSB: Consonant adjustment 6)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL6 = 0x5018;
+ public const int CVM_NM_PHONETIC_SYMBOL6 = 0x5018;
///
/// (0x5019) Phonetic symbol 7(MSB:Phonetic symbol 7, LSB: Consonant adjustment 7)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL7 = 0x5019;
+ public const int CVM_NM_PHONETIC_SYMBOL7 = 0x5019;
///
/// (0x501a) Phonetic symbol 8(MSB:Phonetic symbol 8, LSB: Consonant adjustment 8)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL8 = 0x501a;
+ public const int CVM_NM_PHONETIC_SYMBOL8 = 0x501a;
///
/// (0x501b) Phonetic symbol 9(MSB:Phonetic symbol 9, LSB: Consonant adjustment 9)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL9 = 0x501b;
+ public const int CVM_NM_PHONETIC_SYMBOL9 = 0x501b;
///
/// (0x501c) Phonetic symbol 10(MSB:Phonetic symbol 10, LSB: Consonant adjustment 10)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL10 = 0x501c;
+ public const int CVM_NM_PHONETIC_SYMBOL10 = 0x501c;
///
/// (0x501d) Phonetic symbol 11(MSB:Phonetic symbol 11, LSB: Consonant adjustment 11)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL11 = 0x501d;
+ public const int CVM_NM_PHONETIC_SYMBOL11 = 0x501d;
///
/// (0x501e) Phonetic symbol 12(MSB:Phonetic symbol 12, LSB: Consonant adjustment 12)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL12 = 0x501e;
+ public const int CVM_NM_PHONETIC_SYMBOL12 = 0x501e;
///
/// (0x501f) Phonetic symbol 13(MSB:Phonetic symbol 13, LSB: Consonant adjustment 13)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL13 = 0x501f;
+ public const int CVM_NM_PHONETIC_SYMBOL13 = 0x501f;
///
/// (0x5020) Phonetic symbol 14(MSB:Phonetic symbol 14, LSB: Consonant adjustment 14)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL14 = 0x5020;
+ public const int CVM_NM_PHONETIC_SYMBOL14 = 0x5020;
///
/// (0x5021) Phonetic symbol 15(MSB:Phonetic symbol 15, LSB: Consonant adjustment 15)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL15 = 0x5021;
+ public const int CVM_NM_PHONETIC_SYMBOL15 = 0x5021;
///
/// (0x5022) Phonetic symbol 16(MSB:Phonetic symbol 16, LSB: Consonant adjustment 16)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL16 = 0x5022;
+ public const int CVM_NM_PHONETIC_SYMBOL16 = 0x5022;
///
/// (0x5023) Phonetic symbol 17(MSB:Phonetic symbol 17, LSB: Consonant adjustment 17)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL17 = 0x5023;
+ public const int CVM_NM_PHONETIC_SYMBOL17 = 0x5023;
///
/// (0x5024) Phonetic symbol 18(MSB:Phonetic symbol 18, LSB: Consonant adjustment 18)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL18 = 0x5024;
+ public const int CVM_NM_PHONETIC_SYMBOL18 = 0x5024;
///
/// (0x5025) Phonetic symbol 19(MSB:Phonetic symbol 19, LSB: Consonant adjustment 19)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL19 = 0x5025;
+ public const int CVM_NM_PHONETIC_SYMBOL19 = 0x5025;
///
/// (0x5026) Phonetic symbol 20(MSB:Phonetic symbol 20, LSB: Consonant adjustment 20)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL20 = 0x5026;
+ public const int CVM_NM_PHONETIC_SYMBOL20 = 0x5026;
///
/// (0x5027) Phonetic symbol 21(MSB:Phonetic symbol 21, LSB: Consonant adjustment 21)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL21 = 0x5027;
+ public const int CVM_NM_PHONETIC_SYMBOL21 = 0x5027;
///
/// (0x5028) Phonetic symbol 22(MSB:Phonetic symbol 22, LSB: Consonant adjustment 22)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL22 = 0x5028;
+ public const int CVM_NM_PHONETIC_SYMBOL22 = 0x5028;
///
/// (0x5029) Phonetic symbol 23(MSB:Phonetic symbol 23, LSB: Consonant adjustment 23)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL23 = 0x5029;
+ public const int CVM_NM_PHONETIC_SYMBOL23 = 0x5029;
///
/// (0x502a) Phonetic symbol 24(MSB:Phonetic symbol 24, LSB: Consonant adjustment 24)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL24 = 0x502a;
+ public const int CVM_NM_PHONETIC_SYMBOL24 = 0x502a;
///
/// (0x502b) Phonetic symbol 25(MSB:Phonetic symbol 25, LSB: Consonant adjustment 25)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL25 = 0x502b;
+ public const int CVM_NM_PHONETIC_SYMBOL25 = 0x502b;
///
/// (0x502c) Phonetic symbol 26(MSB:Phonetic symbol 26, LSB: Consonant adjustment 26)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL26 = 0x502c;
+ public const int CVM_NM_PHONETIC_SYMBOL26 = 0x502c;
///
/// (0x502d) Phonetic symbol 27(MSB:Phonetic symbol 27, LSB: Consonant adjustment 27)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL27 = 0x502d;
+ public const int CVM_NM_PHONETIC_SYMBOL27 = 0x502d;
///
/// (0x502e) Phonetic symbol 28(MSB:Phonetic symbol 28, LSB: Consonant adjustment 28)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL28 = 0x502e;
+ public const int CVM_NM_PHONETIC_SYMBOL28 = 0x502e;
///
/// (0x502f) Phonetic symbol 29(MSB:Phonetic symbol 29, LSB: Consonant adjustment 29)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL29 = 0x502f;
+ public const int CVM_NM_PHONETIC_SYMBOL29 = 0x502f;
///
/// (0x5030) Phonetic symbol 30(MSB:Phonetic symbol 30, LSB: Consonant adjustment 30)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL30 = 0x5030;
+ public const int CVM_NM_PHONETIC_SYMBOL30 = 0x5030;
///
/// (0x5031) Phonetic symbol 31(MSB:Phonetic symbol 31, LSB: Consonant adjustment 31)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL31 = 0x5031;
+ public const int CVM_NM_PHONETIC_SYMBOL31 = 0x5031;
///
/// (0x5032) Phonetic symbol 32(MSB:Phonetic symbol 32, LSB: Consonant adjustment 32)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL32 = 0x5032;
+ public const int CVM_NM_PHONETIC_SYMBOL32 = 0x5032;
///
/// (0x5033) Phonetic symbol 33(MSB:Phonetic symbol 33, LSB: Consonant adjustment 33)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL33 = 0x5033;
+ public const int CVM_NM_PHONETIC_SYMBOL33 = 0x5033;
///
/// (0x5034) Phonetic symbol 34(MSB:Phonetic symbol 34, LSB: Consonant adjustment 34)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL34 = 0x5034;
+ public const int CVM_NM_PHONETIC_SYMBOL34 = 0x5034;
///
/// (0x5035) Phonetic symbol 35(MSB:Phonetic symbol 35, LSB: Consonant adjustment 35)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL35 = 0x5035;
+ public const int CVM_NM_PHONETIC_SYMBOL35 = 0x5035;
///
/// (0x5036) Phonetic symbol 36(MSB:Phonetic symbol 36, LSB: Consonant adjustment 36)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL36 = 0x5036;
+ public const int CVM_NM_PHONETIC_SYMBOL36 = 0x5036;
///
/// (0x5037) Phonetic symbol 37(MSB:Phonetic symbol 37, LSB: Consonant adjustment 37)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL37 = 0x5037;
+ public const int CVM_NM_PHONETIC_SYMBOL37 = 0x5037;
///
/// (0x5038) Phonetic symbol 38(MSB:Phonetic symbol 38, LSB: Consonant adjustment 38)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL38 = 0x5038;
+ public const int CVM_NM_PHONETIC_SYMBOL38 = 0x5038;
///
/// (0x5039) Phonetic symbol 39(MSB:Phonetic symbol 39, LSB: Consonant adjustment 39)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL39 = 0x5039;
+ public const int CVM_NM_PHONETIC_SYMBOL39 = 0x5039;
///
/// (0x503a) Phonetic symbol 40(MSB:Phonetic symbol 40, LSB: Consonant adjustment 40)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL40 = 0x503a;
+ public const int CVM_NM_PHONETIC_SYMBOL40 = 0x503a;
///
/// (0x503b) Phonetic symbol 41(MSB:Phonetic symbol 41, LSB: Consonant adjustment 41)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL41 = 0x503b;
+ public const int CVM_NM_PHONETIC_SYMBOL41 = 0x503b;
///
/// (0x503c) Phonetic symbol 42(MSB:Phonetic symbol 42, LSB: Consonant adjustment 42)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL42 = 0x503c;
+ public const int CVM_NM_PHONETIC_SYMBOL42 = 0x503c;
///
/// (0x503d) Phonetic symbol 43(MSB:Phonetic symbol 43, LSB: Consonant adjustment 43)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL43 = 0x503d;
+ public const int CVM_NM_PHONETIC_SYMBOL43 = 0x503d;
///
/// (0x503e) Phonetic symbol 44(MSB:Phonetic symbol 44, LSB: Consonant adjustment 44)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL44 = 0x503e;
+ public const int CVM_NM_PHONETIC_SYMBOL44 = 0x503e;
///
/// (0x503f) Phonetic symbol 45(MSB:Phonetic symbol 45, LSB: Consonant adjustment 45)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL45 = 0x503f;
+ public const int CVM_NM_PHONETIC_SYMBOL45 = 0x503f;
///
/// (0x5040) Phonetic symbol 46(MSB:Phonetic symbol 46, LSB: Consonant adjustment 46)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL46 = 0x5040;
+ public const int CVM_NM_PHONETIC_SYMBOL46 = 0x5040;
///
/// (0x5041) Phonetic symbol 47(MSB:Phonetic symbol 47, LSB: Consonant adjustment 47)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL47 = 0x5041;
+ public const int CVM_NM_PHONETIC_SYMBOL47 = 0x5041;
///
/// (0x5042) Phonetic symbol 48(MSB:Phonetic symbol 48, LSB: Consonant adjustment 48)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL48 = 0x5042;
+ public const int CVM_NM_PHONETIC_SYMBOL48 = 0x5042;
///
/// (0x5043) Phonetic symbol 49(MSB:Phonetic symbol 49, LSB: Consonant adjustment 49)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL49 = 0x5043;
+ public const int CVM_NM_PHONETIC_SYMBOL49 = 0x5043;
///
/// (0x5044) Phonetic symbol 50(MSB:Phonetic symbol 50, LSB: Consonant adjustment 50)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL50 = 0x5044;
+ public const int CVM_NM_PHONETIC_SYMBOL50 = 0x5044;
///
/// (0x5045) Phonetic symbol 51(MSB:Phonetic symbol 51, LSB: Consonant adjustment 51)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL51 = 0x5045;
+ public const int CVM_NM_PHONETIC_SYMBOL51 = 0x5045;
///
/// (0x5046) Phonetic symbol 52(MSB:Phonetic symbol 52, LSB: Consonant adjustment 52)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL52 = 0x5046;
+ public const int CVM_NM_PHONETIC_SYMBOL52 = 0x5046;
///
/// (0x5047) Phonetic symbol 53(MSB:Phonetic symbol 53, LSB: Consonant adjustment 53)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL53 = 0x5047;
+ public const int CVM_NM_PHONETIC_SYMBOL53 = 0x5047;
///
/// (0x5048) Phonetic symbol 54(MSB:Phonetic symbol 54, LSB: Consonant adjustment 54)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL54 = 0x5048;
+ public const int CVM_NM_PHONETIC_SYMBOL54 = 0x5048;
///
/// (0x5049) Phonetic symbol 55(MSB:Phonetic symbol 55, LSB: Consonant adjustment 55)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL55 = 0x5049;
+ public const int CVM_NM_PHONETIC_SYMBOL55 = 0x5049;
///
/// (0x504a) Phonetic symbol 56(MSB:Phonetic symbol 56, LSB: Consonant adjustment 56)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL56 = 0x504a;
+ public const int CVM_NM_PHONETIC_SYMBOL56 = 0x504a;
///
/// (0x504b) Phonetic symbol 57(MSB:Phonetic symbol 57, LSB: Consonant adjustment 57)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL57 = 0x504b;
+ public const int CVM_NM_PHONETIC_SYMBOL57 = 0x504b;
///
/// (0x504c) Phonetic symbol 58(MSB:Phonetic symbol 58, LSB: Consonant adjustment 58)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL58 = 0x504c;
+ public const int CVM_NM_PHONETIC_SYMBOL58 = 0x504c;
///
/// (0x504d) Phonetic symbol 59(MSB:Phonetic symbol 59, LSB: Consonant adjustment 59)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL59 = 0x504d;
+ public const int CVM_NM_PHONETIC_SYMBOL59 = 0x504d;
///
/// (0x504e) Phonetic symbol 60(MSB:Phonetic symbol 60, LSB: Consonant adjustment 60)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL60 = 0x504e;
+ public const int CVM_NM_PHONETIC_SYMBOL60 = 0x504e;
///
/// (0x504f) Phonetic symbol continuation(MSB, 0x7f=end, 0x00=continue)
///
- public const ushort CVM_NM_PHONETIC_SYMBOL_CONTINUATION = 0x504f;
+ public const int CVM_NM_PHONETIC_SYMBOL_CONTINUATION = 0x504f;
///
/// (0x5050) v1mean in Cent/5(MSB)
///
- public const ushort CVM_NM_V1MEAN = 0x5050;
+ public const int CVM_NM_V1MEAN = 0x5050;
///
/// (0x5051) d1mean in millisec/5(MSB)
///
- public const ushort CVM_NM_D1MEAN = 0x5051;
+ public const int CVM_NM_D1MEAN = 0x5051;
///
/// (0x5052) d1meanFirstNote in millisec/5(MSB)
///
- public const ushort CVM_NM_D1MEAN_FIRST_NOTE = 0x5052;
+ public const int CVM_NM_D1MEAN_FIRST_NOTE = 0x5052;
///
/// (0x5053) d2mean in millisec/5(MSB)
///
- public const ushort CVM_NM_D2MEAN = 0x5053;
+ public const int CVM_NM_D2MEAN = 0x5053;
///
/// (0x5054) d4mean in millisec/5(MSB)
///
- public const ushort CVM_NM_D4MEAN = 0x5054;
+ public const int CVM_NM_D4MEAN = 0x5054;
///
/// (0x5055) pMeanOnsetFirstNote in Cent/5(MSB)
///
- public const ushort CVM_NM_PMEAN_ONSET_FIRST_NOTE = 0x5055;
+ public const int CVM_NM_PMEAN_ONSET_FIRST_NOTE = 0x5055;
///
/// (0x5056) vMeanNoteTransition in Cent/5(MSB)
///
- public const ushort CVM_NM_VMEAN_NOTE_TRNSITION = 0x5056;
+ public const int CVM_NM_VMEAN_NOTE_TRNSITION = 0x5056;
///
/// (0x5057) pMeanEndingNote in Cent/5(MSB)
///
- public const ushort CVM_NM_PMEAN_ENDING_NOTE = 0x5057;
+ public const int CVM_NM_PMEAN_ENDING_NOTE = 0x5057;
///
/// (0x5058) AddScooptoUpIntervals &, AddPortamentoToDownIntervals(MSB)
///
- public const ushort CVM_NM_ADD_PORTAMENTO = 0x5058;
+ public const int CVM_NM_ADD_PORTAMENTO = 0x5058;
///
/// (0x5059) changAfterPeak(MSB)
///
- public const ushort CVM_NM_CHANGE_AFTER_PEAK = 0x5059;
+ public const int CVM_NM_CHANGE_AFTER_PEAK = 0x5059;
///
/// (0x505a) Accent(MSB)
///
- public const ushort CVM_NM_ACCENT = 0x505a;
+ public const int CVM_NM_ACCENT = 0x505a;
///
/// (0x507f) Note message continuation(MSB)
///
- public const ushort CVM_NM_NOTE_MESSAGE_CONTINUATION = 0x507f;
+ public const int CVM_NM_NOTE_MESSAGE_CONTINUATION = 0x507f;
///
/// (0x5075) Extended Note message; Voice Overlap(MSB, LSB)(VoiceOverlap = ((MSB & 0x7f) << 7) | (LSB & 0x7f) - 8192)
///
- public const ushort CVM_EXNM_VOICE_OVERLAP = 0x5075;
+ public const int CVM_EXNM_VOICE_OVERLAP = 0x5075;
///
/// (0x5076) Extended Note message; Flags length in bytes(MSB, LSB)
///
- public const ushort CVM_EXNM_FLAGS_BYTES = 0x5076;
+ public const int CVM_EXNM_FLAGS_BYTES = 0x5076;
///
/// (0x5077) Extended Note message; Flag(MSB)
///
- public const ushort CVM_EXNM_FLAGS = 0x5077;
+ public const int CVM_EXNM_FLAGS = 0x5077;
///
/// (0x5078) Extended Note message; Flag continuation(MSB)(MSB, 0x7f=end, 0x00=continue)
///
- public const ushort CVM_EXNM_FLAGS_CONINUATION = 0x5078;
+ public const int CVM_EXNM_FLAGS_CONINUATION = 0x5078;
///
/// (0x5079) Extended Note message; Moduration(MSB, LSB)(Moduration = ((MSB & 0x7f) << 7) | (LSB & 0x7f) - 100)
///
- public const ushort CVM_EXNM_MODURATION = 0x5079;
+ public const int CVM_EXNM_MODURATION = 0x5079;
///
/// (0x507a) Extended Note message; PreUtterance(MSB, LSB)(PreUtterance = ((MSB & 0x7f) << 7) | (LSB & 0x7f) - 8192)
///
- public const ushort CVM_EXNM_PRE_UTTERANCE = 0x507a;
+ public const int CVM_EXNM_PRE_UTTERANCE = 0x507a;
///
/// (0x507e) Extended Note message; Envelope: value1(MSB, LSB) actual value = (value3.msb & 0xf) << 28 | (value2.msb & 0x7f) << 21 | (value2.lsb & 0x7f) << 14 | (value1.msb & 0x7f) << 7 | (value1.lsb & 0x7f)
///
- public const ushort CVM_EXNM_ENV_DATA1 = 0x507e;
+ public const int CVM_EXNM_ENV_DATA1 = 0x507e;
///
/// (0x507d) Extended Note message; Envelope: value2(MSB, LSB)
///
- public const ushort CVM_EXNM_ENV_DATA2 = 0x507d;
+ public const int CVM_EXNM_ENV_DATA2 = 0x507d;
///
/// (0x507c) Extended Note message; Envelope: value3(MSB)
///
- public const ushort CVM_EXNM_ENV_DATA3 = 0x507c;
+ public const int CVM_EXNM_ENV_DATA3 = 0x507c;
///
/// (0x507b) Extended Note message; Envelope: data point continuation(MSB)(MSB, 0x7f=end, 0x00=continue)
///
- public const ushort CVM_EXNM_ENV_DATA_CONTINUATION = 0x507b;
+ public const int CVM_EXNM_ENV_DATA_CONTINUATION = 0x507b;
///
/// (0x6000) Version number &, Device number(MSB, LSB)
///
- public const ushort CC_BS_VERSION_AND_DEVICE = 0x6000;
+ public const int CC_BS_VERSION_AND_DEVICE = 0x6000;
///
/// (0x6001) Delay in millisec(MSB, LSB)
///
- public const ushort CC_BS_DELAY = 0x6001;
+ public const int CC_BS_DELAY = 0x6001;
///
/// (0x6002) Laugnage type(MSB, optional LSB)
///
- public const ushort CC_BS_LANGUAGE_TYPE = 0x6002;
+ public const int CC_BS_LANGUAGE_TYPE = 0x6002;
///
/// (0x6100) Version number &, device number(MSB, LSB)
///
- public const ushort CC_CV_VERSION_AND_DEVICE = 0x6100;
+ public const int CC_CV_VERSION_AND_DEVICE = 0x6100;
///
/// (0x6101) Delay in millisec(MSB, LSB)
///
- public const ushort CC_CV_DELAY = 0x6101;
+ public const int CC_CV_DELAY = 0x6101;
///
/// (0x6102) Volume value(MSB)
///
- public const ushort CC_CV_VOLUME = 0x6102;
+ public const int CC_CV_VOLUME = 0x6102;
///
/// (0x6200) Version number &, device number(MSB, LSB)
///
- public const ushort CC_P_VERSION_AND_DEVICE = 0x6200;
+ public const int CC_P_VERSION_AND_DEVICE = 0x6200;
///
/// (0x6201) Delay in millisec(MSB, LSB)
///
- public const ushort CC_P_DELAY = 0x6201;
+ public const int CC_P_DELAY = 0x6201;
///
/// (0x6202) Pan value(MSB)
///
- public const ushort CC_PAN = 0x6202;
+ public const int CC_PAN = 0x6202;
///
/// (0x6300) Version number &, device number(MSB, LSB)
///
- public const ushort CC_E_VESION_AND_DEVICE = 0x6300;
+ public const int CC_E_VESION_AND_DEVICE = 0x6300;
///
/// (0x6301) Delay in millisec(MSB, LSB)
///
- public const ushort CC_E_DELAY = 0x6301;
+ public const int CC_E_DELAY = 0x6301;
///
/// (0x6302) Expression vlaue(MSB)
///
- public const ushort CC_E_EXPRESSION = 0x6302;
+ public const int CC_E_EXPRESSION = 0x6302;
///
/// (0x6400) Version number &, device number(MSB, LSB)
///
- public const ushort CC_VR_VERSION_AND_DEVICE = 0x6400;
+ public const int CC_VR_VERSION_AND_DEVICE = 0x6400;
///
/// (0x6401) Delay in millisec(MSB, LSB)
///
- public const ushort CC_VR_DELAY = 0x6401;
+ public const int CC_VR_DELAY = 0x6401;
///
/// (0x6402) Vibrato Rate value(MSB)
///
- public const ushort CC_VR_VIBRATO_RATE = 0x6402;
+ public const int CC_VR_VIBRATO_RATE = 0x6402;
///
/// (0x6500) Version number &, device number(MSB, LSB)
///
- public const ushort CC_VD_VERSION_AND_DEVICE = 0x6500;
+ public const int CC_VD_VERSION_AND_DEVICE = 0x6500;
///
/// (0x6501) Delay in millisec(MSB, LSB)
///
- public const ushort CC_VD_DELAY = 0x6501;
+ public const int CC_VD_DELAY = 0x6501;
///
/// (0x6502) Vibrato Depth value(MSB)
///
- public const ushort CC_VD_VIBRATO_DEPTH = 0x6502;
+ public const int CC_VD_VIBRATO_DEPTH = 0x6502;
///
/// (0x6600) Version number &, device number(MSB, LSB)
///
- public const ushort CC_FX2_VERSION_AND_DEVICE = 0x6600;
+ public const int CC_FX2_VERSION_AND_DEVICE = 0x6600;
///
/// (0x6601) Delay in millisec(MSB, LSB)
///
- public const ushort CC_FX2_DELAY = 0x6601;
+ public const int CC_FX2_DELAY = 0x6601;
///
/// (0x6602) Effect2 Depth(MSB)
///
- public const ushort CC_FX2_EFFECT2_DEPTH = 0x6602;
+ public const int CC_FX2_EFFECT2_DEPTH = 0x6602;
///
/// (0x6700) Version number &, device number(MSB, LSB)
///
- public const ushort CC_PBS_VERSION_AND_DEVICE = 0x6700;
+ public const int CC_PBS_VERSION_AND_DEVICE = 0x6700;
///
/// (0x6701) Delay in millisec(MSB, LSB)
///
- public const ushort CC_PBS_DELAY = 0x6701;
+ public const int CC_PBS_DELAY = 0x6701;
///
/// (0x6702) Pitch Bend Sensitivity(MSB, LSB)
///
- public const ushort CC_PBS_PITCH_BEND_SENSITIVITY = 0x6702;
+ public const int CC_PBS_PITCH_BEND_SENSITIVITY = 0x6702;
///
/// (0x5300) Version number &, device number(MSB, LSB)
///
- public const ushort PC_VERSION_AND_DEVICE = 0x5300;
+ public const int PC_VERSION_AND_DEVICE = 0x5300;
///
/// (0x5301) Delay in millisec(MSB, LSB)
///
- public const ushort PC_DELAY = 0x5301;
+ public const int PC_DELAY = 0x5301;
///
/// (0x5302) Voice Type(MSB)
///
- public const ushort PC_VOICE_TYPE = 0x5302;
+ public const int PC_VOICE_TYPE = 0x5302;
///
/// (0x5400) Version number &, device number(MSB, LSB)
///
- public const ushort PB_VERSION_AND_DEVICE = 0x5400;
+ public const int PB_VERSION_AND_DEVICE = 0x5400;
///
/// (0x5401) Delay in millisec(MSB, LSB)
///
- public const ushort PB_DELAY = 0x5401;
+ public const int PB_DELAY = 0x5401;
///
/// (0x5402) Pitch Bend value(MSB, LSB)
///
- public const ushort PB_PITCH_BEND = 0x5402;
+ public const int PB_PITCH_BEND = 0x5402;
///
/// (0x5500) Version number &, device number(MSB, LSB)
///
- public const ushort VCP_VERSION_AND_DEVICE = 0x5500;
+ public const int VCP_VERSION_AND_DEVICE = 0x5500;
///
/// (0x5501) Delay in millisec(MSB, LSB)
///
- public const ushort VCP_DELAY = 0x5501;
+ public const int VCP_DELAY = 0x5501;
///
/// (0x5502) Voice Change Parameter ID(MSB)
///
- public const ushort VCP_VOICE_CHANGE_PARAMETER_ID = 0x5502;
+ public const int VCP_VOICE_CHANGE_PARAMETER_ID = 0x5502;
///
/// (0x5503) Voice Change Parameter value(MSB)
///
- public const ushort VCP_VOICE_CHANGE_PARAMETER = 0x5503;
+ public const int VCP_VOICE_CHANGE_PARAMETER = 0x5503;
- private class NrpnIterator : Iterator {
- private Vector nrpns = new Vector();
- private int m_pos = -1;
-
- public NrpnIterator() {
- Type t = typeof( NRPN );
- foreach ( FieldInfo fi in t.GetFields() ) {
- if ( fi.FieldType.Equals( typeof( ushort ) ) ) {
- nrpns.add( (ushort)fi.GetValue( t ) );
- }
- }
- }
-
- public boolean hasNext() {
- if ( 0 <= m_pos + 1 && m_pos + 1 < nrpns.size() ) {
- return true;
- } else {
- return false;
- }
- }
-
- public Object next() {
- m_pos++;
- return nrpns.get( m_pos );
- }
-
- public void remove() {
- }
+ private NRPN() {
}
public static Iterator iterator() {
return new NrpnIterator();
}
- public static String getName( ushort nrpn ) {
- foreach ( FieldInfo fi in typeof( NRPN ).GetFields() ) {
- if ( fi.FieldType.Equals( typeof( ushort ) ) ) {
- ushort v = (ushort)fi.GetValue( typeof( NRPN ) );
- if ( v == nrpn ) {
- return fi.Name;
- }
+ public static String getName( int nrpn ) {
+ for ( Iterator itr = iterator(); itr.hasNext(); ) {
+ ValuePair v = (ValuePair)itr.next();
+ if ( v.getValue() == nrpn ) {
+ return v.getKey();
}
}
return "";
@@ -612,69 +590,50 @@ namespace Boare.Lib.Vsq {
///
public static byte getVoiceChangeParameterID( String curve_name ) {
byte lsb = 0x31;
- switch ( curve_name.ToLower() ) {
- case "harmonics":
- lsb = 0x30;
- break;
- case "bre":
- lsb = 0x31;
- break;
- case "bri":
- lsb = 0x32;
- break;
- case "cle":
- lsb = 0x33;
- break;
- case "por":
- lsb = 0x34;
- break;
- case "ope":
- lsb = 0x35;
- break;
- case "reso1freq":
- lsb = 0x40;
- break;
- case "reso2freq":
- lsb = 0x41;
- break;
- case "reso3freq":
- lsb = 0x42;
- break;
- case "reso4freq":
- lsb = 0x43;
- break;
- case "reso1bw":
- lsb = 0x50;
- break;
- case "reso2bw":
- lsb = 0x51;
- break;
- case "reso3bw":
- lsb = 0x52;
- break;
- case "reso4bw":
- lsb = 0x53;
- break;
- case "reso1amp":
- lsb = 0x60;
- break;
- case "reso2amp":
- lsb = 0x61;
- break;
- case "reso3amp":
- lsb = 0x62;
- break;
- case "reso4amp":
- lsb = 0x63;
- break;
- case "gen":
- lsb = 0x70;
- break;
+ curve_name = curve_name.ToLower();
+ if ( curve_name.Equals( "harmonics" ) ) {
+ lsb = 0x30;
+ } else if ( curve_name.Equals( "bre" ) ) {
+ lsb = 0x31;
+ } else if ( curve_name.Equals( "bri" ) ) {
+ lsb = 0x32;
+ } else if ( curve_name.Equals( "cle" ) ) {
+ lsb = 0x33;
+ } else if ( curve_name.Equals( "por" ) ) {
+ lsb = 0x34;
+ } else if ( curve_name.Equals( "ope" ) ) {
+ lsb = 0x35;
+ } else if ( curve_name.Equals( "reso1freq" ) ) {
+ lsb = 0x40;
+ } else if ( curve_name.Equals( "reso2freq" ) ) {
+ lsb = 0x41;
+ } else if ( curve_name.Equals( "reso3freq" ) ) {
+ lsb = 0x42;
+ } else if ( curve_name.Equals( "reso4freq" ) ) {
+ lsb = 0x43;
+ } else if ( curve_name.Equals( "reso1bw" ) ) {
+ lsb = 0x50;
+ } else if ( curve_name.Equals( "reso2bw" ) ) {
+ lsb = 0x51;
+ } else if ( curve_name.Equals( "reso3bw" ) ) {
+ lsb = 0x52;
+ } else if ( curve_name.Equals( "reso4bw" ) ) {
+ lsb = 0x53;
+ } else if ( curve_name.Equals( "reso1amp" ) ) {
+ lsb = 0x60;
+ } else if ( curve_name.Equals( "reso2amp" ) ) {
+ lsb = 0x61;
+ } else if ( curve_name.Equals( "reso3amp" ) ) {
+ lsb = 0x62;
+ } else if ( curve_name.Equals( "reso4amp" ) ) {
+ lsb = 0x63;
+ } else if ( curve_name.Equals( "gen" ) ) {
+ lsb = 0x70;
}
return lsb;
}
- public static boolean is_require_data_lsb( ushort nrpn ) {
+ public static boolean is_require_data_lsb( int nrpn ) {
switch ( nrpn ) {
case CVM_NM_VERSION_AND_DEVICE:
case CVM_NM_DELAY:
@@ -747,4 +706,6 @@ namespace Boare.Lib.Vsq {
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/NoteHeadHandle.cs b/trunk/Boare.Lib.Vsq/NoteHeadHandle.cs
new file mode 100644
index 0000000..ca9ebe5
--- /dev/null
+++ b/trunk/Boare.Lib.Vsq/NoteHeadHandle.cs
@@ -0,0 +1,94 @@
+/*
+ * NoteHeadHandle.cs
+ * Copyright (c) 2009 kbinani
+ *
+ * This file is part of Boare.Lib.Vsq.
+ *
+ * Boare.Lib.Vsq is free software; you can redistribute it and/or
+ * modify it under the terms of the BSD License.
+ *
+ * Boare.Lib.Vsq 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.vsq;
+
+import java.io.*;
+#else
+using System;
+
+namespace Boare.Lib.Vsq {
+#endif
+
+#if JAVA
+ public class NoteHeadHandle implements Cloneable, Serializable {
+#else
+ [Serializable]
+ public class NoteHeadHandle : ICloneable {
+#endif
+ public int Index;
+ public String IconID = "";
+ public String IDS = "";
+ public int Original;
+ public String Caption = "";
+ public int Length;
+ public int Duration;
+ public int Depth;
+
+ public NoteHeadHandle() {
+ }
+
+ public int getLength() {
+ return Length;
+ }
+
+ public void setLength( int value ) {
+ Length = value;
+ }
+
+ public String getDisplayString() {
+ String s = IDS;
+ if ( !Caption.Equals( "" ) ) {
+ s += " (" + Caption + ")";
+ }
+ return s;
+ }
+
+#if !JAVA
+ public object Clone() {
+ return clone();
+ }
+#endif
+
+ public Object clone() {
+ NoteHeadHandle result = new NoteHeadHandle();
+ result.Index = Index;
+ result.IconID = IconID;
+ result.IDS = IDS;
+ result.Original = Original;
+ result.Caption = Caption;
+ result.setLength( Length );
+ result.Duration = Duration;
+ result.Depth = Depth;
+ return result;
+ }
+
+ public VsqHandle castToVsqHandle() {
+ VsqHandle ret = new VsqHandle();
+ ret.m_type = VsqHandleType.NoteHeadHandle;
+ ret.Index = Index;
+ ret.IconID = IconID;
+ ret.IDS = IDS;
+ ret.Original = Original;
+ ret.Caption = Caption;
+ ret.setLength( Length );
+ ret.Duration = Duration;
+ ret.Depth = Depth;
+ return ret;
+ }
+ }
+
+#if !JAVA
+}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/NrpnData.cs b/trunk/Boare.Lib.Vsq/NrpnData.cs
index 05ebdba..37f4ac4 100644
--- a/trunk/Boare.Lib.Vsq/NrpnData.cs
+++ b/trunk/Boare.Lib.Vsq/NrpnData.cs
@@ -11,7 +11,11 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
+#if JAVA
+package org.kbinani.vsq;
+#else
namespace Boare.Lib.Vsq {
+#endif
public class NrpnData {
int m_clock;
@@ -24,13 +28,15 @@ namespace Boare.Lib.Vsq {
Value = value;
}
- public int getClock(){
+ public int getClock() {
return m_clock;
}
- public byte getParameter(){
+ public byte getParameter() {
return m_parameter;
}
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/NrpnIterator.cs b/trunk/Boare.Lib.Vsq/NrpnIterator.cs
new file mode 100644
index 0000000..8c9aed8
--- /dev/null
+++ b/trunk/Boare.Lib.Vsq/NrpnIterator.cs
@@ -0,0 +1,83 @@
+/*
+ * NrpnIterator.cs
+ * Copyright (c) 2009 kbinani
+ *
+ * This file is part of Boare.Lib.Vsq.
+ *
+ * Boare.Lib.Vsq is free software; you can redistribute it and/or
+ * modify it under the terms of the BSD License.
+ *
+ * Boare.Lib.Vsq 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.vsq;
+
+import java.lang.reflect.*;
+import java.util.*;
+import org.kbinani.*;
+#else
+using System;
+using System.Reflection;
+using bocoree;
+using bocoree.java.util;
+
+namespace Boare.Lib.Vsq {
+ using boolean = System.Boolean;
+ using Integer = System.Int32;
+#endif
+
+#if JAVA
+ public class NrpnIterator implements Iterator {
+#else
+ public class NrpnIterator : Iterator {
+#endif
+ private Vector> nrpns = new Vector>();
+ private int m_pos = -1;
+
+ public NrpnIterator() {
+#if JAVA
+ try{
+ Field[] fields = NRPN.class.getFields();
+ for( int i = 0; i < 0; i++ ){
+ Class type = fields[i].getType();
+ if( type == Integer.class || type == Integer.TYPE ){
+ Integer value = (Integer)fields[i].get( null );
+ String name = fields[i].getName();
+ nrpns.add( new ValuePair( name, value ) );
+ }
+ }
+ }catch( Exception ex ){
+ System.out.println( "com.boare.vsq.NrpnIterator#.ctor; ex=" + ex );
+ }
+#else
+ Type t = typeof( NRPN );
+ foreach ( FieldInfo fi in t.GetFields() ) {
+ if ( fi.FieldType.Equals( typeof( int ) ) ) {
+ nrpns.add( new ValuePair( fi.Name, (int)fi.GetValue( t ) ) );
+ }
+ }
+#endif
+ }
+
+ public boolean hasNext() {
+ if ( 0 <= m_pos + 1 && m_pos + 1 < nrpns.size() ) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public Object next() {
+ m_pos++;
+ return nrpns.get( m_pos ).getValue();
+ }
+
+ public void remove() {
+ }
+ }
+
+#if !JAVA
+}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/SMF/MidiFile.cs b/trunk/Boare.Lib.Vsq/SMF/MidiFile.cs
deleted file mode 100644
index 1eed05d..0000000
--- a/trunk/Boare.Lib.Vsq/SMF/MidiFile.cs
+++ /dev/null
@@ -1,444 +0,0 @@
-/*
- * MidiFile.cs
- * Copyright (c) 2009 kbinani
- *
- * This file is part of Boare.Lib.Vsq.
- *
- * Boare.Lib.Vsq is free software; you can redistribute it and/or
- * modify it under the terms of the BSD License.
- *
- * Boare.Lib.Vsq 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.
- */
-using System;
-using System.IO;
-using System.Collections.Generic;
-
-using bocoree;
-
-namespace Boare.Lib.Vsq {
-
- using boolean = System.Boolean;
-
- ///
- /// midiイベント。メタイベントは、メタイベントのデータ長をData[1]に格納せず、生のデータをDataに格納するので、注意が必要
- ///
- public struct MidiEvent : IComparable {
- public long clock;
- public byte firstByte;
- public byte[] data;
-
- public long Clock {
- get {
- return clock;
- }
- set {
- clock = value;
- }
- }
-
- public byte FirstByte {
- get {
- return firstByte;
- }
- set {
- firstByte = value;
- }
- }
-
- public byte[] Data {
- get {
- return data;
- }
- set {
- data = value;
- }
- }
-
- private static void writeDeltaClock( Stream stream, long number ) {
- boolean[] bits = new boolean[64];
- long val = 0x1;
- bits[0] = (number & val) == val;
- for ( int i = 1; i < 64; i++ ) {
- val = val << 1;
- bits[i] = (number & val) == val;
- }
- int first = 0;
- for ( int i = 63; i >= 0; i-- ) {
- if ( bits[i] ) {
- first = i;
- break;
- }
- }
- // 何バイト必要か?
- int bytes = first / 7 + 1;
- for ( int i = 1; i <= bytes; i++ ) {
- uint num = 0;
- uint count = 0x80;
- for ( int j = (bytes - i + 1) * 7 - 1; j >= (bytes - i + 1) * 7 - 6 - 1; j-- ) {
- count = count >> 1;
- if ( bits[j] ) {
- num += count;
- }
- }
- if ( i != bytes ) {
- num += 0x80;
- }
- stream.WriteByte( (byte)num );
- }
- }
-
- private static long readDeltaClock( Stream stream ) {
- long ret = 0;
- while ( true ) {
- int i = stream.ReadByte();
- if ( i < 0 ) {
- break;
- }
- byte d = (byte)i;
- ret = (ret << 7) | ((long)d & 0x7f);
- if ( (d & 0x80) == 0x00 ) {
- break;
- }
- }
- return ret;
- }
-
- public static MidiEvent read( Stream stream, ref long last_clock, ref byte last_status_byte ) {
- long delta_clock = readDeltaClock( stream );
- last_clock += delta_clock;
- byte first_byte = (byte)stream.ReadByte();
- if ( first_byte < 0x80 ) {
- // ランニングステータスが適用される
- stream.Seek( -1, SeekOrigin.Current );
- first_byte = last_status_byte;
- } else {
- last_status_byte = first_byte;
- }
- byte ctrl = (byte)(first_byte & (byte)0xf0);
- if ( ctrl == 0x80 || ctrl == 0x90 || ctrl == 0xA0 || ctrl == 0xB0 || ctrl == 0xE0 || first_byte == 0xF2 ) {
- // 3byte使用するチャンネルメッセージ:
- // 0x8*: ノートオフ
- // 0x9*: ノートオン
- // 0xA*: ポリフォニック・キープレッシャ
- // 0xB*: コントロールチェンジ
- // 0xE*: ピッチベンドチェンジ
- // 3byte使用するシステムメッセージ
- // 0xF2: ソングポジション・ポインタ
- MidiEvent me = new MidiEvent();
- me.clock = last_clock;
- me.firstByte = first_byte;
- me.data = new byte[2];
- stream.Read( me.data, 0, 2 );
- return me;
- } else if ( ctrl == 0xC0 || ctrl == 0xD0 || first_byte == 0xF1 || first_byte == 0xF2 ) {
- // 2byte使用するチャンネルメッセージ
- // 0xC*: プログラムチェンジ
- // 0xD*: チャンネルプレッシャ
- // 2byte使用するシステムメッセージ
- // 0xF1: クォータフレーム
- // 0xF3: ソングセレクト
- MidiEvent me = new MidiEvent();
- me.clock = last_clock;
- me.firstByte = first_byte;
- me.data = new byte[1];
- stream.Read( me.data, 0, 1 );
- return me;
- } else if ( first_byte == 0xF6 ) {
- // 1byte使用するシステムメッセージ
- // 0xF6: チューンリクエスト
- // 0xF7: エンドオブエクスクルーシブ(このクラスではF0ステータスのSysExの一部として取り扱う)
- // 0xF8: タイミングクロック
- // 0xFA: スタート
- // 0xFB: コンティニュー
- // 0xFC: ストップ
- // 0xFE: アクティブセンシング
- // 0xFF: システムリセット
- MidiEvent me = new MidiEvent();
- me.clock = last_clock;
- me.firstByte = first_byte;
- me.data = new byte[0];
- return me;
- } else if ( first_byte == 0xff ) {
- // メタイベント
- byte meta_event_type = (byte)stream.ReadByte();
- long meta_event_length = readDeltaClock( stream );
- MidiEvent me = new MidiEvent();
- me.clock = last_clock;
- me.firstByte = first_byte;
- me.data = new byte[meta_event_length + 1];
- me.data[0] = meta_event_type;
- stream.Read( me.data, 1, (int)meta_event_length );
- return me;
- } else if ( first_byte == 0xf0 ) {
- // f0ステータスのSysEx
- MidiEvent me = new MidiEvent();
- me.clock = last_clock;
- me.firstByte = first_byte;
- long sysex_length = readDeltaClock( stream );
- me.data = new byte[sysex_length + 1];
- stream.Read( me.data, 0, (int)(sysex_length + 1) );
- return me;
- } else if ( first_byte == 0xf7 ) {
- // f7ステータスのSysEx
- MidiEvent me = new MidiEvent();
- me.clock = last_clock;
- me.firstByte = first_byte;
- long sysex_length = readDeltaClock( stream );
- me.data = new byte[sysex_length];
- stream.Read( me.data, 0, (int)sysex_length );
- return me;
- } else {
- throw new ApplicationException( "don't know how to process first_byte: 0x" + Convert.ToString( first_byte, 16 ) );
- }
- }
-
- public void writeData( Stream stream ) {
- stream.WriteByte( firstByte );
- if ( firstByte == 0xff ) {
- stream.WriteByte( data[0] );
- writeDeltaClock( stream, data.Length - 1 );
- //stream.WriteByte( (byte)(Data.Length - 1) );
- stream.Write( data, 1, data.Length - 1 );
- } else {
- stream.Write( data, 0, data.Length );
- }
- }
-
- public int CompareTo( MidiEvent item ) {
- if ( clock != item.clock ) {
- return (int)(clock - item.clock);
- } else {
- int first_this = firstByte & 0xf0;
- int first_item = item.firstByte & 0xf0;
-
- if ( (first_this == 0x80 || first_this == 0x90) && (first_item == 0x80 || first_item == 0x90) ) {
- if ( data != null && data.Length >= 2 && item.data != null && item.data.Length >= 2 ) {
- if ( first_item == 0x90 && item.data[1] == 0 ) {
- first_item = 0x80;
- }
- if ( first_this == 0x90 && data[1] == 0 ) {
- first_this = 0x80;
- }
- if ( data[0] == item.data[0] ) {
- if ( first_this == 0x90 ) {
- if ( first_item == 0x80 ) {
- // ON -> OFF
- return 1;
- } else {
- // ON -> ON
- return 0;
- }
- } else {
- if ( first_item == 0x80 ) {
- // OFF -> OFF
- return 0;
- } else {
- // OFF -> ON
- return -1;
- }
- }
- }
- }
- }
- return (int)(clock - item.clock);
- }
- }
-
- public static MidiEvent generateTimeSigEvent( int clock, int numerator, int denominator ) {
- MidiEvent ret = new MidiEvent();
- ret.clock = clock;
- ret.firstByte = 0xff;
- byte b_numer = (byte)(Math.Log( denominator, 2 ) + 0.1);
-#if DEBUG
- Console.WriteLine( "VsqEvent.generateTimeSigEvent; b_number=" + b_numer + "; denominator=" + denominator );
-#endif
- ret.data = new byte[5] { 0x58, (byte)numerator, b_numer, 0x18, 0x08 };
- return ret;
- }
-
- public static MidiEvent generateTempoChangeEvent( int clock, int tempo ) {
- MidiEvent ret = new MidiEvent();
- ret.clock = clock;
- ret.firstByte = 0xff;
- byte b1 = (byte)(tempo & 0xff);
- tempo = tempo >> 8;
- byte b2 = (byte)(tempo & 0xff);
- tempo = tempo >> 8;
- byte b3 = (byte)(tempo & 0xff);
- ret.data = new byte[4] { 0x51, b3, b2, b1 };
- return ret;
- }
- }
-
- public class MidiFile : IDisposable {
- private Vector> m_events;
- private ushort m_format;
- private ushort m_time_format;
-
- public MidiFile( String path ){
- Stream stream = new FileStream( path, FileMode.Open, FileAccess.Read );
- // ヘッダ
- byte[] byte4 = new byte[4];
- stream.Read( byte4, 0, 4 );
- if ( makeUInt32( byte4 ) != 0x4d546864 ) {
- throw new ApplicationException( "header error: MThd" );
- }
-
- // データ長
- stream.Read( byte4, 0, 4 );
- uint length = makeUInt32( byte4 );
-
- // フォーマット
- stream.Read( byte4, 0, 2 );
- m_format = makeUint16( byte4 );
-
- // トラック数
- int tracks = 0;
- stream.Read( byte4, 0, 2 );
- tracks = (int)makeUint16( byte4 );
-
- // 時間分解能
- stream.Read( byte4, 0, 2 );
- m_time_format = makeUint16( byte4 );
-
- // 各トラックを読込み
- m_events = new Vector>();
- for ( int track = 0; track < tracks; track++ ) {
- // ヘッダー
- stream.Read( byte4, 0, 4 );
- if ( makeUInt32( byte4 ) != 0x4d54726b ) {
- throw new ApplicationException( "header error; MTrk" );
- }
- m_events.add( new Vector() );
-
- // チャンクサイズ
- stream.Read( byte4, 0, 4 );
- long size = (long)makeUInt32( byte4 );
- long startpos = stream.Position;
-
- // チャンクの終わりまで読込み
- long clock = 0;
- byte last_status_byte = 0x00;
- while ( stream.Position < startpos + size ) {
- MidiEvent mi = MidiEvent.read( stream, ref clock, ref last_status_byte );
- m_events.get( track ).add( mi );
- }
- if ( m_time_format != 480 ) {
- int count = m_events.get( track ).size();
- for ( int i = 0; i < count; i++ ) {
- MidiEvent mi = m_events.get( track ).get( i );
- mi.clock = mi.clock * 480 / m_time_format;
- m_events.get( track ).set( i, mi );
- }
- }
- }
- m_time_format = 480;
-#if DEBUG
- String dbg = Path.Combine( Path.GetDirectoryName( path ), Path.GetFileNameWithoutExtension( path ) + ".txt" );
- using ( StreamWriter sw = new StreamWriter( dbg ) ) {
- const String format = " {0,8} 0x{1:X4} {2,-35} 0x{3:X2} 0x{4:X2}";
- const String format0 = " {0,8} 0x{1:X4} {2,-35} 0x{3:X2}";
- for ( int track = 1; track < m_events.size(); track++ ) {
- sw.WriteLine( "MidiFile..ctor; track=" + track );
- byte msb, lsb, data_msb, data_lsb;
- msb = lsb = data_msb = data_lsb = 0x0;
- for ( int i = 0; i < m_events.get( track ).size(); i++ ) {
- if ( m_events.get( track ).get( i ).firstByte == 0xb0 ) {
- switch ( m_events.get( track ).get( i ).data[0] ) {
- case 0x63:
- msb = m_events.get( track ).get( i ).data[1];
- lsb = 0x0;
- break;
- case 0x62:
- lsb = m_events.get( track ).get( i ).data[1];
- break;
- case 0x06:
- data_msb = m_events.get( track ).get( i ).data[1];
- ushort nrpn = (ushort)(msb << 8 | lsb);
- String name = NRPN.getName( nrpn );
- if ( name.Equals( "" ) ) {
- name = "* * UNKNOWN * *";
- sw.WriteLine( String.Format( format0, m_events.get( track ).get( i ).clock, nrpn, name, data_msb ) );
- } else {
- //if ( !NRPN.is_require_data_lsb( nrpn ) ) {
- sw.WriteLine( String.Format( format0, m_events.get( track ).get( i ).clock, nrpn, name, data_msb ) );
- //}
- }
- break;
- case 0x26:
- data_lsb = m_events.get( track ).get( i ).data[1];
- ushort nrpn2 = (ushort)(msb << 8 | lsb);
- String name2 = NRPN.getName( nrpn2 );
- if ( name2.Equals( "" ) ) {
- name2 = "* * UNKNOWN * *";
- }
- sw.WriteLine( String.Format( format, m_events.get( track ).get( i ).clock, nrpn2, name2, data_msb, data_lsb ) );
- break;
- }
- }
- }
- }
- }
-#endif
- stream.Close();
- }
-
- /*public void Write( String path ) {
- }*/
-
- public Vector getMidiEventList( int track ) {
- if ( m_events == null ) {
- return new Vector();
- } else if ( 0 <= track && track < m_events.size() ) {
- return m_events.get( track );
- } else {
- return new Vector();
- }
- }
-
- public int getTrackCount() {
- if ( m_events == null ) {
- return 0;
- } else {
- return m_events.size();
- }
- }
-
- public void Dispose() {
- Close();
- }
-
- public void Close() {
- if ( m_events != null ) {
- for ( int i = 0; i < m_events.size(); i++ ) {
- m_events.get( i ).clear();
- }
- m_events.clear();
- }
- }
-
- private static UInt32 makeUInt32( byte[] value ) {
- return (uint)((uint)((uint)((uint)(value[0] << 8) | value[1]) << 8 | value[2]) << 8 | value[3]);
- }
-
- private static UInt16 makeUint16( byte[] value ) {
- return (ushort)((ushort)(value[0] << 8) | value[1]);
- }
-
- private static long readDeltaClock( Stream stream ) {
- byte[] b;
- long ret = 0;
- while ( true ) {
- byte d = (byte)stream.ReadByte();
- ret = (ret << 7) | ((long)d & 0x7f);
- if ( (d & 0x80) == 0x00 ) {
- break;
- }
- }
- return ret;
- }
- }
-
-}
\ No newline at end of file
diff --git a/trunk/Boare.Lib.Vsq/SingerConfig.cs b/trunk/Boare.Lib.Vsq/SingerConfig.cs
index 799e2f6..2e14de7 100644
--- a/trunk/Boare.Lib.Vsq/SingerConfig.cs
+++ b/trunk/Boare.Lib.Vsq/SingerConfig.cs
@@ -11,18 +11,29 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
-using System;
-using System.IO;
-using System.Collections.Generic;
+#if JAVA
+package org.kbinani.vsq;
+import java.io.*;
+import java.util.*;
+import org.kbinani.*;
+#else
+using System;
using bocoree;
+using bocoree.java.util;
+using bocoree.java.io;
namespace Boare.Lib.Vsq {
+#endif
+#if JAVA
+ public class SingerConfig implements Cloneable {
+#else
public class SingerConfig : ICloneable {
+#endif
public String ID = "";
public String FORMAT = "";
- public String VOICEIDSTR = "";
+ public String VOICEIDSTR = "";
public String VOICENAME = "Unknown";
public int Breathiness;
public int Brightness;
@@ -47,8 +58,8 @@ namespace Boare.Lib.Vsq {
public SingerConfig() {
}
-
- public object Clone() {
+
+ public Object clone() {
SingerConfig ret = new SingerConfig();
ret.ID = ID;
ret.FORMAT = FORMAT;
@@ -77,6 +88,12 @@ namespace Boare.Lib.Vsq {
return ret;
}
+#if !JAVA
+ public object Clone() {
+ return clone();
+ }
+#endif
+
public static SingerConfig fromVvd( String file, int original ) {
SingerConfig sc = new SingerConfig();
//original = original;
@@ -90,21 +107,23 @@ namespace Boare.Lib.Vsq {
sc.Opening = 0;
sc.GenderFactor = 0;
sc.Original = original; //original = 0;
- FileStream fs = null;
+ RandomAccessFile fs = null;
try {
- fs = new FileStream( file, FileMode.Open, FileAccess.Read );
- int length = (int)fs.Length;
+ fs = new RandomAccessFile( file, "r" );
+ int length = (int)fs.length();
byte[] dat = new byte[length];
- fs.Read( dat, 0, length );
- TransCodeUtil.decodeBytes( ref dat );
- String str = bocoree.cp932.convert( dat );
+ fs.read( dat, 0, length );
+ TransCodeUtil.decodeBytes( dat );
+ String str = PortUtil.getDecodedString( "Shift_JIS", dat );
#if DEBUG
- Console.WriteLine( "SingerConfig.readSingerConfig; str=" + str );
+ PortUtil.println( "SingerConfig.readSingerConfig; str=" + str );
#endif
- String crlf = ((char)0x0d).ToString() + ((char)0x0a).ToString();
- String[] spl = str.Split( new String[] { crlf }, StringSplitOptions.RemoveEmptyEntries );
+ String crlf = "" + (char)0x0d + "" + (char)0x0a;
+ String[] spl = PortUtil.splitString( str, new String[] { crlf }, true );
- foreach ( String s in spl ) {
+ int count = spl.Length;
+ for ( int i = 0; i < spl.Length; i++ ) {
+ String s = spl[i];
int first = s.IndexOf( '"' );
int first_end = get_quated_string( s, first );
int second = s.IndexOf( '"', first_end + 1 );
@@ -112,11 +131,14 @@ namespace Boare.Lib.Vsq {
char[] chs = s.ToCharArray();
String id = new String( chs, first, first_end - first + 1 );
String value = new String( chs, second, second_end - second + 1 );
- id = id.Substring( 1, id.Length - 2 );
- value = value.Substring( 1, value.Length - 2 );
- value = value.Replace( "\\\"", "\"" );
+ id = id.Substring( 1, PortUtil.getStringLength( id ) - 2 );
+ value = value.Substring( 1, PortUtil.getStringLength( value ) - 2 );
+ value = value.Replace( "\\" + "\"", "\"" );
int parsed_int = 64;
- int.TryParse( value, out parsed_int );
+ try {
+ parsed_int = PortUtil.parseInt( value );
+ } catch ( Exception ex ) {
+ }
if ( id.Equals( "ID" ) ) {
sc.ID = value;
} else if ( id.Equals( "FORMAT" ) ) {
@@ -163,11 +185,14 @@ namespace Boare.Lib.Vsq {
sc.Harmonics = parsed_int;
}
}
- } catch {
+ } catch ( Exception ex ) {
} finally {
if ( fs != null ) {
- fs.Close();
+ try {
+ fs.close();
+ } catch ( Exception ex2 ) {
+ }
}
}
return sc;
@@ -211,17 +236,27 @@ namespace Boare.Lib.Vsq {
ret.add( "\"Clearness\":=:\"" + Clearness + "\"" );
ret.add( "\"Opening\":=:\"" + Opening + "\"" );
ret.add( "\"Gender:Factor\":=:\"" + GenderFactor + "\"" );
- return ret.toArray( new String[]{} );
+ return ret.toArray( new String[] { } );
}
- public override String ToString() {
+#if !JAVA
+ public override string ToString() {
+ return toString();
+ }
+#endif
+
+ public String toString() {
String[] r = ToStringArray();
String ret = "";
- foreach ( String s in r ) {
+ int count = r.Length;
+ for ( int i = 0; i < count; i++ ) {
+ String s = r[i];
ret += s + "\n";
}
return ret;
}
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/SingerConfigSys.cs b/trunk/Boare.Lib.Vsq/SingerConfigSys.cs
index cf661bf..c108cbf 100644
--- a/trunk/Boare.Lib.Vsq/SingerConfigSys.cs
+++ b/trunk/Boare.Lib.Vsq/SingerConfigSys.cs
@@ -11,13 +11,20 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
-using System;
-using System.Collections.Generic;
-using System.IO;
+#if JAVA
+package org.kbinani.vsq;
+import java.io.*;
+import java.util.*;
+import org.kbinani.*;
+#else
+using System;
using bocoree;
+using bocoree.java.util;
+using bocoree.java.io;
namespace Boare.Lib.Vsq {
+#endif
public class SingerConfigSys {
private const int MAX_SINGERS = 0x4000;
@@ -33,23 +40,25 @@ namespace Boare.Lib.Vsq {
public SingerConfigSys( String path_voicedb, String[] path_installed_singers ) {
m_installed_singers = new Vector();
m_singer_configs = new Vector();
- String map = Path.Combine( path_voicedb, "voice.map" );
- if ( !File.Exists( map ) ) {
+ String map = PortUtil.combinePath( path_voicedb, "voice.map" );
+ if ( !PortUtil.isFileExists( map ) ) {
return;
}
- using ( FileStream fs = new FileStream( map, FileMode.Open, FileAccess.Read ) ) {
+ RandomAccessFile fs = null;
+ try {
+ fs = new RandomAccessFile( map, "r" );
byte[] dat = new byte[8];
- fs.Seek( 0x20, SeekOrigin.Begin );
+ fs.seek( 0x20 );
for ( int i = 0; i < MAX_SINGERS; i++ ) {
- fs.Read( dat, 0, 8 );
- ulong value = VocaloSysUtil.makelong_le( dat );
+ fs.read( dat, 0, 8 );
+ long value = VocaloSysUtil.makelong_le( dat );
if ( value >= 1 ) {
- String vvd = Path.Combine( path_voicedb, "vvoice" + value + ".vvd" );
+ String vvd = PortUtil.combinePath( path_voicedb, "vvoice" + value + ".vvd" );
SingerConfig item = SingerConfig.fromVvd( vvd, 0 );
item.Program = i;
int original = -1;
- for ( Iterator itr = m_installed_singers.iterator(); itr.hasNext(); ){
+ for ( Iterator itr = m_installed_singers.iterator(); itr.hasNext(); ) {
SingerConfig sc = (SingerConfig)itr.next();
if ( sc.VOICEIDSTR.Equals( item.VOICEIDSTR ) ) {
original = sc.Program;
@@ -57,10 +66,20 @@ namespace Boare.Lib.Vsq {
}
}
if ( original < 0 ) {
- foreach ( String ipath in path_installed_singers ) {
+#if JAVA
+ int count = path_installed_singers.length;
+#else
+ int count = path_installed_singers.Length;
+#endif
+ for ( int j = 0; j < count; j++ ) {
+ String ipath = path_installed_singers[j];
if ( ipath.EndsWith( item.VOICEIDSTR ) ) {
- String[] vvds = Directory.GetFiles( ipath, "*.vvd" );
+ String[] vvds = PortUtil.listFiles( ipath, "*.vvd" );
+#if JAVA
+ if ( vvds.length > 0 ) {
+#else
if ( vvds.Length > 0 ) {
+#endif
original = m_installed_singers.size();
SingerConfig installed = SingerConfig.fromVvd( vvds[0], original );
installed.Program = original;
@@ -75,11 +94,19 @@ namespace Boare.Lib.Vsq {
m_singer_configs.add( item );
}
}
+ } catch ( Exception ex ) {
+ } finally {
+ if ( fs != null ) {
+ try {
+ fs.close();
+ } catch ( Exception ex2 ) {
+ }
+ }
}
}
public SingerConfig[] getInstalledSingers() {
- return m_installed_singers.toArray( new SingerConfig[]{} );
+ return m_installed_singers.toArray( new SingerConfig[] { } );
}
///
@@ -101,32 +128,37 @@ namespace Boare.Lib.Vsq {
sc = new SingerConfig();
}
int lang = 0;
- for( Iterator itr = m_installed_singers.iterator(); itr.hasNext(); ){
+ for ( Iterator itr = m_installed_singers.iterator(); itr.hasNext(); ) {
SingerConfig sc2 = (SingerConfig)itr.next();
if ( sc.VOICEIDSTR.Equals( sc2.VOICEIDSTR ) ) {
- lang = (int)VocaloSysUtil.getLanguageFromName( sc.VOICENAME );
+ VsqVoiceLanguage lang_enum = VocaloSysUtil.getLanguageFromName( sc.VOICENAME );
+#if JAVA
+ lang = lang_enum.ordinal();
+#else
+ lang = (int)lang_enum;
+#endif
break;
}
}
ret.IconHandle = new IconHandle();
- ret.IconHandle.IconID = "$0701" + sc.Program.ToString( "0000" );
+ ret.IconHandle.IconID = "$0701" + PortUtil.toHexString( sc.Program, 4 );
ret.IconHandle.IDS = sc.VOICENAME;
ret.IconHandle.Index = 0;
ret.IconHandle.Language = lang;
- ret.IconHandle.Length = 1;
+ ret.IconHandle.setLength( 1 );
ret.IconHandle.Original = sc.Original;
ret.IconHandle.Program = sc.Program;
ret.IconHandle.Caption = "";
return ret;
}
-
+
///
/// Gets the singer information of pecified program change.
///
///
///
public SingerConfig getSingerInfo( String singer ) {
- for ( Iterator itr = m_installed_singers.iterator(); itr.hasNext(); ){
+ for ( Iterator itr = m_installed_singers.iterator(); itr.hasNext(); ) {
SingerConfig item = (SingerConfig)itr.next();
if ( item.VOICENAME.Equals( singer ) ) {
return item;
@@ -140,8 +172,10 @@ namespace Boare.Lib.Vsq {
///
///
public SingerConfig[] getSingerConfigs() {
- return m_singer_configs.toArray( new SingerConfig[]{} );
+ return m_singer_configs.toArray( new SingerConfig[] { } );
}
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/SymbolTable.cs b/trunk/Boare.Lib.Vsq/SymbolTable.cs
index 65492d1..f002680 100644
--- a/trunk/Boare.Lib.Vsq/SymbolTable.cs
+++ b/trunk/Boare.Lib.Vsq/SymbolTable.cs
@@ -11,28 +11,43 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
-using System;
-using System.IO;
-using System.Text;
-using System.Collections.Generic;
-using System.Windows.Forms;
+#if JAVA
+package org.kbinani.vsq;
+import java.util.*;
+import java.io.*;
+import org.kbinani.*;
+#else
+using System;
+using System.Text;
+using System.Windows.Forms;
using bocoree;
+using bocoree.java.util;
+using bocoree.java.io;
namespace Boare.Lib.Vsq {
-
using boolean = System.Boolean;
+ using Integer = System.Int32;
+#endif
+#if JAVA
+ public class SymbolTable implements Cloneable {
+#else
public class SymbolTable : ICloneable {
+#endif
private TreeMap m_dict;
private String m_name;
private boolean m_enabled;
#region Static Field
- private static SortedList s_table = new SortedList();
+ private static TreeMap s_table = new TreeMap();
private static SymbolTable s_default_jp = null;
private static boolean s_initialized = false;
+#if JAVA
+ public static final String[][] _KEY_JP = {
+#else
public static readonly String[,] _KEY_JP = {
+#endif
{"あ", "a"},
{"い", "i"},
{"う", "M"},
@@ -60,7 +75,7 @@ namespace Boare.Lib.Vsq {
{"の", "n o"},
{"は", "h a"},
{"ひ", "C i"},
- {"ふ", @"p\ M"},
+ {"ふ", "p\\ M"},
{"へ", "h e"},
{"ほ", "h o"},
{"ま", "m a"},
@@ -134,10 +149,10 @@ namespace Boare.Lib.Vsq {
{"ひゅ", "C M"},
{"ひぇ", "C e"},
{"ひょ", "C o"},
- {"ふゃ", @"p\' a"},
- {"ふぃ", @"p\' i"},
- {"ふゅ", @"p\' M"},
- {"ふぇ", @"p\ e"},
+ {"ふゃ", "p\\' a"},
+ {"ふぃ", "p\\' i"},
+ {"ふゅ", "p\\' M"},
+ {"ふぇ", "p\\ e"},
{"みゃ", "m' a"},
{"みゅ", "m' M"},
{"みぇ", "m' e"},
@@ -162,8 +177,8 @@ namespace Boare.Lib.Vsq {
{"ぴゅ", "p' M"},
{"ぴぇ", "p' e"},
{"ぴょ", "p' o"},
- {"ふぁ", @"p\ a"},
- {"ふぉ", @"p\ o"},
+ {"ふぁ", "p\\ a"},
+ {"ふぉ", "p\\ o"},
{"てゃ", "t' a"},
{"てぃ", "t' i"},
{"てゅ", "t' M"},
@@ -209,7 +224,7 @@ namespace Boare.Lib.Vsq {
{"ノ", "n o"},
{"ハ", "h a"},
{"ヒ", "C i"},
- {"フ", @"p\ M"},
+ {"フ", "p\\ M"},
{"ヘ", "h e"},
{"ホ", "h o"},
{"マ", "m a"},
@@ -283,10 +298,10 @@ namespace Boare.Lib.Vsq {
{"ヒュ", "C M"},
{"ヒェ", "C e"},
{"ヒョ", "C o"},
- {"フャ", @"p\' a"},
- {"フィ", @"p\' i"},
- {"フュ", @"p\' M"},
- {"フェ", @"p\ e"},
+ {"フャ", "p\\' a"},
+ {"フィ", "p\\' i"},
+ {"フュ", "p\\' M"},
+ {"フェ", "p\\ e"},
{"ミャ", "m' a"},
{"ミュ", "m' M"},
{"ミェ", "m' e"},
@@ -311,8 +326,8 @@ namespace Boare.Lib.Vsq {
{"ピュ", "p' M"},
{"ピェ", "p' e"},
{"ピョ", "p' o"},
- {"ファ", @"p\ a"},
- {"フォ", @"p\ o"},
+ {"ファ", "p\\ a"},
+ {"フォ", "p\\ o"},
{"テャ", "t' a"},
{"ティ", "t' i"},
{"テュ", "t' M"},
@@ -452,7 +467,7 @@ namespace Boare.Lib.Vsq {
{"chi", "tS i"},
{"chu", "tS M"},
{"cho", "tS o"},
- {"fu", @"p\ M"},
+ {"fu", "p\\ M"},
{"ja", "dZ a"},
{"ji", "dZ i"},
{"ju", "dZ M"},
@@ -465,8 +480,8 @@ namespace Boare.Lib.Vsq {
if ( !s_initialized ) {
loadDictionary();
}
- if ( 0 <= index && index < s_table.Count ) {
- return s_table[index];
+ if ( 0 <= index && index < s_table.size() ) {
+ return s_table.get( index );
} else {
return null;
}
@@ -474,64 +489,65 @@ namespace Boare.Lib.Vsq {
public static void loadDictionary() {
#if DEBUG
- Console.WriteLine( "SymbolTable.LoadDictionary()" );
+ PortUtil.println( "SymbolTable.LoadDictionary()" );
#endif
s_default_jp = new SymbolTable( "DEFAULT_JP", _KEY_JP, true );
- s_table.Clear();
- s_table.Add( 0, s_default_jp );
+ s_table.clear();
+ s_table.put( 0, s_default_jp );
int count = 0;
// 辞書フォルダからの読込み
- String editor_path = VocaloSysUtil.getEditorPath2();
+ String editor_path = VocaloSysUtil.getEditorPath( SynthesizerType.VOCALOID2 );
if ( editor_path != "" ) {
- String path = Path.Combine( Path.GetDirectoryName( editor_path ), "UDIC" );
- if ( !Directory.Exists( path ) ) {
+ String path = PortUtil.combinePath( PortUtil.getDirectoryName( editor_path ), "UDIC" );
+ if ( !PortUtil.isDirectoryExists( path ) ) {
return;
}
- String[] files = Directory.GetFiles( path, "*.udc" );
+ String[] files = PortUtil.listFiles( path, "*.udc" );
for ( int i = 0; i < files.Length; i++ ) {
- files[i] = Path.GetFileName( files[i] );
+ files[i] = PortUtil.getFileName( files[i] );
#if DEBUG
- Console.WriteLine( " files[i]=" + files[i] );
+ PortUtil.println( " files[i]=" + files[i] );
#endif
count++;
- String dict = Path.Combine( path, files[i] );
- s_table.Add( count, new SymbolTable( dict, true, false ) );
+ String dict = PortUtil.combinePath( path, files[i] );
+ s_table.put( count, new SymbolTable( dict, true, false ) );
}
}
// 起動ディレクトリ
- String path2 = Path.Combine( Application.StartupPath, "udic" );
- if ( Directory.Exists( path2 ) ) {
- String[] files2 = Directory.GetFiles( path2, "*.eudc" );
+ String path2 = PortUtil.combinePath( PortUtil.getApplicationStartupPath(), "udic" );
+ if ( PortUtil.isDirectoryExists( path2 ) ) {
+ String[] files2 = PortUtil.listFiles( path2, "*.eudc" );
for ( int i = 0; i < files2.Length; i++ ) {
- files2[i] = Path.GetFileName( files2[i] );
+ files2[i] = PortUtil.getFileName( files2[i] );
#if DEBUG
- Console.WriteLine( " files2[i]=" + files2[i] );
+ PortUtil.println( " files2[i]=" + files2[i] );
#endif
count++;
- String dict = Path.Combine( path2, files2[i] );
- s_table.Add( count, new SymbolTable( dict, false, false ) );
+ String dict = PortUtil.combinePath( path2, files2[i] );
+ s_table.put( count, new SymbolTable( dict, false, false ) );
}
}
s_initialized = true;
}
- public static boolean attatch( String phrase, out String result ) {
+ public static boolean attatch( String phrase, ByRef result ) {
#if DEBUG
- Console.WriteLine( "SymbolTable.Attatch" );
- Console.WriteLine( " phrase=" + phrase );
+ PortUtil.println( "SymbolTable.Attatch" );
+ PortUtil.println( " phrase=" + phrase );
#endif
- for ( int i = 0; i < s_table.Keys.Count; i++ ) {
- int key = s_table.Keys[i];
- if ( s_table[key].isEnabled() ) {
- if ( s_table[key].attatchImp( phrase, out result ) ) {
+ for ( Iterator itr = s_table.keySet().iterator(); itr.hasNext(); ) {
+ int key = (Integer)itr.next();
+ SymbolTable table = s_table.get( key );
+ if ( table.isEnabled() ) {
+ if ( table.attatchImp( phrase, result ) ) {
return true;
}
}
}
- result = "a";
+ result.value = "a";
return false;
}
@@ -539,27 +555,31 @@ namespace Boare.Lib.Vsq {
if ( !s_initialized ) {
loadDictionary();
}
- return s_table.Count;
+ return s_table.size();
}
- public static void changeOrder( KeyValuePair[] list ) {
+ public static void changeOrder( Vector> list ) {
#if DEBUG
- Console.WriteLine( "SymbolTable.Sort()" );
+ PortUtil.println( "SymbolTable.Sort()" );
#endif
- SortedList buff = new SortedList();
- foreach ( int key in s_table.Keys ) {
- buff.Add( key, (SymbolTable)s_table[key].Clone() );
+ TreeMap buff = new TreeMap();
+ for ( Iterator itr = s_table.keySet().iterator(); itr.hasNext(); ) {
+ int key = (Integer)itr.next();
+ buff.put( key, (SymbolTable)s_table.get( key ).clone() );
}
- s_table.Clear();
- for ( int i = 0; i < list.Length; i++ ) {
+ s_table.clear();
+ int count = list.size();
+ for ( int i = 0; i < count; i++ ) {
+ ValuePair itemi = list.get( i );
#if DEBUG
- Console.WriteLine( " list[i]=" + list[i].Key + "," + list[i].Value );
+ PortUtil.println( " list[i]=" + itemi.getKey() + "," + itemi.getValue() );
#endif
- for ( int j = 0; j < buff.Keys.Count; j++ ) {
- int key = buff.Keys[j];
- if ( buff[key].getName().Equals( list[i].Key ) ) {
- buff[key].setEnabled( list[i].Value );
- s_table.Add( i, buff[key] );
+ for ( Iterator itr = buff.keySet().iterator(); itr.hasNext(); ) {
+ int key = (Integer)itr.next();
+ SymbolTable table = buff.get( key );
+ if ( table.getName().Equals( itemi.getKey() ) ) {
+ table.setEnabled( itemi.getValue() );
+ s_table.put( i, table );
break;
}
}
@@ -567,10 +587,16 @@ namespace Boare.Lib.Vsq {
}
#endregion
+#if !JAVA
public object Clone() {
+ return clone();
+ }
+#endif
+
+ public Object clone() {
SymbolTable ret = new SymbolTable();
ret.m_dict = new TreeMap();
- for ( Iterator itr = m_dict.keySet().iterator(); itr.hasNext(); ){
+ for ( Iterator itr = m_dict.keySet().iterator(); itr.hasNext(); ) {
String key = (String)itr.next();
ret.m_dict.put( key, m_dict.get( key ) );
}
@@ -589,91 +615,96 @@ namespace Boare.Lib.Vsq {
public boolean isEnabled() {
return m_enabled;
}
-
- public void setEnabled( boolean value ){
+
+ public void setEnabled( boolean value ) {
m_enabled = value;
}
public SymbolTable( String path, boolean is_udc_mode, boolean enabled ) {
m_dict = new TreeMap();
m_enabled = enabled;
- if ( !File.Exists( path ) ) {
+ if ( !PortUtil.isFileExists( path ) ) {
return;
}
- m_name = Path.GetFileName( path );
- cp932reader sr1 = null;
- StreamReader sr2 = null;
+ m_name = PortUtil.getFileName( path );
+ BufferedReader sr = null;
try {
if ( is_udc_mode ) {
- sr1 = new cp932reader( path );
- if ( sr1 == null ) {
+ sr = new BufferedReader( new InputStreamReader( new FileInputStream( path ), "Shift_JIS" ) );
+ if ( sr == null ) {
return;
}
} else {
- sr2 = new StreamReader( path, Encoding.UTF8 );
- if ( sr2 == null ) {
+ sr = new BufferedReader( new InputStreamReader( new FileInputStream( path ), "UTF8" ) );
+ if ( sr == null ) {
return;
}
}
String line;
- int peek = (is_udc_mode) ? sr1.Peek() : sr2.Peek();
- while ( peek >= 0 ) {
- line = (is_udc_mode) ? sr1.ReadLine() : sr2.ReadLine();
+ while ( sr.ready() ) {
+ line = sr.readLine();
if ( !line.StartsWith( "//" ) ) {
- String[] spl = line.Split( "\t".ToCharArray(), 2, StringSplitOptions.RemoveEmptyEntries );
+ String[] spl = PortUtil.splitString( line, new String[] { "\t" }, 2, true );
if ( spl.Length >= 2 ) {
if ( m_dict.containsKey( spl[0] ) ) {
- bocoree.debug.push_log( "SymbolTable..ctor" );
- bocoree.debug.push_log( " dictionary already contains key: " + spl[0] );
+ PortUtil.println( "SymbolTable..ctor" );
+ PortUtil.println( " dictionary already contains key: " + spl[0] );
} else {
m_dict.put( spl[0], spl[1] );
}
}
}
- peek = (is_udc_mode) ? sr1.Peek() : sr2.Peek();
}
} catch ( Exception ex ) {
- bocoree.debug.push_log( "SymbolTable..ctor" );
- bocoree.debug.push_log( " " + ex );
+ PortUtil.println( "SymbolTable..ctor" );
+ PortUtil.println( " " + ex );
} finally {
- if ( sr1 != null ) {
- sr1.Close();
- }
- if ( sr2 != null ) {
- sr2.Close();
+ if ( sr != null ) {
+ try {
+ sr.close();
+ } catch ( Exception ex2 ) {
+ }
}
}
}
- private boolean attatchImp( String phrase, out String result ) {
+ private boolean attatchImp( String phrase, ByRef result ) {
String s = phrase.ToLower();
if ( m_dict.containsKey( s ) ) {
- result = m_dict.get( s );
+ result.value = m_dict.get( s );
return true;
} else {
- result = "a";
+ result.value = "a";
return false;
}
}
+#if JAVA
+ private SymbolTable( String name, String[][] key, boolean enabled ){
+#else
private SymbolTable( String name, String[,] key, boolean enabled ) {
-#if DEBUG
- Console.WriteLine( "SymolTable.ctor(String,String[,])" );
- Console.WriteLine( " key.GetLength(0)=" + key.GetLength( 0 ) );
#endif
m_enabled = enabled;
m_name = name;
m_dict = new TreeMap();
+#if JAVA
+ for( int i = 0; i < key.length; i++ ){
+ if( m_dict.containsKey( key[i][0] ) ){
+ }else{
+ m_dict.put( key[i][0], key[i][1] );
+ }
+ }
+#else
for ( int i = 0; i < key.GetLength( 0 ); i++ ) {
if ( m_dict.containsKey( key[i, 0] ) ) {
-#if DEBUG
- throw new ApplicationException( "dictionary already contains key: " + key[i, 0] );
-#endif
} else {
m_dict.put( key[i, 0], key[i, 1] );
}
}
+#endif
}
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/SynthesizerType.cs b/trunk/Boare.Lib.Vsq/SynthesizerType.cs
new file mode 100644
index 0000000..256a2cc
--- /dev/null
+++ b/trunk/Boare.Lib.Vsq/SynthesizerType.cs
@@ -0,0 +1,27 @@
+/*
+ * SynthesizerType.cs
+ * Copyright (c) 2009 kbinani
+ *
+ * This file is part of Boare.Cadencii.
+ *
+ * Boare.Cadencii is free software; you can redistribute it and/or
+ * modify it under the terms of the GPLv3 License.
+ *
+ * Boare.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.vsq;
+#else
+namespace Boare.Lib.Vsq {
+#endif
+
+ public enum SynthesizerType {
+ VOCALOID1,
+ VOCALOID2,
+ }
+
+#if !JAVA
+}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/TempoTableEntry.cs b/trunk/Boare.Lib.Vsq/TempoTableEntry.cs
index be6f172..0630aef 100644
--- a/trunk/Boare.Lib.Vsq/TempoTableEntry.cs
+++ b/trunk/Boare.Lib.Vsq/TempoTableEntry.cs
@@ -11,152 +11,37 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
-using System;
-using System.Collections.Generic;
+#if JAVA
+package org.kbinani.vsq;
-using bocoree;
+import java.io.*;
+#else
+using System;
namespace Boare.Lib.Vsq {
-
using boolean = System.Boolean;
+#endif
- public class TempoTable : ICloneable {
- private struct TempoTableEntry : IComparable {
- public int Clock;
- public int Tempo;
- public double Time;
-
- public TempoTableEntry( int clock, int tempo, double time ) {
- Clock = clock;
- Tempo = tempo;
- Time = time;
- }
-
- public int CompareTo( TempoTableEntry item ) {
- return Clock - item.Clock;
- }
- }
-
- private Vector m_tempo_table;
- private int m_base_tempo;
- private int m_tpq;
-
- private TempoTable() {
- }
-
- public TempoTable( int base_tempo, int clock_per_quoter ) {
- m_base_tempo = base_tempo;
- m_tpq = clock_per_quoter;
- m_tempo_table = new Vector();
- m_tempo_table.add( new TempoTableEntry( 0, base_tempo, 0.0 ) );
- }
-
- public object Clone() {
- TempoTable ret = new TempoTable();
- ret.m_base_tempo = m_base_tempo;
- ret.m_tpq = m_tpq;
- ret.m_tempo_table = new Vector();
- for ( int i = 0; i < m_tempo_table.size(); i++ ) {
- ret.m_tempo_table.add( m_tempo_table.get( i ) );
- }
- ret.update();
- return ret;
- }
-
- public void add( int clock, int tempo ) {
- boolean found = false;
- for ( int i = 0; i < m_tempo_table.size(); i++ ) {
- if ( m_tempo_table.get( i ).Clock == clock ) {
- found = true;
- m_tempo_table.set( i, new TempoTableEntry( clock, tempo, 0.0 ) );
- break;
- }
- }
- if ( !found ) {
- m_tempo_table.add( new TempoTableEntry( clock, tempo, 0.0 ) );
- }
- Collections.sort( m_tempo_table );
- update();
- }
-
- public void clear( int base_tempo ) {
- m_tempo_table.clear();
- m_tempo_table.add( new TempoTableEntry( 0, base_tempo, 0.0 ) );
- }
-
- private void update() {
- for ( int i = 0; i < m_tempo_table.size(); i++ ) {
- long sum = 0;
- for ( int k = 0; k < i; k++ ) {
- sum += (m_tempo_table.get( k ).Tempo * (m_tempo_table.get( k + 1 ).Clock - m_tempo_table.get( k ).Clock));
- }
- double time = sum / (m_tpq * 1e6);
- m_tempo_table.set( i, new TempoTableEntry( m_tempo_table.get( i ).Clock, m_tempo_table.get( i ).Tempo, time ) );
- }
- }
-
- ///
- /// 指定した時刻における、クロックを取得します
- ///
- ///
- ///
- public double getClockFromSec( double time ) {
- // timeにおけるテンポを取得
- int tempo = m_base_tempo;
- double base_clock = 0;
- double base_time = 0f;
- if ( m_tempo_table.size() == 0 ) {
- tempo = m_base_tempo;
- base_clock = 0;
- base_time = 0f;
- } else if ( m_tempo_table.size() == 1 ) {
- tempo = m_tempo_table.get( 0 ).Tempo;
- base_clock = m_tempo_table.get( 0 ).Clock;
- base_time = m_tempo_table.get( 0 ).Time;
- } else {
- for ( int i = m_tempo_table.size() - 1; i >= 0; i-- ) {
- if ( m_tempo_table.get( i ).Time < time ) {
- return m_tempo_table.get( i ).Clock + (time - m_tempo_table.get( i ).Time) * m_tpq * 1000000.0 / m_tempo_table.get( i ).Tempo;
- }
- }
- }
- double dt = time - base_time;
- return base_clock + dt * m_tpq * 1000000.0 / (double)tempo;
- }
-
- ///
- /// 指定したクロックにおける、clock=0からの演奏経過時間(sec)を取得します
- ///
- ///
- ///
- public double getSecFromClock( int clock ) {
- for ( int i = m_tempo_table.size() - 1; i >= 0; i-- ) {
- if ( m_tempo_table.get( i ).Clock < clock ) {
- double init = m_tempo_table.get( i ).Time;
- int dclock = clock - m_tempo_table.get( i ).Clock;
- double sec_per_clock1 = m_tempo_table.get( i ).Tempo * 1e-6 / 480.0;
- return init + dclock * sec_per_clock1;
- }
- }
- double sec_per_clock = m_base_tempo * 1e-6 / 480.0;
- return clock * sec_per_clock;
- }
-
- public int getBaseTempo() {
- return m_base_tempo;
- }
- }
-
+#if JAVA
+ public class TempoTableEntry implements Comparable, Cloneable, Serializable {
+#else
[Serializable]
public class TempoTableEntry : IComparable, ICloneable {
+#endif
public int Clock;
public int Tempo;
public double Time;
- public object Clone() {
+ public Object clone() {
return new TempoTableEntry( Clock, Tempo, Time );
}
+#if !JAVA
+ public object Clone() {
+ return clone();
+ }
+#endif
+
public TempoTableEntry( int clock, int _tempo, double _time ) {
this.Clock = clock;
this.Tempo = _tempo;
@@ -166,10 +51,16 @@ namespace Boare.Lib.Vsq {
public TempoTableEntry() {
}
- public int CompareTo( TempoTableEntry entry ) {
+ public int compareTo( TempoTableEntry entry ) {
return this.Clock - entry.Clock;
}
+#if !JAVA
+ public int CompareTo( TempoTableEntry entry ) {
+ return compareTo( entry );
+ }
+#endif
+
public boolean Equals( TempoTableEntry entry ) {
if ( this.Clock == entry.Clock ) {
return true;
@@ -179,4 +70,6 @@ namespace Boare.Lib.Vsq {
}
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/TextMemoryStream.cs b/trunk/Boare.Lib.Vsq/TextMemoryStream.cs
index 0da581b..0106832 100644
--- a/trunk/Boare.Lib.Vsq/TextMemoryStream.cs
+++ b/trunk/Boare.Lib.Vsq/TextMemoryStream.cs
@@ -11,16 +11,26 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
-using System;
-using System.IO;
-using System.Text;
-using System.Collections.Generic;
+#if JAVA
+package org.kbinani.vsq;
+import java.util.*;
+import java.io.*;
+import org.kbinani.*;
+#else
+using System;
using bocoree;
+using bocoree.java.util;
+using bocoree.java.io;
namespace Boare.Lib.Vsq {
+#endif
- public class TextMemoryStream : IDisposable {
+#if JAVA
+ public class TextMemoryStream implements ITextWriter {
+#else
+ public class TextMemoryStream : IDisposable, ITextWriter {
+#endif
private static readonly String NL = (char)0x0d + "" + (char)0x0a;
private Vector m_lines;
@@ -32,16 +42,26 @@ namespace Boare.Lib.Vsq {
m_index = 0;
}
- public TextMemoryStream( String path, Encoding encoding ) {
+ public TextMemoryStream( String path, String encoding ) {
m_lines = new Vector();
m_index = 0;
- if ( File.Exists( path ) ) {
- using ( StreamReader sr = new StreamReader( path, encoding ) ) {
- while ( sr.Peek() >= 0 ) {
- String line = sr.ReadLine();
+ if ( PortUtil.isFileExists( path ) ) {
+ BufferedReader sr = null;
+ try {
+ sr = new BufferedReader( new InputStreamReader( new FileInputStream( path ), encoding ) );
+ while ( sr.ready() ) {
+ String line = sr.readLine();
m_lines.add( line );
m_index++;
}
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sr != null ) {
+ try {
+ sr.close();
+ } catch ( Exception ex2 ) {
+ }
+ }
}
}
}
@@ -54,15 +74,23 @@ namespace Boare.Lib.Vsq {
appendString( value + NL );
}
- private void appendString( String value ) {
- String[] lines = value.Split( new String[] { NL }, StringSplitOptions.None );
- Vector lines2 = new Vector();
- for ( int i = 0; i < lines.Length; i++ ) {
- String[] spl = lines[i].Split( (char)0x0d, (char)0x0a );
- for ( int j = 0; j < spl.Length; j++ ) {
- lines2.add( spl[j] );
+ private static Vector splitLine( String line ) {
+ Vector ret = new Vector();
+ String[] spl_0x0d_0x0a = PortUtil.splitString( line, new String[] { NL }, false );
+ for ( int i = 0; i < spl_0x0d_0x0a.Length; i++ ) {
+ String[] spl_0x0d = PortUtil.splitString( spl_0x0d_0x0a[i], (char)0x0d );
+ for ( int j = 0; j < spl_0x0d.Length; j++ ) {
+ String[] spl_0x0a = PortUtil.splitString( spl_0x0d[j], (char)0x0a );
+ for ( int k = 0; k < spl_0x0a.Length; k++ ) {
+ ret.add( spl_0x0a[k] );
+ }
}
}
+ return ret;
+ }
+
+ private void appendString( String value ) {
+ Vector lines2 = splitLine( value );
int count = lines2.size();
if ( count > 0 ) {
m_lines.set( m_index, m_lines.get( m_index ) + lines2.get( 0 ) );
@@ -87,7 +115,11 @@ namespace Boare.Lib.Vsq {
if ( m_lines.get( m_index ).Equals( "" ) ) {
return -1;
} else {
+#if JAVA
+ return (int)m_lines.get( m_index ).charAt( 0 );
+#else
return (int)m_lines.get( m_index )[0];
+#endif
}
} else {
return -1;
@@ -103,4 +135,6 @@ namespace Boare.Lib.Vsq {
}
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/TimeSigTableEntry.cs b/trunk/Boare.Lib.Vsq/TimeSigTableEntry.cs
index 61b8468..bf8a42a 100644
--- a/trunk/Boare.Lib.Vsq/TimeSigTableEntry.cs
+++ b/trunk/Boare.Lib.Vsq/TimeSigTableEntry.cs
@@ -11,14 +11,23 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
-using System;
+#if JAVA
+package org.kbinani.vsq;
+import java.io.*;
+#else
+using System;
using bocoree;
-namespace Boare.Lib.Vsq{
+namespace Boare.Lib.Vsq {
+#endif
+#if JAVA
+ public class TimeSigTableEntry implements Comparable, Cloneable, Serializable {
+#else
[Serializable]
public class TimeSigTableEntry : IComparable, ICloneable {
+#endif
///
/// クロック数
///
@@ -54,13 +63,27 @@ namespace Boare.Lib.Vsq{
return "{Clock=" + Clock + ", Numerator=" + Numerator + ", Denominator=" + Denominator + ", BarCount=" + BarCount + "}";
}
- public object Clone() {
+ public Object clone() {
return new TimeSigTableEntry( Clock, Numerator, Denominator, BarCount );
}
- public int CompareTo( TimeSigTableEntry item ) {
+#if !JAVA
+ public object Clone() {
+ return clone();
+ }
+#endif
+
+ public int compareTo( TimeSigTableEntry item ) {
return this.BarCount - item.BarCount;
}
+
+#if !JAVA
+ public int CompareTo( TimeSigTableEntry item ) {
+ return compareTo( item );
+ }
+#endif
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/Timesig.cs b/trunk/Boare.Lib.Vsq/Timesig.cs
new file mode 100644
index 0000000..2e7dd83
--- /dev/null
+++ b/trunk/Boare.Lib.Vsq/Timesig.cs
@@ -0,0 +1,27 @@
+/*
+ * Timesig.cs
+ * Copyright (c) 2009 kbinani
+ *
+ * This file is part of Boare.Lib.Vsq.
+ *
+ * Boare.Lib.Vsq is free software; you can redistribute it and/or
+ * modify it under the terms of the BSD License.
+ *
+ * Boare.Lib.Vsq 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.vsq;
+#else
+namespace Boare.Lib.Vsq {
+#endif
+
+ public struct Timesig {
+ public int numerator;
+ public int denominator;
+ }
+
+#if !JAVA
+}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/TransCodeUtil.cs b/trunk/Boare.Lib.Vsq/TransCodeUtil.cs
index f0dbf2a..5cfa00e 100644
--- a/trunk/Boare.Lib.Vsq/TransCodeUtil.cs
+++ b/trunk/Boare.Lib.Vsq/TransCodeUtil.cs
@@ -1,10 +1,27 @@
-namespace Boare.Lib.Vsq {
+/*
+ * TransCodeUtil.cs
+ * Copyright (c) 2009 kbinani
+ *
+ * This file is part of Boare.Lib.Vsq.
+ *
+ * Boare.Lib.Vsq is free software; you can redistribute it and/or
+ * modify it under the terms of the BSD License.
+ *
+ * Boare.Lib.Vsq 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.vsq;
+#else
+namespace Boare.Lib.Vsq {
+#endif
- public static class TransCodeUtil {
+ public class TransCodeUtil {
private static readonly byte[] MAP_L = new byte[] { 0xA, 0xB, 0x8, 0x9, 0xE, 0xF, 0xC, 0xD, 0x2, 0x3, 0x0, 0x1, 0x6, 0x7, 0x4, 0x5 };
private static readonly byte[] MAP_R = new byte[] { 0x1, 0x0, 0x3, 0x2, 0x5, 0x4, 0x7, 0x6, 0x9, 0x8, 0xB, 0xA, 0xD, 0xC, 0xF, 0xE };
-
- public static void decodeBytes( ref byte[] dat ) {
+
+ public static void decodeBytes( byte[] dat ) {
for ( int i = 0; i < dat.Length; i++ ) {
byte M = (byte)(dat[i] >> 4);
byte L = (byte)(dat[i] - (M << 4));
@@ -29,4 +46,6 @@
}
}
-}
\ No newline at end of file
+#if !JAVA
+}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/UstEnvelope.cs b/trunk/Boare.Lib.Vsq/UstEnvelope.cs
index fa31bc3..dd3abcd 100644
--- a/trunk/Boare.Lib.Vsq/UstEnvelope.cs
+++ b/trunk/Boare.Lib.Vsq/UstEnvelope.cs
@@ -11,14 +11,24 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
-using System;
+#if JAVA
+package org.kbinani.vsq;
+import java.io.*;
+import org.kbinani.*;
+#else
+using System;
using bocoree;
namespace Boare.Lib.Vsq {
+#endif
+#if JAVA
+ public class UstEnvelope implements Cloneable, Serializable {
+#else
[Serializable]
public class UstEnvelope : ICloneable {
+#endif
public int p1 = 0;
public int p2 = 5;
public int p3 = 35;
@@ -36,33 +46,45 @@ namespace Boare.Lib.Vsq {
public UstEnvelope( String line ) {
if ( line.ToLower().StartsWith( "envelope=" ) ) {
- String[] spl = line.Split( '=' );
- spl = spl[1].Split( ',' );
+ String[] spl = PortUtil.splitString( line, '=' );
+ spl = PortUtil.splitString( spl[1], ',' );
if ( spl.Length < 7 ) {
return;
}
//Separator = "";
- p1 = int.Parse( spl[0] );
- p2 = int.Parse( spl[1] );
- p3 = int.Parse( spl[2] );
- v1 = int.Parse( spl[3] );
- v2 = int.Parse( spl[4] );
- v3 = int.Parse( spl[5] );
- v4 = int.Parse( spl[6] );
+ p1 = PortUtil.parseInt( spl[0] );
+ p2 = PortUtil.parseInt( spl[1] );
+ p3 = PortUtil.parseInt( spl[2] );
+ v1 = PortUtil.parseInt( spl[3] );
+ v2 = PortUtil.parseInt( spl[4] );
+ v3 = PortUtil.parseInt( spl[5] );
+ v4 = PortUtil.parseInt( spl[6] );
if ( spl.Length == 11 ) {
//Separator = "%";
- p4 = int.Parse( spl[8] );
- p5 = int.Parse( spl[9] );
- v5 = int.Parse( spl[10] );
+ p4 = PortUtil.parseInt( spl[8] );
+ p5 = PortUtil.parseInt( spl[9] );
+ v5 = PortUtil.parseInt( spl[10] );
}
}
}
- public object Clone() {
- return new UstEnvelope( ToString() );
+ public Object clone() {
+ return new UstEnvelope( toString() );
}
- public override String ToString() {
+#if !JAVA
+ public object Clone() {
+ return clone();
+ }
+#endif
+
+#if !JAVA
+ public override string ToString() {
+ return toString();
+ }
+#endif
+
+ public String toString() {
String ret = "Envelope=" + p1 + "," + p2 + "," + p3 + "," + v1 + "," + v2 + "," + v3 + "," + v4;
ret += ",%," + p4 + "," + p5 + "," + v5;
return ret;
@@ -70,11 +92,13 @@ namespace Boare.Lib.Vsq {
public int getCount() {
//if ( Separator == "%" ) {
- return 5;
+ return 5;
//} else {
- //return 4;
+ //return 4;
//}
}
}
-}
\ No newline at end of file
+#if !JAVA
+}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/UstEvent.cs b/trunk/Boare.Lib.Vsq/UstEvent.cs
index f114fdb..b6bac25 100644
--- a/trunk/Boare.Lib.Vsq/UstEvent.cs
+++ b/trunk/Boare.Lib.Vsq/UstEvent.cs
@@ -11,17 +11,25 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Text;
+#if JAVA
+package org.kbinani.vsq;
+import java.io.*;
+import org.kbinani.*;
+#else
+using System;
using bocoree;
+using bocoree.java.io;
namespace Boare.Lib.Vsq {
+#endif
+#if JAVA
+ public class UstEvent implements Cloneable, Serializable {
+#else
[Serializable]
public class UstEvent : ICloneable {
+#endif
public String Tag;
public int Length = 0;
public String Lyric = "";
@@ -39,12 +47,20 @@ namespace Boare.Lib.Vsq {
public int Moduration = 100;
public int Index;
- public UstEvent(){
+ public UstEvent() {
}
- public object Clone() {
+ public int getLength() {
+ return Length;
+ }
+
+ public void setLength( int value ) {
+ Length = value;
+ }
+
+ public Object clone() {
UstEvent ret = new UstEvent();
- ret.Length = Length;
+ ret.setLength( Length );
ret.Lyric = Lyric;
ret.Note = Note;
ret.Intensity = Intensity;
@@ -57,13 +73,13 @@ namespace Boare.Lib.Vsq {
}
ret.Tempo = Tempo;
if ( Vibrato != null ) {
- ret.Vibrato = (UstVibrato)Vibrato.Clone();
+ ret.Vibrato = (UstVibrato)Vibrato.clone();
}
if ( Portamento != null ) {
- ret.Portamento = (UstPortamento)Portamento.Clone();
+ ret.Portamento = (UstPortamento)Portamento.clone();
}
if ( Envelope != null ) {
- ret.Envelope = (UstEnvelope)Envelope.Clone();
+ ret.Envelope = (UstEnvelope)Envelope.clone();
}
ret.PreUtterance = PreUtterance;
ret.VoiceOverlap = VoiceOverlap;
@@ -73,57 +89,99 @@ namespace Boare.Lib.Vsq {
return ret;
}
- public void print( StreamWriter sw ) {
+#if !JAVA
+ public object Clone() {
+ return clone();
+ }
+#endif
+
+ public void print( BufferedWriter sw )
+#if JAVA
+ throws IOException
+#endif
+ {
if ( this.Index == int.MinValue ) {
- sw.WriteLine( "[#PREV]" );
+ sw.write( "[#PREV]" );
+ sw.newLine();
} else if ( this.Index == int.MaxValue ) {
- sw.WriteLine( "[#NEXT]" );
+ sw.write( "[#NEXT]" );
+ sw.newLine();
} else {
- sw.WriteLine( String.Format( "[#{0:d4}]", Index ) );
+ sw.write( "[#" + PortUtil.formatDecimal( "0000", Index ) + "]" );
+ sw.newLine();
}
- sw.WriteLine( "Length=" + Length );
- sw.WriteLine( "Lyric=" + Lyric );
- sw.WriteLine( "NoteNum=" + Note );
+ sw.write( "Length=" + Length );
+ sw.newLine();
+ sw.write( "Lyric=" + Lyric );
+ sw.newLine();
+ sw.write( "NoteNum=" + Note );
+ sw.newLine();
if ( Intensity >= 0 ) {
- sw.WriteLine( "Intensity=" + Intensity );
+ sw.write( "Intensity=" + Intensity );
+ sw.newLine();
}
if ( PBType >= 0 && Pitches != null ) {
- sw.WriteLine( "PBType=" + PBType );
- sw.Write( "Piches=" );
+ sw.write( "PBType=" + PBType );
+ sw.newLine();
+ sw.write( "Piches=" );
for ( int i = 0; i < Pitches.Length; i++ ) {
if ( i == 0 ) {
- sw.Write( Pitches[i] );
+ sw.write( Pitches[i] + "" );
} else {
- sw.Write( "," + Pitches[i] );
+ sw.write( "," + Pitches[i] );
}
}
- sw.WriteLine();
+ sw.newLine();
}
if ( Tempo > 0 ) {
- sw.WriteLine( "Tempo=" + Tempo );
+ sw.write( "Tempo=" + Tempo );
+ sw.newLine();
}
if ( Vibrato != null ) {
- sw.WriteLine( Vibrato.ToString() );
+ sw.write( Vibrato.ToString() );
+ sw.newLine();
}
if ( Portamento != null ) {
Portamento.print( sw );
}
if ( Envelope != null ) {
if ( PreUtterance >= 0 ) {
- sw.WriteLine( "PreUtterance=" + PreUtterance );
+ sw.write( "PreUtterance=" + PreUtterance );
+ sw.newLine();
}
if ( VoiceOverlap != 0 ) {
- sw.WriteLine( "VoiceOverlap=" + VoiceOverlap );
+ sw.write( "VoiceOverlap=" + VoiceOverlap );
+ sw.newLine();
}
- sw.WriteLine( Envelope.ToString() );
+ sw.write( Envelope.ToString() );
+ sw.newLine();
}
if ( Flags != "" ) {
- sw.WriteLine( "Flags=" + Flags );
+ sw.write( "Flags=" + Flags );
+ sw.newLine();
}
if ( Moduration >= 0 ) {
- sw.WriteLine( "Moduration=" + Moduration );
+ sw.write( "Moduration=" + Moduration );
+ sw.newLine();
}
}
+
+ /*public VsqEvent convertToVsqEvent( int clock, int internal_id ) {
+ VsqEvent ret = new VsqEvent();
+ ret.Clock = clock;
+ ret.InternalID = internal_id;
+ ret.UstEvent = (UstEvent)this.clone();
+ ret.ID.setLength( Length );
+ ByRef phonetic_symbol = new ByRef( "" );
+ SymbolTable.attatch( Lyric, phonetic_symbol );
+ ret.ID.LyricHandle = new LyricHandle( Lyric, phonetic_symbol.value );
+ ret.ID.Note = Note;
+ ret.ID.Dynamics = Intensity;
+ ret.ID.type = VsqIDType.Anote;
+ return ret;
+ }*/
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/UstFile.cs b/trunk/Boare.Lib.Vsq/UstFile.cs
index abfbbc3..c9f8638 100644
--- a/trunk/Boare.Lib.Vsq/UstFile.cs
+++ b/trunk/Boare.Lib.Vsq/UstFile.cs
@@ -1,4 +1,4 @@
-/*
+/*
* UstFile.cs
* Copyright (c) 2009 kbinani, PEX
*
@@ -11,17 +11,38 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
+#if JAVA
+package org.kbinani.vsq;
+
+import java.util.*;
+import java.io.*;
+import org.kbinani.*;
+#else
using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Text;
-
using bocoree;
+using bocoree.java.util;
+using bocoree.java.io;
-namespace Boare.Lib.Vsq{
+namespace Boare.Lib.Vsq {
+ using Float = System.Single;
+ using boolean = System.Boolean;
+#endif
+#if JAVA
+ public class UstFile implements Cloneable {
+#else
public class UstFile : ICloneable {
- public object Tag;
+#endif
+ ///
+ /// [#PREV]が指定されているUstEventのIndex
+ ///
+ public const int PREV_INDEX = int.MinValue;
+ ///
+ /// [#NEXT]が指定されているUstEventのIndex
+ ///
+ public const int NEXT_INDEX = int.MaxValue;
+
+ public Object Tag;
private float m_tempo = 120.00f;
private String m_project_name = "";
private String m_voice_dir = "";
@@ -31,23 +52,24 @@ namespace Boare.Lib.Vsq{
private String m_tool2 = "";
private Vector m_tracks = new Vector();
private Vector m_tempo_table;
-
- public UstFile( String path ){
+
+ public UstFile( String path ) {
+ BufferedReader sr = null;
try {
- cp932reader sr = new cp932reader( path );
+ sr = new BufferedReader( new InputStreamReader( new FileInputStream( path ), "Shift_JIS" ) );
#if DEBUG
bocoree.debug.push_log( "path=" + path );
bocoree.debug.push_log( "(sr==null)=" + (sr == null) );
#endif
- String line = sr.ReadLine();
- if ( line != "[#SETTING]" ) {
+ String line = sr.readLine();
+ if ( !line.Equals( "[#SETTING]" ) ) {
throw new Exception( "invalid ust file" );
}
UstTrack track = new UstTrack();
int type = 0; //0 => reading "SETTING" section
while ( true ) {
#if DEBUG
- bocoree.debug.push_log( "line=" + line );
+ PortUtil.println( "line=" + line );
#endif
UstEvent ue = null;
if ( type == 1 ) {
@@ -57,32 +79,40 @@ namespace Boare.Lib.Vsq{
if ( line.Equals( "[#TRACKEND]" ) ) {
break;
} else if ( line.ToUpper().Equals( "[#NEXT]" ) ) {
- index = int.MaxValue;
+ index = NEXT_INDEX;
} else if ( line.ToUpper().Equals( "[#PREV]" ) ) {
- index = int.MinValue;
+ index = PREV_INDEX;
} else {
- String s = line.Replace( "[#", "" ).Replace( "#", "" ).Trim();
- int.TryParse( s, out index );
+ String s = line.Replace( "[#", "" ).Replace( "]", "" ).Trim();
+ try {
+ index = PortUtil.parseInt( s );
+ } catch ( Exception ex ) {
+#if DEBUG
+ PortUtil.println( "UstFile#.ctor; ex=" + ex );
+#endif
+ }
}
#if DEBUG
bocoree.debug.push_log( "index=" + index );
#endif
- line = sr.ReadLine(); // "[#" ̍s
+ line = sr.readLine(); // "[#" 直下の行
if ( line == null ) {
break;
}
while ( !line.StartsWith( "[#" ) ) {
#if DEBUG
- Console.WriteLine( "line=" + line );
+ PortUtil.println( "line=" + line );
#endif
- String[] spl = line.Split( "=".ToCharArray(), 2 );
+ String[] spl = PortUtil.splitString( line, new char[] { '=' }, 2 );
if ( type == 0 ) {
// reading "SETTING" section
if ( spl[0].Equals( "Tempo" ) ) {
m_tempo = 125f;
float v = 125f;
- if ( float.TryParse( spl[1], out v ) ) {
+ try {
+ v = PortUtil.parseFloat( spl[1] );
m_tempo = v;
+ } catch ( Exception ex ) {
}
} else if ( spl[0].Equals( "ProjectName" ) ) {
m_project_name = spl[1];
@@ -100,45 +130,58 @@ namespace Boare.Lib.Vsq{
} else if ( type == 1 ) {
// readin event section
if ( spl[0].Equals( "Length" ) ) {
- ue.Length = 0;
+ ue.setLength( 0 );
int v = 0;
- if ( int.TryParse( spl[1], out v ) ) {
- ue.Length = v;
+ try {
+ v = PortUtil.parseInt( spl[1] );
+ ue.setLength( v );
+ } catch ( Exception ex ) {
}
} else if ( spl[0].Equals( "Lyric" ) ) {
ue.Lyric = spl[1];
} else if ( spl[0].Equals( "NoteNum" ) ) {
ue.Note = 0;
int v = 0;
- if ( int.TryParse( spl[1], out v ) ) {
+ try {
+ v = PortUtil.parseInt( spl[1] );
ue.Note = v;
+ } catch ( Exception ex ) {
}
} else if ( spl[0].Equals( "Intensity" ) ) {
ue.Intensity = 64;
int v = 64;
- if ( int.TryParse( spl[1], out v ) ) {
+ try {
+ v = PortUtil.parseInt( spl[1] );
ue.Intensity = v;
+ } catch ( Exception ex ) {
}
} else if ( spl[0].Equals( "PBType" ) ) {
ue.PBType = 5;
int v = 5;
- if ( int.TryParse( spl[1], out v ) ) {
+ try {
+ v = PortUtil.parseInt( spl[1] );
ue.PBType = v;
+ } catch ( Exception ex ) {
}
} else if ( spl[0].Equals( "Piches" ) ) {
- String[] spl2 = spl[1].Split( ",".ToCharArray() );
+ String[] spl2 = PortUtil.splitString( spl[1], ',' );
float[] t = new float[spl2.Length];
for ( int i = 0; i < spl2.Length; i++ ) {
float v = 0;
- float.TryParse( spl2[i], out v );
- t[i] = v;
+ try {
+ v = PortUtil.parseFloat( spl2[i] );
+ t[i] = v;
+ } catch ( Exception ex ) {
+ }
}
ue.Pitches = t;
} else if ( spl[0].Equals( "Tempo" ) ) {
ue.Tempo = 125f;
float v;
- if ( float.TryParse( spl[1], out v ) ) {
+ try {
+ v = PortUtil.parseFloat( spl[1] );
ue.Tempo = v;
+ } catch ( Exception ex ) {
}
} else if ( spl[0].Equals( "VBR" ) ) {
ue.Vibrato = new UstVibrato( line );
@@ -159,20 +202,24 @@ namespace Boare.Lib.Vsq{
//VoiceOverlap=6
} else if ( spl[0].Equals( "VoiceOverlap" ) ) {
if ( spl[1] != "" ) {
- ue.VoiceOverlap = int.Parse( spl[1] );
+ ue.VoiceOverlap = PortUtil.parseInt( spl[1] );
}
} else if ( spl[0].Equals( "PreUtterance" ) ) {
if ( spl[1] != "" ) {
- ue.PreUtterance = int.Parse( spl[1] );
+ ue.PreUtterance = PortUtil.parseInt( spl[1] );
}
} else if ( spl[0].Equals( "Flags" ) ) {
ue.Flags = line.Substring( 6 );
+ } else {
+#if DEBUG
+ PortUtil.println( "UstFile#.ctor; info: don't know how to process this line; line=" + line );
+#endif
}
}
- if ( sr.Peek() < 0 ) {
+ if ( !sr.ready() ) {
break;
}
- line = sr.ReadLine();
+ line = sr.readLine();
}
#if DEBUG
bocoree.debug.push_log( "(ue==null)=" + (ue == null) );
@@ -185,16 +232,109 @@ namespace Boare.Lib.Vsq{
}
}
m_tracks.add( track );
- sr.Close();
updateTempoInfo();
} catch ( Exception ex ) {
#if DEBUG
bocoree.debug.push_log( "ex=" + ex );
#endif
+ } finally {
+ if ( sr != null ) {
+ try {
+ sr.close();
+ } catch ( Exception ex2 ) {
+ }
+ }
}
}
- private UstFile(){
+ ///
+ /// vsqの指定したトラックを元に,トラックを1つだけ持つustを構築します
+ ///
+ ///
+ ///
+ public UstFile( VsqFile vsq, int track_index ) {
+ VsqTrack track = vsq.Track.get( track_index );
+
+ // デフォルトのテンポ
+ if( vsq.TempoTable.size() <= 0 ){
+ m_tempo = 120.0f;
+ }else{
+ m_tempo = (float)(60e6 / (double)vsq.TempoTable.get( 0 ).Tempo);
+ }
+ updateTempoInfo();
+
+ // R用音符のテンプレート
+ int PBTYPE = 5;
+ UstEvent template = new UstEvent();
+ template.Lyric = "R";
+ template.Note = 60;
+ template.PreUtterance = 0;
+ template.VoiceOverlap = 0;
+ template.Intensity = 100;
+ template.Moduration = 0;
+
+ // 再生秒時をとりあえず無視して,ゲートタイム基準で音符を追加
+ UstTrack track_add = new UstTrack();
+ int last_clock = 0;
+ int index = 0;
+ for( Iterator itr = track.getNoteEventIterator(); itr.hasNext(); ){
+ VsqEvent item = (VsqEvent)itr.next();
+ if( last_clock < item.Clock ){
+ // ゲートタイム差あり,Rを追加
+ UstEvent itemust = (UstEvent)template.clone();
+ itemust.setLength( item.Clock - last_clock );
+ itemust.Index = index;
+ index++;
+ track_add.addEvent( itemust );
+ }
+ UstEvent item_add = new UstEvent();
+ item_add.setLength( item.ID.getLength() );
+ item_add.Lyric = item.ID.LyricHandle.L0.Phrase;
+ item_add.Note = item.ID.Note;
+ item_add.Index = index;
+ item_add.Intensity = item.ID.Dynamics;
+ item_add.Moduration = item.UstEvent.Moduration;
+ item_add.PreUtterance = item.UstEvent.PreUtterance;
+ item_add.VoiceOverlap = item.UstEvent.VoiceOverlap;
+ index++;
+ track_add.addEvent( item_add );
+ last_clock = item.Clock + item.ID.getLength();
+ }
+
+ // 再生秒時を無視して,ピッチベンドを追加
+ //VsqBPList pbs = track.getCurve( "pbs" );
+ //VsqBPList pit = track.getCurve( "pit" );
+ int clock = 0;
+ for ( Iterator itr = track_add.getNoteEventIterator(); itr.hasNext(); ) {
+ UstEvent item = (UstEvent)itr.next();
+ int clock_begin = clock;
+ int clock_end = clock + item.getLength();
+ Vector pitch = new Vector();
+ boolean allzero = true;
+ for ( int cl = clock_begin; cl <= clock_end; cl += PBTYPE ) {
+ float pit = (float)track.getPitchAt( cl );
+ if ( pit != 0.0 ) {
+ allzero = false;
+ }
+ pitch.add( pit );
+ }
+ if ( !allzero ) {
+ item.Pitches = PortUtil.convertFloatArray( pitch.toArray( new Float[] { } ) );
+ item.PBType = PBTYPE;
+ } else {
+ item.PBType = -1;
+ }
+ clock += item.getLength();
+ }
+
+ // 再生秒時を考慮して,適時テンポを追加
+ //TODO: このへん
+ // throw new NotImplementedException();
+
+ m_tracks.add( track_add );
+ }
+
+ private UstFile() {
}
public String getProjectName() {
@@ -210,7 +350,7 @@ namespace Boare.Lib.Vsq{
for ( int track = 0; track < m_tracks.size(); track++ ) {
int count = 0;
for ( int i = 0; i < m_tracks.get( track ).getEventCount(); i++ ) {
- count += (int)m_tracks.get( track ).getEvent( i ).Length;
+ count += (int)m_tracks.get( track ).getEvent( i ).getLength();
}
max = Math.Max( max, count );
}
@@ -230,7 +370,7 @@ namespace Boare.Lib.Vsq{
}
///
- /// TempoTable[*].Time̕XV܂
+ /// TempoTableの[*].Timeの部分を更新します
///
///
public void updateTempoInfo() {
@@ -240,8 +380,8 @@ namespace Boare.Lib.Vsq{
}
int clock = 0;
double time = 0.0;
- int last_tempo_clock = 0; //ŌTempolĂCxg̃NbN
- float last_tempo = m_tempo; //ŌɑĂe|̒l
+ int last_tempo_clock = 0; //最後にTempo値が代入されていたイベントのクロック
+ float last_tempo = m_tempo; //最後に代入されていたテンポの値
for ( int i = 0; i < m_tracks.get( 0 ).getEventCount(); i++ ) {
if ( m_tracks.get( 0 ).getEvent( i ).Tempo > 0f ) {
time += (clock - last_tempo_clock) / (8.0 * last_tempo);
@@ -252,29 +392,23 @@ namespace Boare.Lib.Vsq{
last_tempo = m_tracks.get( 0 ).getEvent( i ).Tempo;
last_tempo_clock = clock;
}
- clock += (int)m_tracks.get( 0 ).getEvent( i ).Length;
+ clock += (int)m_tracks.get( 0 ).getEvent( i ).getLength();
}
-#if DEBUG
- using ( StreamWriter sw = new StreamWriter( Path.Combine( System.Windows.Forms.Application.StartupPath, "ust_tempo_info.txt" ) ) ) {
- sw.WriteLine( "Clock\tTime\tTempo" );
- for ( int i = 0; i < m_tempo_table.size(); i++ ) {
- sw.WriteLine( m_tempo_table.get( i ).Clock + "\t" + m_tempo_table.get( i ).Time + "\t" + m_tempo_table.get( i ).Tempo );
- }
- }
-#endif
}
///
- /// w肵NbNɂAclock=0̉toߎ(sec)
+ /// 指定したクロックにおける、clock=0からの演奏経過時間(sec)
///
///
///
public double getSecFromClock( int clock ) {
- for ( int i = m_tempo_table.size() - 1; i >= 0; i-- ) {
- if ( m_tempo_table.get( i ).Clock < clock ) {
- double init = m_tempo_table.get( i ).Time;
- int dclock = clock - m_tempo_table.get( i ).Clock;
- double sec_per_clock1 = m_tempo_table.get( i ).Tempo * 1e-6 / 480.0;
+ int c = m_tempo_table.size();
+ for ( int i = c - 1; i >= 0; i-- ) {
+ TempoTableEntry item = m_tempo_table.get( i );
+ if ( item.Clock < clock ) {
+ double init = item.Time;
+ int dclock = clock - item.Clock;
+ double sec_per_clock1 = item.Tempo * 1e-6 / 480.0;
return init + dclock * sec_per_clock1;
}
}
@@ -283,24 +417,46 @@ namespace Boare.Lib.Vsq{
}
public void write( String file ) {
- StreamWriter sw = new StreamWriter( file, false, Encoding.GetEncoding( "Shift_JIS" ) );
- sw.WriteLine( "[#SETTING]" );
- sw.WriteLine( "Tempo=" + m_tempo );
- sw.WriteLine( "Tracks=1" );
- sw.WriteLine( "ProjectName=" + m_project_name );
- sw.WriteLine( "VoiceDir=" + m_voice_dir );
- sw.WriteLine( "OutFile=" + m_out_file );
- sw.WriteLine( "CacheDir=" + m_cache_dir );
- sw.WriteLine( "Tool1=" + m_tool1 );
- sw.WriteLine( "Tool2=" + m_tool2 );
- for ( int i = 0; i < m_tracks.get( 0 ).getEventCount(); i++ ) {
- m_tracks.get( 0 ).getEvent( i ).print( sw );
+ BufferedWriter sw = null;
+ try {
+ sw = new BufferedWriter( new OutputStreamWriter( new FileOutputStream( file ), "Shift_JIS" ) );
+ sw.write( "[#SETTING]" );
+ sw.newLine();
+ sw.write( "Tempo=" + m_tempo );
+ sw.newLine();
+ sw.write( "Tracks=1" );
+ sw.newLine();
+ sw.write( "ProjectName=" + m_project_name );
+ sw.newLine();
+ sw.write( "VoiceDir=" + m_voice_dir );
+ sw.newLine();
+ sw.write( "OutFile=" + m_out_file );
+ sw.newLine();
+ sw.write( "CacheDir=" + m_cache_dir );
+ sw.newLine();
+ sw.write( "Tool1=" + m_tool1 );
+ sw.newLine();
+ sw.write( "Tool2=" + m_tool2 );
+ sw.newLine();
+ UstTrack target = m_tracks.get( 0 );
+ int count = target.getEventCount();
+ for ( int i = 0; i < count; i++ ) {
+ target.getEvent( i ).print( sw );
+ }
+ sw.write( "[#TRACKEND]" );
+ sw.newLine();
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sw != null ) {
+ try {
+ sw.close();
+ } catch ( Exception ex2 ) {
+ }
+ }
}
- sw.WriteLine( "[#TRACKEND]" );
- sw.Close();
}
- public object Clone(){
+ public Object clone() {
UstFile ret = new UstFile();
ret.m_tempo = m_tempo;
ret.m_project_name = m_project_name;
@@ -310,14 +466,22 @@ namespace Boare.Lib.Vsq{
ret.m_tool1 = m_tool1;
ret.m_tool2 = m_tool2;
for ( int i = 0; i < m_tracks.size(); i++ ) {
- ret.m_tracks.set( i, (UstTrack)m_tracks.get( i ).Clone() );
+ ret.m_tracks.set( i, (UstTrack)m_tracks.get( i ).clone() );
}
ret.m_tempo_table = new Vector();
for ( int i = 0; i < m_tempo_table.size(); i++ ) {
- ret.m_tempo_table.add( (TempoTableEntry)m_tempo_table.get( i ).Clone() );
+ ret.m_tempo_table.add( (TempoTableEntry)m_tempo_table.get( i ).clone() );
}
return ret;
}
+
+#if !JAVA
+ public object Clone() {
+ return clone();
+ }
+#endif
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/UstPortamento.cs b/trunk/Boare.Lib.Vsq/UstPortamento.cs
index 5b1ab10..fe517d1 100644
--- a/trunk/Boare.Lib.Vsq/UstPortamento.cs
+++ b/trunk/Boare.Lib.Vsq/UstPortamento.cs
@@ -11,59 +11,82 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
-using System;
-using System.Collections.Generic;
-using System.IO;
+#if JAVA
+package org.kbinani.vsq;
+import java.util.*;
+import java.io.*;
+import org.kbinani.*;
+#else
+using System;
using bocoree;
+using bocoree.java.util;
+using bocoree.java.io;
namespace Boare.Lib.Vsq {
+#endif
+#if JAVA
+ public class UstPortamento implements Cloneable, Serializable {
+#else
[Serializable]
public class UstPortamento : ICloneable {
+#endif
public Vector Points = new Vector();
public int Start;
- public void print( StreamWriter sw ) {
+ public void print( BufferedWriter sw )
+#if JAVA
+ throws IOException
+#endif
+ {
String pbw = "";
String pby = "";
String pbm = "";
- for ( int i = 0; i < Points.size(); i++ ) {
+ int count = Points.size();
+ for ( int i = 0; i < count; i++ ) {
String comma = (i == 0 ? "" : ",");
pbw += comma + Points.get( i ).Step;
pby += comma + Points.get( i ).Value;
String type = "";
- switch ( Points.get( i ).Type ) {
- case UstPortamentoType.S:
- type = "";
- break;
- case UstPortamentoType.Linear:
- type = "s";
- break;
- case UstPortamentoType.R:
- type = "r";
- break;
- case UstPortamentoType.J:
- type = "j";
- break;
+ UstPortamentoType ut = Points.get( i ).Type;
+ if ( ut == UstPortamentoType.S ) {
+ type = "";
+ } else if ( ut == UstPortamentoType.Linear ) {
+ type = "s";
+ } else if ( ut == UstPortamentoType.R ) {
+ type = "r";
+ } else if ( ut == UstPortamentoType.J ) {
+ type = "j";
}
pbm += comma + type;
}
- sw.WriteLine( "PBW=" + pbw );
- sw.WriteLine( "PBS=" + Start );
- sw.WriteLine( "PBY=" + pby );
- sw.WriteLine( "PBM=" + pbm );
+ sw.write( "PBW=" + pbw );
+ sw.newLine();
+ sw.write( "PBS=" + Start );
+ sw.newLine();
+ sw.write( "PBY=" + pby );
+ sw.newLine();
+ sw.write( "PBM=" + pbm );
+ sw.newLine();
}
- public object Clone() {
+ public Object clone() {
UstPortamento ret = new UstPortamento();
- for ( int i = 0; i < Points.size(); i++ ) {
+ int count = Points.size();
+ for ( int i = 0; i < count; i++ ) {
ret.Points.add( Points.get( i ) );
}
ret.Start = Start;
return ret;
}
+#if !JAVA
+ public object Clone() {
+ return clone();
+ }
+#endif
+
/*
PBW=50,50,46,48,56,50,50,50,50
PBS=-87
@@ -72,20 +95,20 @@ namespace Boare.Lib.Vsq {
*/
public void ParseLine( String line ) {
line = line.ToLower();
- String[] spl = line.Split( '=' );
+ String[] spl = PortUtil.splitString( line, '=' );
if ( spl.Length == 0 ) {
return;
}
- String[] values = spl[1].Split( ',' );
+ String[] values = PortUtil.splitString( spl[1], ',' );
if ( line.StartsWith( "pbs=" ) ) {
- Start = int.Parse( values[0] );
+ Start = PortUtil.parseInt( values[0] );
} else if ( line.StartsWith( "pbw=" ) ) {
for ( int i = 0; i < values.Length; i++ ) {
if ( i >= Points.size() ) {
Points.add( new UstPortamentoPoint() );
}
UstPortamentoPoint up = Points.get( i );
- up.Step = int.Parse( values[i] );
+ up.Step = PortUtil.parseInt( values[i] );
Points.set( i, up );
}
} else if ( line.StartsWith( "pby=" ) ) {
@@ -94,7 +117,7 @@ namespace Boare.Lib.Vsq {
Points.add( new UstPortamentoPoint() );
}
UstPortamentoPoint up = Points.get( i );
- up.Value = float.Parse( values[i] );
+ up.Value = PortUtil.parseFloat( values[i] );
Points.set( i, up );
}
} else if ( line.StartsWith( "pbm=" ) ) {
@@ -103,19 +126,15 @@ namespace Boare.Lib.Vsq {
Points.add( new UstPortamentoPoint() );
}
UstPortamentoPoint up = Points.get( i );
- switch ( values[i].ToLower() ) {
- case "s":
- up.Type = UstPortamentoType.Linear;
- break;
- case "r":
- up.Type = UstPortamentoType.R;
- break;
- case "j":
- up.Type = UstPortamentoType.J;
- break;
- default:
- up.Type = UstPortamentoType.S;
- break;
+ String search = values[i].ToLower();
+ if ( search.Equals( "s" ) ) {
+ up.Type = UstPortamentoType.Linear;
+ } else if ( search.Equals( "r" ) ) {
+ up.Type = UstPortamentoType.R;
+ } else if ( search.Equals( "j" ) ) {
+ up.Type = UstPortamentoType.J;
+ } else {
+ up.Type = UstPortamentoType.S;
}
Points.set( i, up );
}
@@ -125,29 +144,6 @@ namespace Boare.Lib.Vsq {
}
}
- public struct UstPortamentoPoint {
- public int Step;
- public float Value;
- public UstPortamentoType Type;
- }
-
- public enum UstPortamentoType{
- ///
- /// S型.表記は''(空文字)
- ///
- S,
- ///
- /// 直線型.表記は's'
- ///
- Linear,
- ///
- /// R型.表記は'r'
- ///
- R,
- ///
- /// J型.表記は'j'
- ///
- J,
- }
-
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/UstPortamentoPoint.cs b/trunk/Boare.Lib.Vsq/UstPortamentoPoint.cs
new file mode 100644
index 0000000..17c8622
--- /dev/null
+++ b/trunk/Boare.Lib.Vsq/UstPortamentoPoint.cs
@@ -0,0 +1,28 @@
+/*
+ * UstPortamentoPoint.cs
+ * Copyright (c) 2009 kbinani
+ *
+ * This file is part of Boare.Lib.Vsq.
+ *
+ * Boare.Lib.Vsq is free software; you can redistribute it and/or
+ * modify it under the terms of the BSD License.
+ *
+ * Boare.Lib.Vsq 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.vsq;
+#else
+namespace Boare.Lib.Vsq {
+#endif
+
+ public struct UstPortamentoPoint {
+ public int Step;
+ public float Value;
+ public UstPortamentoType Type;
+ }
+
+#if !JAVA
+}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/UstPortamentoType.cs b/trunk/Boare.Lib.Vsq/UstPortamentoType.cs
new file mode 100644
index 0000000..99dfe39
--- /dev/null
+++ b/trunk/Boare.Lib.Vsq/UstPortamentoType.cs
@@ -0,0 +1,41 @@
+/*
+ * UstPortamentoType.cs
+ * Copyright (c) 2009 kbinani
+ *
+ * This file is part of Boare.Lib.Vsq.
+ *
+ * Boare.Lib.Vsq is free software; you can redistribute it and/or
+ * modify it under the terms of the BSD License.
+ *
+ * Boare.Lib.Vsq 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.vsq;
+#else
+namespace Boare.Lib.Vsq {
+#endif
+
+ public enum UstPortamentoType {
+ ///
+ /// S型.表記は''(空文字)
+ ///
+ S,
+ ///
+ /// 直線型.表記は's'
+ ///
+ Linear,
+ ///
+ /// R型.表記は'r'
+ ///
+ R,
+ ///
+ /// J型.表記は'j'
+ ///
+ J,
+ }
+
+#if !JAVA
+}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/UstTrack.cs b/trunk/Boare.Lib.Vsq/UstTrack.cs
index 19307e3..682bec6 100644
--- a/trunk/Boare.Lib.Vsq/UstTrack.cs
+++ b/trunk/Boare.Lib.Vsq/UstTrack.cs
@@ -11,18 +11,27 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
+#if JAVA
+package org.kbinani.vsq;
+
+import java.util.*;
+#else
using System;
-using System.Collections.Generic;
-
using bocoree;
+using bocoree.java.util;
-namespace Boare.Lib.Vsq{
+namespace Boare.Lib.Vsq {
+#endif
+#if JAVA
+ public class UstTrack implements Cloneable {
+#else
public class UstTrack : ICloneable {
- public object Tag;
+#endif
+ public Object Tag;
private Vector m_events;
-
- public UstTrack(){
+
+ public UstTrack() {
m_events = new Vector();
}
@@ -38,7 +47,7 @@ namespace Boare.Lib.Vsq{
m_events.add( item );
}
- public void removeEvent( int index ) {
+ public void removeEventAt( int index ) {
m_events.removeElementAt( index );
}
@@ -47,16 +56,29 @@ namespace Boare.Lib.Vsq{
}
public Iterator getNoteEventIterator() {
+#if JAVA
+ return m_events.iterator();
+#else
return new ListIterator( m_events );
+#endif
}
- public object Clone() {
+ public Object clone() {
UstTrack ret = new UstTrack();
- for ( int i = 0; i < m_events.size(); i++ ) {
- ret.m_events.set( i, (UstEvent)m_events.get( i ).Clone() );
+ int c = m_events.size();
+ for ( int i = 0; i < c; i++ ) {
+ ret.m_events.set( i, (UstEvent)m_events.get( i ).clone() );
}
return ret;
}
+
+#if !JAVA
+ public object Clone() {
+ return clone();
+ }
+#endif
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/UstVibrato.cs b/trunk/Boare.Lib.Vsq/UstVibrato.cs
index f02a10f..6365cc7 100644
--- a/trunk/Boare.Lib.Vsq/UstVibrato.cs
+++ b/trunk/Boare.Lib.Vsq/UstVibrato.cs
@@ -11,14 +11,24 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
-using System;
+#if JAVA
+package org.kbinani.vsq;
+import java.io.*;
+import org.kbinani.*;
+#else
+using System;
using bocoree;
namespace Boare.Lib.Vsq {
+#endif
+#if JAVA
+ public class UstVibrato implements Cloneable, Serializable {
+#else
[Serializable]
public class UstVibrato : ICloneable {
+#endif
///
/// 音符の長さに対する、パーセントで表したビブラートの長さ。
///
@@ -51,18 +61,18 @@ namespace Boare.Lib.Vsq {
public UstVibrato( String line ) {
if ( line.ToLower().StartsWith( "vbr=" ) ) {
- String[] spl = line.Split( '=' );
- spl = spl[1].Split( ',' );
+ String[] spl = PortUtil.splitString( line, '=' );
+ spl = PortUtil.splitString( spl[1], ',' );
//VBR=65,180,70,20.0,17.6,82.8,49.8,100
if ( spl.Length >= 8 ) {
- Length = float.Parse( spl[0] );
- Period = float.Parse( spl[1] );
- Depth = float.Parse( spl[2] );
- In = float.Parse( spl[3] );
- Out = float.Parse( spl[4] );
- Phase = float.Parse( spl[5] );
- Shift = float.Parse( spl[6] );
- Unknown = float.Parse( spl[7] );
+ Length = PortUtil.parseFloat( spl[0] );
+ Period = PortUtil.parseFloat( spl[1] );
+ Depth = PortUtil.parseFloat( spl[2] );
+ In = PortUtil.parseFloat( spl[3] );
+ Out = PortUtil.parseFloat( spl[4] );
+ Phase = PortUtil.parseFloat( spl[5] );
+ Shift = PortUtil.parseFloat( spl[6] );
+ Unknown = PortUtil.parseFloat( spl[7] );
}
}
}
@@ -70,13 +80,27 @@ namespace Boare.Lib.Vsq {
public UstVibrato() {
}
- public override String ToString() {
+ public float getLength() {
+ return Length;
+ }
+
+ public void setLength( float value ) {
+ Length = value;
+ }
+
+#if !JAVA
+ public override string ToString() {
+ return toString();
+ }
+#endif
+
+ public String toString() {
return "VBR=" + Length + "," + Period + "," + Depth + "," + In + "," + Out + "," + Phase + "," + Shift + "," + Unknown;
}
- public object Clone() {
+ public Object clone() {
UstVibrato ret = new UstVibrato();
- ret.Length = Length;
+ ret.setLength( Length );
ret.Period = Period;
ret.Depth = Depth;
ret.In = In;
@@ -86,6 +110,14 @@ namespace Boare.Lib.Vsq {
ret.Unknown = Unknown;
return ret;
}
+
+#if !JAVA
+ public object Clone() {
+ return clone();
+ }
+#endif
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/VibratoBPList.cs b/trunk/Boare.Lib.Vsq/VibratoBPList.cs
index 371bd9d..4d2f290 100644
--- a/trunk/Boare.Lib.Vsq/VibratoBPList.cs
+++ b/trunk/Boare.Lib.Vsq/VibratoBPList.cs
@@ -11,27 +11,50 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
-using System;
-using System.Collections.Generic;
+#if JAVA
+package org.kbinani.vsq;
+import java.util.*;
+import java.io.*;
+import org.kbinani.*;
+#else
+using System;
using bocoree;
+using bocoree.java.util;
namespace Boare.Lib.Vsq {
+#endif
+#if JAVA
+ public class VibratoBPList implements Cloneable, Serializable {
+#else
[Serializable]
public class VibratoBPList : ICloneable {
+#endif
private Vector m_list;
public VibratoBPList() {
m_list = new Vector();
}
- public VibratoBPList( float[] x, int[] y ){
- if ( x == null ){
+ public VibratoBPList( float[] x, int[] y )
+#if JAVA
+ throws NullPointerException
+#endif
+ {
+ if ( x == null ) {
+#if JAVA
+ throw new NullPointerException( "x" );
+#else
throw new ArgumentNullException( "x" );
+#endif
}
- if ( y == null ){
+ if ( y == null ) {
+#if JAVA
+ throw new NullPointerException( "y" );
+#else
throw new ArgumentNullException( "y" );
+#endif
}
int len = Math.Min( x.Length, y.Length );
m_list = new Vector( len );
@@ -46,7 +69,8 @@ namespace Boare.Lib.Vsq {
return default_value;
}
int index = -1;
- for ( int i = 0; i < m_list.size(); i++ ) {
+ int size = m_list.size();
+ for ( int i = 0; i < size; i++ ) {
if ( x < m_list.get( i ).X ) {
break;
}
@@ -59,7 +83,7 @@ namespace Boare.Lib.Vsq {
}
}
- public object Clone() {
+ public Object clone() {
VibratoBPList ret = new VibratoBPList();
for ( int i = 0; i < m_list.size(); i++ ) {
ret.m_list.add( new VibratoBPPair( m_list.get( i ).X, m_list.get( i ).Y ) );
@@ -67,6 +91,12 @@ namespace Boare.Lib.Vsq {
return ret;
}
+#if !JAVA
+ public object Clone() {
+ return clone();
+ }
+#endif
+
public int getCount() {
return m_list.size();
}
@@ -79,29 +109,41 @@ namespace Boare.Lib.Vsq {
m_list.set( index, value );
}
+#if !JAVA
///
/// XMLシリアライズ用
///
public String Data {
get {
- String ret = "";
- for ( int i = 0; i < m_list.size(); i++ ) {
- ret += (i == 0 ? "" : ",") + m_list.get( i ).X + "=" + m_list.get( i ).Y;
- }
- return ret;
+ return getData();
}
set {
- m_list.clear();
- String[] spl = value.Split( ',' );
- for ( int i = 0; i < spl.Length; i++ ) {
- String[] spl2 = spl[i].Split( '=' );
- if ( spl2.Length < 2 ) {
- continue;
- }
- m_list.add( new VibratoBPPair( float.Parse( spl2[0] ), int.Parse( spl2[1] ) ) );
+ setData( value );
+ }
+ }
+#endif
+
+ public String getData() {
+ String ret = "";
+ for ( int i = 0; i < m_list.size(); i++ ) {
+ ret += (i == 0 ? "" : ",") + m_list.get( i ).X + "=" + m_list.get( i ).Y;
+ }
+ return ret;
+ }
+
+ public void setData( String value ) {
+ m_list.clear();
+ String[] spl = PortUtil.splitString( value, ',' );
+ for ( int i = 0; i < spl.Length; i++ ) {
+ String[] spl2 = PortUtil.splitString( spl[i], '=' );
+ if ( spl2.Length < 2 ) {
+ continue;
}
+ m_list.add( new VibratoBPPair( PortUtil.parseFloat( spl2[0] ), PortUtil.parseInt( spl2[1] ) ) );
}
}
}
-}
\ No newline at end of file
+#if !JAVA
+}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/VibratoBPPair.cs b/trunk/Boare.Lib.Vsq/VibratoBPPair.cs
index 8262ee4..1ec3f8a 100644
--- a/trunk/Boare.Lib.Vsq/VibratoBPPair.cs
+++ b/trunk/Boare.Lib.Vsq/VibratoBPPair.cs
@@ -11,12 +11,22 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
+#if JAVA
+package org.kbinani.vsq;
+
+import java.io.*;
+#else
using System;
namespace Boare.Lib.Vsq {
+#endif
+#if JAVA
+ public class VibratoBPPair implements Comparable, Serializable {
+#else
[Serializable]
public class VibratoBPPair : IComparable {
+#endif
public float X;
public int Y;
@@ -28,7 +38,7 @@ namespace Boare.Lib.Vsq {
Y = y;
}
- public int CompareTo( VibratoBPPair item ) {
+ public int compareTo( VibratoBPPair item ) {
float v = X - item.X;
if ( v > 0.0f ) {
return 1;
@@ -37,6 +47,14 @@ namespace Boare.Lib.Vsq {
}
return 0;
}
+
+#if !JAVA
+ public int CompareTo( VibratoBPPair item ) {
+ return compareTo( item );
+ }
+#endif
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/VibratoConfig.cs b/trunk/Boare.Lib.Vsq/VibratoConfig.cs
index d2e4b15..6ed794a 100644
--- a/trunk/Boare.Lib.Vsq/VibratoConfig.cs
+++ b/trunk/Boare.Lib.Vsq/VibratoConfig.cs
@@ -11,12 +11,18 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
-using System;
-using System.IO;
+#if JAVA
+package org.kbinani.vsq;
+import java.io.*;
+import org.kbinani.*;
+#else
+using System;
using bocoree;
+using bocoree.java.io;
namespace Boare.Lib.Vsq {
+#endif
public class VibratoConfig {
public int number;
@@ -25,12 +31,22 @@ namespace Boare.Lib.Vsq {
public String vendor;
public VibratoHandle contents;
+ public override String ToString() {
+ if ( contents == null ) {
+ return base.ToString();
+ } else {
+ return contents.Caption;
+ }
+ }
+
public VibratoConfig() {
contents = new VibratoHandle();
}
public void parseAic( String aic_file ) {
- using ( StreamReader sr = new StreamReader( aic_file ) ) {
+ BufferedReader sr = null;
+ try {
+ sr = new BufferedReader( new FileReader( aic_file ) );
String line;
String current_entry = "";
String articulation = "";
@@ -40,7 +56,7 @@ namespace Boare.Lib.Vsq {
String rate_bpy = "";
int depth_bpnum = 0;
int rate_bpnum = 0;
- while ( (line = sr.ReadLine()) != null ) {
+ while ( (line = sr.readLine()) != null ) {
if ( line.StartsWith( "[" ) ) {
current_entry = line;
continue;
@@ -48,7 +64,7 @@ namespace Boare.Lib.Vsq {
continue;
}
- String[] spl = line.Split( new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries );
+ String[] spl = PortUtil.splitString( line, new char[] { '=' }, true );
if ( spl.Length < 2 ) {
continue;
}
@@ -61,28 +77,33 @@ namespace Boare.Lib.Vsq {
} else if ( current_entry.Equals( "[Parameter]" ) ) {
if ( spl[0].Equals( "Length" ) ) {
try {
- this.contents.Length = int.Parse( spl[1] );
- } catch { }
+ this.contents.setLength( PortUtil.parseInt( spl[1] ) );
+ } catch ( Exception ex0 ) {
+ }
} else if ( spl[0].Equals( "StartDepth" ) ) {
try {
- this.contents.StartDepth = int.Parse( spl[1] );
- } catch { }
+ this.contents.StartDepth = PortUtil.parseInt( spl[1] );
+ } catch ( Exception ex0 ) {
+ }
} else if ( spl[0].Equals( "DepthBPNum" ) ) {
try {
- depth_bpnum = int.Parse( spl[1] );
- } catch { }
+ depth_bpnum = PortUtil.parseInt( spl[1] );
+ } catch ( Exception ex0 ) {
+ }
} else if ( spl[0].Equals( "DepthBPX" ) ) {
depth_bpx = spl[1];
} else if ( spl[0].Equals( "DepthBPY" ) ) {
depth_bpy = spl[1];
} else if ( spl[0].Equals( "StartRate" ) ) {
try {
- this.contents.StartRate = int.Parse( spl[1] );
- } catch { }
+ this.contents.StartRate = PortUtil.parseInt( spl[1] );
+ } catch ( Exception ex0 ) {
+ }
} else if ( spl[0].Equals( "RateBPNum" ) ) {
try {
- rate_bpnum = int.Parse( spl[1] );
- } catch { }
+ rate_bpnum = PortUtil.parseInt( spl[1] );
+ } catch ( Exception ex0 ) {
+ }
} else if ( spl[0].Equals( "RateBPX" ) ) {
rate_bpx = spl[1];
} else if ( spl[0].Equals( "RateBPY" ) ) {
@@ -90,45 +111,57 @@ namespace Boare.Lib.Vsq {
}
}
}
- if ( articulation != "Vibrato" ) {
+ if ( !articulation.Equals( "Vibrato" ) ) {
return;
}
// depth bp
- if ( depth_bpnum > 0 && depth_bpx != "" && depth_bpy != "" ) {
- String[] bpx = depth_bpx.Split( ',' );
- String[] bpy = depth_bpy.Split( ',' );
+ if ( depth_bpnum > 0 && !depth_bpx.Equals( "" ) && !depth_bpy.Equals( "" ) ) {
+ String[] bpx = PortUtil.splitString( depth_bpx, ',' );
+ String[] bpy = PortUtil.splitString( depth_bpy, ',' );
if ( depth_bpnum == bpx.Length && depth_bpnum == bpy.Length ) {
float[] x = new float[depth_bpnum];
int[] y = new int[depth_bpnum];
try {
for ( int i = 0; i < depth_bpnum; i++ ) {
- x[i] = float.Parse( bpx[i] );
- y[i] = int.Parse( bpy[i] );
+ x[i] = PortUtil.parseFloat( bpx[i] );
+ y[i] = PortUtil.parseInt( bpy[i] );
}
this.contents.DepthBP = new VibratoBPList( x, y );
- } catch { }
+ } catch ( Exception ex0 ) {
+ }
}
}
// rate bp
- if ( rate_bpnum > 0 && rate_bpx != "" && rate_bpy != "" ) {
- String[] bpx = rate_bpx.Split( ',' );
- String[] bpy = rate_bpy.Split( ',' );
+ if ( rate_bpnum > 0 && !rate_bpx.Equals( "" ) && !rate_bpy.Equals( "" ) ) {
+ String[] bpx = PortUtil.splitString( rate_bpx, ',' );
+ String[] bpy = PortUtil.splitString( rate_bpy, ',' );
if ( rate_bpnum == bpx.Length && rate_bpnum == bpy.Length ) {
float[] x = new float[rate_bpnum];
int[] y = new int[rate_bpnum];
try {
for ( int i = 0; i < rate_bpnum; i++ ) {
- x[i] = float.Parse( bpx[i] );
- y[i] = int.Parse( bpy[i] );
+ x[i] = PortUtil.parseFloat( bpx[i] );
+ y[i] = PortUtil.parseInt( bpy[i] );
}
this.contents.RateBP = new VibratoBPList( x, y );
- } catch { }
+ } catch ( Exception ex0 ) {
+ }
+ }
+ }
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sr != null ) {
+ try {
+ sr.close();
+ } catch ( Exception ex2 ) {
}
}
}
}
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/VibratoHandle.cs b/trunk/Boare.Lib.Vsq/VibratoHandle.cs
new file mode 100644
index 0000000..2000d57
--- /dev/null
+++ b/trunk/Boare.Lib.Vsq/VibratoHandle.cs
@@ -0,0 +1,104 @@
+/*
+ * VibratoHandle.cs
+ * Copyright (c) 2009 kbinani
+ *
+ * This file is part of Boare.Lib.Vsq.
+ *
+ * Boare.Lib.Vsq is free software; you can redistribute it and/or
+ * modify it under the terms of the BSD License.
+ *
+ * Boare.Lib.Vsq 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.vsq;
+
+import java.io.*;
+#else
+using System;
+
+namespace Boare.Lib.Vsq {
+#endif
+
+#if JAVA
+ public class VibratoHandle implements Cloneable, Serializable {
+#else
+ [Serializable]
+ public class VibratoHandle : ICloneable {
+#endif
+ public int StartDepth;
+ public VibratoBPList DepthBP;
+ public int StartRate;
+ public VibratoBPList RateBP;
+ public int Index;
+ public String IconID = "";
+ public String IDS = "";
+ public int Original;
+ public String Caption = "";
+ public int Length;
+
+ public VibratoHandle() {
+ StartRate = 64;
+ StartDepth = 64;
+ RateBP = new VibratoBPList();
+ DepthBP = new VibratoBPList();
+ }
+
+ public int getLength() {
+ return Length;
+ }
+
+ public void setLength( int value ) {
+ Length = value;
+ }
+
+ public String getDisplayString() {
+ String s = IDS;
+ if ( !Caption.Equals( "" ) ) {
+ s += " (" + Caption + ")";
+ }
+ return s;
+ }
+
+#if !JAVA
+ public object Clone() {
+ return clone();
+ }
+#endif
+
+ public Object clone() {
+ VibratoHandle result = new VibratoHandle();
+ result.Index = Index;
+ result.IconID = IconID;
+ result.IDS = this.IDS;
+ result.Original = this.Original;
+ result.Caption = this.Caption;
+ result.setLength( Length );
+ result.StartDepth = this.StartDepth;
+ result.DepthBP = (VibratoBPList)DepthBP.clone();
+ result.StartRate = this.StartRate;
+ result.RateBP = (VibratoBPList)RateBP.clone();
+ return result;
+ }
+
+ public VsqHandle castToVsqHandle() {
+ VsqHandle ret = new VsqHandle();
+ ret.m_type = VsqHandleType.Vibrato;
+ ret.Index = Index;
+ ret.IconID = IconID;
+ ret.IDS = IDS;
+ ret.Original = Original;
+ ret.Caption = Caption;
+ ret.setLength( Length );
+ ret.StartDepth = StartDepth;
+ ret.StartRate = StartRate;
+ ret.DepthBP = (VibratoBPList)DepthBP.clone();
+ ret.RateBP = (VibratoBPList)RateBP.clone();
+ return ret;
+ }
+ }
+
+#if !JAVA
+}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/VocaloSysUtil.cs b/trunk/Boare.Lib.Vsq/VocaloSysUtil.cs
index 5f10f78..237157d 100644
--- a/trunk/Boare.Lib.Vsq/VocaloSysUtil.cs
+++ b/trunk/Boare.Lib.Vsq/VocaloSysUtil.cs
@@ -11,169 +11,263 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
+#if JAVA
+package org.kbinani.vsq;
+
+import java.io.*;
+import java.util.*;
+import org.kbinani.*;
+#else
using System;
-using System.IO;
using System.Collections.Generic;
using Microsoft.Win32;
-
using bocoree;
+using bocoree.java.util;
+using bocoree.java.io;
namespace Boare.Lib.Vsq {
+#endif
- using boolean = Boolean;
+ public class VocaloSysUtil {
+ private static TreeMap s_singer_config_sys = new TreeMap();
+ private static TreeMap s_exp_config_sys = new TreeMap();
+ private static TreeMap s_path_vsti = new TreeMap();
+ private static TreeMap s_path_editor = new TreeMap();
- public static class VocaloSysUtil{
- private static SingerConfigSys s_singer_config_sys1;
- private static SingerConfigSys s_singer_config_sys2;
- private static ExpressionConfigSys s_exp_config_sys1;
- private static ExpressionConfigSys s_exp_config_sys2;
- private static String s_path_vsti1 = "";
- private static String s_path_vsti2 = "";
- private static String s_path_editor1 = "";
- private static String s_path_editor2 = "";
+ private VocaloSysUtil() {
+ }
+#if JAVA
+ static{
+#else
static VocaloSysUtil() {
+#endif
+ ExpressionConfigSys exp_config_sys1 = null;
try {
Vector dir1 = new Vector();
- RegistryKey key1 = Registry.LocalMachine.OpenSubKey( "SOFTWARE\\VOCALOID", false );
- String path_voicedb1 = "";
- String path_expdb1 = "";
+ ByRef path_voicedb1 = new ByRef( "" );
+ ByRef path_expdb1 = new ByRef( "" );
Vector installed_singers1 = new Vector();
- if ( key1 != null ) {
- String header1 = "HKLM\\SOFTWARE\\VOCALOID";
- print( key1, header1, dir1 );
- key1.Close();
- extract( dir1,
- header1,
- out s_path_vsti1,
- out path_voicedb1,
- out path_expdb1,
- out s_path_editor1,
- installed_singers1 );
+ String header1 = "HKLM\\SOFTWARE\\VOCALOID";
+ print( "SOFTWARE\\VOCALOID", header1, dir1 );
+#if DEBUG
+ BufferedWriter sw = null;
+ try {
+ sw = new BufferedWriter( new FileWriter( PortUtil.combinePath( System.Windows.Forms.Application.StartupPath, "reg_keys_vocalo1.txt" ) ) );
+ foreach ( String s in dir1 ) {
+ sw.write( s );
+ sw.newLine();
+ }
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sw != null ) {
+ try {
+ sw.close();
+ } catch ( Exception ex2 ) {
+ }
+ }
}
- s_singer_config_sys1 = new SingerConfigSys( path_voicedb1, installed_singers1.toArray( new String[] { } ) );
- s_exp_config_sys1 = new ExpressionConfigSys( path_expdb1 );
- }catch( Exception ex ){
- Console.WriteLine( "VocaloSysUtil..cctor; ex=" + ex );
- s_singer_config_sys1 = new SingerConfigSys( "", new String[] { } );
- s_exp_config_sys1 = new ExpressionConfigSys( "" );
- }
-
- try{
- Vector dir2 = new Vector();
- RegistryKey key2 = Registry.LocalMachine.OpenSubKey( "SOFTWARE\\VOCALOID2", false );
- String path_voicedb2 = "";
- String path_expdb2 = "";
- Vector installed_singers2 = new Vector();
- if ( key2 != null ) {
- String header2 = "HKLM\\SOFTWARE\\VOCALOID2";
- print( key2, header2, dir2 );
- key2.Close();
- extract( dir2,
- header2,
- out s_path_vsti2,
- out path_voicedb2,
- out path_expdb2,
- out s_path_editor2,
- installed_singers2 );
+#endif
+ ByRef path_vsti = new ByRef( "" );
+ ByRef path_editor = new ByRef( "" );
+ extract( dir1,
+ header1,
+ path_vsti,
+ path_voicedb1,
+ path_expdb1,
+ path_editor,
+ installed_singers1 );
+ s_path_vsti.put( SynthesizerType.VOCALOID1, path_vsti.value );
+ s_path_editor.put( SynthesizerType.VOCALOID1, path_editor.value );
+ SingerConfigSys singer_config_sys = new SingerConfigSys( path_voicedb1.value, installed_singers1.toArray( new String[] { } ) );
+ if ( PortUtil.isFileExists( PortUtil.combinePath( path_expdb1.value, "expression.map" ) ) ) {
+ exp_config_sys1 = new ExpressionConfigSys( path_expdb1.value );
}
- s_singer_config_sys2 = new SingerConfigSys( path_voicedb2, installed_singers2.toArray( new String[] { } ) );
- s_exp_config_sys2 = new ExpressionConfigSys( path_expdb2 );
+ s_singer_config_sys.put( SynthesizerType.VOCALOID1, singer_config_sys );
} catch ( Exception ex ) {
- Console.WriteLine( "VocaloSysUtil..cctor; ex=" + ex );
- s_singer_config_sys2 = new SingerConfigSys( "", new String[] { } );
- s_exp_config_sys2 = new ExpressionConfigSys( "" );
+ PortUtil.println( "VocaloSysUtil..cctor; ex=" + ex );
+ SingerConfigSys singer_config_sys = new SingerConfigSys( "", new String[] { } );
+ exp_config_sys1 = null;
+ s_singer_config_sys.put( SynthesizerType.VOCALOID1, singer_config_sys );
}
+ if ( exp_config_sys1 == null ) {
+ exp_config_sys1 = ExpressionConfigSys.getVocaloid1Default();
+ }
+ s_exp_config_sys.put( SynthesizerType.VOCALOID1, exp_config_sys1 );
+
+ ExpressionConfigSys exp_config_sys2 = null;
+ try {
+ Vector dir2 = new Vector();
+ ByRef path_voicedb2 = new ByRef( "" );
+ ByRef path_expdb2 = new ByRef( "" );
+ Vector installed_singers2 = new Vector();
+ String header2 = "HKLM\\SOFTWARE\\VOCALOID2";
+ print( "SOFTWARE\\VOCALOID2", header2, dir2 );
+#if DEBUG
+ BufferedWriter sw = null;
+ try {
+ sw = new BufferedWriter( new FileWriter( PortUtil.combinePath( System.Windows.Forms.Application.StartupPath, "reg_keys_vocalo2.txt" ) ) );
+ foreach ( String s in dir2 ) {
+ sw.write( s );
+ sw.newLine();
+ }
+ } catch ( Exception ex ) {
+ } finally {
+ if ( sw != null ) {
+ try {
+ sw.close();
+ } catch ( Exception ex2 ) {
+ }
+ }
+ }
+#endif
+ ByRef path_vsti = new ByRef( "" );
+ ByRef path_editor = new ByRef( "" );
+ extract( dir2,
+ header2,
+ path_vsti,
+ path_voicedb2,
+ path_expdb2,
+ path_editor,
+ installed_singers2 );
+ s_path_vsti.put( SynthesizerType.VOCALOID2, path_vsti.value );
+ s_path_editor.put( SynthesizerType.VOCALOID2, path_editor.value );
+ SingerConfigSys singer_config_sys = new SingerConfigSys( path_voicedb2.value, installed_singers2.toArray( new String[] { } ) );
+ if ( PortUtil.isFileExists( PortUtil.combinePath( path_expdb2.value, "expression.map" ) ) ) {
+ exp_config_sys2 = new ExpressionConfigSys( path_expdb2.value );
+ }
+ s_singer_config_sys.put( SynthesizerType.VOCALOID2, singer_config_sys );
+ } catch ( Exception ex ) {
+ PortUtil.println( "VocaloSysUtil..cctor; ex=" + ex );
+ SingerConfigSys singer_config_sys = new SingerConfigSys( "", new String[] { } );
+ exp_config_sys2 = null;
+ s_singer_config_sys.put( SynthesizerType.VOCALOID2, singer_config_sys );
+ }
+ if ( exp_config_sys2 == null ) {
+ exp_config_sys2 = ExpressionConfigSys.getVocaloid2Default();
+ }
+ s_exp_config_sys.put( SynthesizerType.VOCALOID2, exp_config_sys2 );
+#if DEBUG
+ SingerConfigSys scs2 = s_singer_config_sys.get( SynthesizerType.VOCALOID2 );
+ foreach( SingerConfig sc in scs2.getInstalledSingers() ){
+ PortUtil.println( "VocaloSysUtil#.ctor; sc=" + sc.toString() );
+ }
+#endif
}
+ ///
+ /// ビブラートのプリセットタイプから,VibratoHandleを作成します
+ ///
+ ///
+ ///
+ ///
+ public static VibratoHandle getDefaultVibratoHandle( String icon_id, int vibrato_length, SynthesizerType type ) {
+ if ( s_exp_config_sys.containsKey( type ) ) {
+ for ( Iterator itr = s_exp_config_sys.get( type ).vibratoConfigIterator(); itr.hasNext(); ) {
+ VibratoConfig vconfig = (VibratoConfig)itr.next();
+ if ( vconfig.contents.IconID.Equals( icon_id ) ) {
+ VibratoHandle ret = (VibratoHandle)vconfig.contents.clone();
+ ret.setLength( vibrato_length );
+ return ret;
+ }
+ }
+ }
+ VibratoHandle empty = new VibratoHandle();
+ empty.IconID = "$04040000";
+ return empty;
+ }
+
+
private static void extract( Vector dir,
String header,
- out String path_vsti,
- out String path_voicedb,
- out String path_expdb,
- out String path_editor,
+ ByRef path_vsti,
+ ByRef path_voicedb,
+ ByRef path_expdb,
+ ByRef path_editor,
Vector installed_singers ) {
Vector application = new Vector();
Vector expression = new Vector();
Vector voice = new Vector();
- path_vsti = "";
- path_expdb = "";
- path_voicedb = "";
- path_editor = "";
- for( Iterator itr = dir.iterator(); itr.hasNext(); ) {
+ path_vsti.value = "";
+ path_expdb.value = "";
+ path_voicedb.value = "";
+ path_editor.value = "";
+ for ( Iterator itr = dir.iterator(); itr.hasNext(); ) {
String s = (String)itr.next();
if ( s.StartsWith( header + "\\APPLICATION" ) ) {
- application.add( s.Substring( (header + "\\APPLICATION").Length ) );
+ application.add( s.Substring( PortUtil.getStringLength( header + "\\APPLICATION" ) ) );
} else if ( s.StartsWith( header + "\\DATABASE\\EXPRESSION" ) ) {
- expression.add( s.Substring( (header + "\\DATABASE\\EXPRESSION").Length ) );
+ expression.add( s.Substring( PortUtil.getStringLength( header + "\\DATABASE\\EXPRESSION" ) ) );
} else if ( s.StartsWith( header + "\\DATABASE\\VOICE" ) ) {
- voice.add( s.Substring( (header + "\\DATABASE\\VOICE\\").Length ) );
+ voice.add( s.Substring( PortUtil.getStringLength( header + "\\DATABASE\\VOICE\\" ) ) );
}
}
// path_vstiを取得
- for( Iterator itr = application.iterator(); itr.hasNext(); ){
+ for ( Iterator itr = application.iterator(); itr.hasNext(); ) {
String s = (String)itr.next();
- String[] spl = s.Split( '\t' );
- if ( spl.Length >= 3 && spl[1].Equals( "PATH" ) ){
+ String[] spl = PortUtil.splitString( s, '\t' );
+ if ( spl.Length >= 3 && spl[1].Equals( "PATH" ) ) {
if ( spl[2].ToLower().EndsWith( ".dll" ) ) {
- path_vsti = spl[2];
+ path_vsti.value = spl[2];
} else if ( spl[2].ToLower().EndsWith( ".exe" ) ) {
- path_editor = spl[2];
+ path_editor.value = spl[2];
}
}
}
// path_vicedbを取得
- Vector voice_ids = new Vector();
+ TreeMap install_dirs = new TreeMap();
// 最初はpath_voicedbの取得と、id(BHXXXXXXXXXXXXXXXX)のようなシリアルを取得
- for( Iterator itr = voice.iterator(); itr.hasNext(); ){
+ for ( Iterator itr = voice.iterator(); itr.hasNext(); ) {
String s = (String)itr.next();
- String[] spl = s.Split( '\t' );
+ String[] spl = PortUtil.splitString( s, '\t' );
if ( spl.Length >= 2 ) {
if ( spl[0].Equals( "VOICEDIR" ) ) {
- path_voicedb = spl[1];
+ path_voicedb.value = spl[1];
} else if ( spl.Length >= 3 ) {
- String[] spl2 = spl[0].Split( '\\' );
- if ( spl2.Length == 1 ) {
- if ( !voice_ids.contains( spl2[0] ) ) {
- voice_ids.add( spl2[0] );
+ String[] spl2 = PortUtil.splitString( spl[0], '\\' );
+ if ( spl2.Length == 1 ){
+ if ( !install_dirs.containsKey( spl2[0] ) ) {
+ String install = "";
+ if ( spl[1].Equals( "INSTALLDIR" ) ) {
+ install = spl[2];
+ }
+ install_dirs.put( spl2[0], install );
+ } else {
+ if ( spl[1].Equals( "INSTALLDIR" ) ) {
+ install_dirs.put( spl2[0], spl[2] );
+ }
}
}
}
}
}
- // 取得したシリアルを元に、installed_singersを取得
- for( Iterator itr = voice_ids.iterator(); itr.hasNext(); ) {
- String s = (String)itr.next();
- String install_dir = "";
- for( Iterator itr2 = voice.iterator(); itr2.hasNext(); ){
- String s2 = (String)itr2.next();
- if ( s2.StartsWith( header + "\\" + s + "\t" ) ) {
- String[] spl = s2.Split( '\t' );
- if ( spl.Length >= 3 && spl[1].Equals( "INSTALLDIR" ) ) {
- install_dir = Path.Combine( spl[2], s );
- break;
- }
- }
+
+ // installed_singersに追加
+ for ( Iterator itr = install_dirs.keySet().iterator(); itr.hasNext(); ) {
+ String id = (String)itr.next();
+ String install = install_dirs.get( id );
+ if ( id.Equals( "" ) ) {
+ install = path_voicedb.value;
}
- if ( install_dir.Equals( "" ) ) {
- install_dir = Path.Combine( path_voicedb, s );
- }
- installed_singers.add( install_dir );
+ installed_singers.add( install );
}
// path_expdbを取得
Vector exp_ids = new Vector();
// 最初はpath_expdbの取得と、id(BHXXXXXXXXXXXXXXXX)のようなシリアルを取得
- for( Iterator itr = expression.iterator(); itr.hasNext(); ){
+ for ( Iterator itr = expression.iterator(); itr.hasNext(); ) {
String s = (String)itr.next();
- String[] spl = s.Split( '\t' );
+#if DEBUG
+ PortUtil.println( "VocaloSysUtil#extract; s=" + s );
+#endif
+ String[] spl = PortUtil.splitString( s, new char[] { '\t' }, true );
if ( spl.Length >= 2 ) {
if ( spl[0].Equals( "EXPRESSIONDIR" ) ) {
- path_expdb = spl[1];
+ path_expdb.value = spl[1];
} else if ( spl.Length >= 3 ) {
- String[] spl2 = spl[0].Split( '\\' );
+ String[] spl2 = PortUtil.splitString( spl[0], '\\' );
if ( spl2.Length == 1 ) {
if ( !exp_ids.contains( spl2[0] ) ) {
exp_ids.add( spl2[0] );
@@ -182,59 +276,65 @@ namespace Boare.Lib.Vsq {
}
}
}
- // 取得したシリアルを元に、installed_singersを取得
- /*foreach ( String s in exp_ids ) {
- String install_dir = "";
- foreach ( String s2 in expression ) {
- if ( s2.StartsWith( header + "\\" + s + "\t" ) ) {
- String[] spl = s2.Split( '\t' );
- if ( spl.Length >= 3 && spl[1].Equals( "INSTALLDIR" ) ) {
- install_dir = Path.Combine( spl[2], s );
- break;
- }
- }
- }
- if ( install_dir.Equals( "" ) ) {
- install_dir = Path.Combine( path_expdb, s );
- }
- installed_singers.Add( install_dir );
- }*/
-
#if DEBUG
- Console.WriteLine( "path_vsti=" + path_vsti );
- Console.WriteLine( "path_voicedb=" + path_voicedb );
- Console.WriteLine( "path_expdb=" + path_expdb );
- Console.WriteLine( "installed_singers=" );
- for( Iterator itr = installed_singers.iterator(); itr.hasNext(); ){
+ PortUtil.println( "path_vsti=" + path_vsti.value );
+ PortUtil.println( "path_voicedb=" + path_voicedb.value );
+ PortUtil.println( "path_expdb=" + path_expdb.value );
+ PortUtil.println( "installed_singers=" );
+ for ( Iterator itr = installed_singers.iterator(); itr.hasNext(); ) {
String s = (String)itr.next();
- Console.WriteLine( " " + s );
+ PortUtil.println( " " + s );
}
#endif
}
- // レジストリkey内の値を再帰的に検索し、ファイルfpに順次出力する
- private static void print( RegistryKey key, String parent_name, Vector list ){
+ ///
+ /// レジストリkey内の値を再帰的に検索し、ファイルfpに順次出力する
+ ///
+ ///
+ ///
+ ///
+ private static void print( String reg_key_name, String parent_name, Vector list ) {
+#if JAVA
+#else
+ RegistryKey key = Registry.LocalMachine.OpenSubKey( reg_key_name, false );
if ( key == null ) {
return;
}
// 直下のキー内を再帰的にリストアップ
String[] subkeys = key.GetSubKeyNames();
- foreach( String s in subkeys ){
- RegistryKey subkey = key.OpenSubKey( s, false );
- print( subkey, parent_name + "\\" + s, list );
- subkey.Close();
+ foreach ( String s in subkeys ) {
+ print( reg_key_name + "\\" + s, parent_name + "\\" + s, list );
}
// 直下の値を出力
String[] valuenames = key.GetValueNames();
- foreach( String s in valuenames ){
+ foreach ( String s in valuenames ) {
RegistryValueKind kind = key.GetValueKind( s );
- if ( kind == RegistryValueKind.String ){
+ if ( kind == RegistryValueKind.String ) {
String str = parent_name + "\t" + s + "\t" + (String)key.GetValue( s, "" );
list.add( str );
}
}
+ key.Close();
+#endif
+ }
+
+ public static Iterator attackConfigIterator( SynthesizerType type ) {
+ if ( s_exp_config_sys.containsKey( type ) ) {
+ return s_exp_config_sys.get( type ).attackConfigIterator();
+ } else {
+ return (new Vector()).iterator();
+ }
+ }
+
+ public static Iterator vibratoConfigIterator( SynthesizerType type ) {
+ if ( s_exp_config_sys.containsKey( type ) ) {
+ return s_exp_config_sys.get( type ).vibratoConfigIterator();
+ } else {
+ return (new Vector()).iterator();
+ }
}
///
@@ -242,9 +342,13 @@ namespace Boare.Lib.Vsq {
///
///
///
- public static String getOriginalSinger1( String singer ) {
+ public static String getOriginalSinger( String singer, SynthesizerType type ) {
String voiceidstr = "";
- SingerConfig[] singer_configs = s_singer_config_sys1.getSingerConfigs();
+ if ( !s_singer_config_sys.containsKey( type ) ) {
+ return "";
+ }
+ SingerConfigSys scs = s_singer_config_sys.get( type );
+ SingerConfig[] singer_configs = scs.getSingerConfigs();
for ( int i = 0; i < singer_configs.Length; i++ ) {
if ( singer.Equals( singer_configs[i].VOICENAME ) ) {
voiceidstr = singer_configs[i].VOICEIDSTR;
@@ -254,7 +358,7 @@ namespace Boare.Lib.Vsq {
if ( voiceidstr.Equals( "" ) ) {
return "";
}
- SingerConfig[] installed_singers = s_singer_config_sys1.getInstalledSingers();
+ SingerConfig[] installed_singers = scs.getInstalledSingers();
for ( int i = 0; i < installed_singers.Length; i++ ) {
if ( voiceidstr.Equals( installed_singers[i].VOICEIDSTR ) ) {
return installed_singers[i].VOICENAME;
@@ -263,62 +367,36 @@ namespace Boare.Lib.Vsq {
return "";
}
- ///
- /// Gets the name of original singer of specified program change.
- ///
- ///
- ///
- public static String getOriginalSinger2( String singer ) {
- String voiceidstr = "";
- SingerConfig[] singer_configs = s_singer_config_sys2.getSingerConfigs();
- for ( int i = 0; i < singer_configs.Length; i++ ) {
- if ( singer.Equals( singer_configs[i].VOICENAME ) ) {
- voiceidstr = singer_configs[i].VOICEIDSTR;
- break;
- }
+ public static VsqID getSingerID( String singer, SynthesizerType type ) {
+ if ( !s_singer_config_sys.containsKey( type ) ) {
+ return null;
+ } else {
+ return s_singer_config_sys.get( type ).getSingerID( singer );
}
- if ( voiceidstr.Equals( "" ) ) {
+ }
+
+ public static String getEditorPath( SynthesizerType type ) {
+ if ( !s_path_editor.containsKey( type ) ) {
return "";
+ } else {
+ return s_path_editor.get( type );
}
- SingerConfig[] installed_singers = s_singer_config_sys2.getInstalledSingers();
- for ( int i = 0; i < installed_singers.Length; i++ ) {
- if ( voiceidstr.Equals( installed_singers[i].VOICEIDSTR ) ) {
- return installed_singers[i].VOICENAME;
- }
+ }
+
+ public static String getDllPathVsti( SynthesizerType type ) {
+ if ( !s_path_vsti.containsKey( type ) ) {
+ return "";
+ } else {
+ return s_path_vsti.get( type );
}
- return "";
}
- public static VsqID getSingerID1( String singer ) {
- return s_singer_config_sys1.getSingerID( singer );
- }
-
- public static VsqID getSingerID2( String singer ) {
- return s_singer_config_sys2.getSingerID( singer );
- }
-
- public static String getEditorPath1() {
- return s_path_editor1;
- }
-
- public static String getEditorPath2() {
- return s_path_editor2;
- }
-
- public static String getDllPathVsti1() {
- return s_path_vsti1;
- }
-
- public static String getDllPathVsti2() {
- return s_path_vsti2;
- }
-
- public static SingerConfig[] getSingerConfigs1() {
- return s_singer_config_sys1.getSingerConfigs();
- }
-
- public static SingerConfig[] getSingerConfigs2() {
- return s_singer_config_sys2.getSingerConfigs();
+ public static SingerConfig[] getSingerConfigs( SynthesizerType type ) {
+ if ( !s_singer_config_sys.containsKey( type ) ) {
+ return new SingerConfig[] { };
+ } else {
+ return s_singer_config_sys.get( type ).getSingerConfigs();
+ }
}
///
@@ -327,25 +405,25 @@ namespace Boare.Lib.Vsq {
/// name of singer
///
public static VsqVoiceLanguage getLanguageFromName( String name ) {
- switch ( name.ToLower() ) {
- case "meiko":
- case "kaito":
- case "miku":
- case "rin":
- case "len":
- case "rin_act2":
- case "len_act2":
- case "gackpoid":
- case "luka_jpn":
- case "megpoid":
- return VsqVoiceLanguage.Japanese;
- case "sweet_ann":
- case "prima":
- case "luka_eng":
- case "sonika":
- return VsqVoiceLanguage.English;
+ String search = name.ToLower();
+ if ( search.Equals( "meiko" ) ||
+ search.Equals( "kaito" ) ||
+ search.Equals( "miku" ) ||
+ search.Equals( "rin" ) ||
+ search.Equals( "len" ) ||
+ search.Equals( "rin_act2" ) ||
+ search.Equals( "len_act2" ) ||
+ search.Equals( "gackpoid" ) ||
+ search.Equals( "luka_jpn" ) ||
+ search.Equals( "megpoid" ) ) {
+ return VsqVoiceLanguage.Japanese;
+ } else if ( search.Equals( "sweet_ann" ) ||
+ search.Equals( "prima" ) ||
+ search.Equals( "luka_eng" ) ||
+ search.Equals( "sonika" ) ) {
+ return VsqVoiceLanguage.English;
}
- return VsqVoiceLanguage.Default;
+ return VsqVoiceLanguage.Japanese;
}
public static double getAmplifyCoeffFromPanLeft( int pan ) {
@@ -365,462 +443,11 @@ namespace Boare.Lib.Vsq {
///
///
///
- public static ulong makelong_le( byte[] oct ) {
- return (ulong)oct[7] << 56 | (ulong)oct[6] << 48 | (ulong)oct[5] << 40 | (ulong)oct[4] << 32 | (ulong)oct[3] << 24 | (ulong)oct[2] << 16 | (ulong)oct[1] << 8 | (ulong)oct[0];
- }
- }
-
- public static class VocaloSysUtil_ {
- private static boolean s_initialized = false;
-
- private static String s_dll_path2 = "";
- private static String s_editor_path2 = "";
- private static String s_voicedbdir2 = "";
- private static Vector s_installed_singers2 = new Vector();
- private static Vector s_singer_configs2 = new Vector();
-
- private static String s_dll_path1 = "";
- private static String s_editor_path1 = "";
- private static String s_voicedbdir1 = "";
- private static Vector s_installed_singers1 = new Vector();
- private static Vector s_singer_configs1 = new Vector();
-
- private const int MAX_SINGERS = 0x4000;
-
- static VocaloSysUtil_() {
- init_vocalo2();
- init_vocalo1();
- }
-
- ///
- /// Gets the name of original singer of specified program change.
- ///
- ///
- ///
- public static String getOriginalSinger1( String singer ) {
- String voiceidstr = "";
- for ( int i = 0; i < s_singer_configs1.size(); i++ ) {
- if ( singer.Equals( s_singer_configs1.get( i ).VOICENAME ) ) {
- voiceidstr = s_singer_configs1.get( i ).VOICEIDSTR;
- }
- }
- if ( voiceidstr.Equals( "" ) ) {
- return "";
- }
- for ( int i = 0; i < s_installed_singers1.size(); i++ ) {
- if ( voiceidstr.Equals( s_installed_singers1.get( i ).VOICEIDSTR ) ) {
- return s_installed_singers1.get( i ).VOICENAME;
- }
- }
- return "";
- }
-
- ///
- /// Gets the name of original singer of specified program change.
- ///
- ///
- ///
- public static String getOriginalSinger2( String singer ) {
- String voiceidstr = "";
- for ( int i = 0; i < s_singer_configs2.size(); i++ ) {
- if ( singer.Equals( s_singer_configs2.get( i ).VOICENAME ) ) {
- voiceidstr = s_singer_configs2.get( i ).VOICEIDSTR;
- }
- }
- if ( voiceidstr.Equals( "" ) ) {
- return "";
- }
- for ( int i = 0; i < s_installed_singers2.size(); i++ ) {
- if ( voiceidstr.Equals( s_installed_singers2.get( i ).VOICEIDSTR ) ) {
- return s_installed_singers2.get( i ).VOICENAME;
- }
- }
- return "";
- }
-
- ///
- /// Gets the voice language of specified program change
- ///
- /// name of singer
- ///
- public static VsqVoiceLanguage getLanguageFromName( String name ) {
- switch ( name ) {
- case "MEIKO":
- case "KAITO":
- case "Miku":
- case "Rin":
- case "Len":
- case "Rin_ACT2":
- case "Len_ACT2":
- case "Gackpoid":
- case "Luka_JPN":
- case "Megpoid":
- return VsqVoiceLanguage.Japanese;
- case "Sweet_Ann":
- case "Prima":
- case "Luka_ENG":
- return VsqVoiceLanguage.English;
- }
- return VsqVoiceLanguage.Default;
- }
-
- public static VsqID getSingerID1( String singer_name ) {
- VsqID ret = new VsqID( 0 );
- ret.type = VsqIDType.Singer;
- SingerConfig sc = null;
- for ( int i = 0; i < s_singer_configs1.size(); i++ ) {
- if ( s_singer_configs1.get( i ).VOICENAME.Equals( singer_name ) ) {
- sc = s_singer_configs1.get( i );
- break;
- }
- }
- if ( sc == null ) {
- sc = new SingerConfig();
- }
- int lang = 0;
- for ( Iterator itr = s_installed_singers1.iterator(); itr.hasNext(); ){
- SingerConfig sc2 = (SingerConfig)itr.next();
- if ( sc.VOICEIDSTR.Equals( sc2.VOICEIDSTR ) ) {
- lang = (int)getLanguageFromName( sc.VOICENAME );
- break;
- }
- }
- ret.IconHandle = new IconHandle();
- ret.IconHandle.IconID = "$0701" + sc.Program.ToString( "0000" );
- ret.IconHandle.IDS = sc.VOICENAME;
- ret.IconHandle.Index = 0;
- ret.IconHandle.Language = lang;
- ret.IconHandle.Length = 1;
- ret.IconHandle.Original = sc.Original;
- ret.IconHandle.Program = sc.Program;
- ret.IconHandle.Caption = "";
- return ret;
- }
-
- public static VsqID getSingerID2( String singer_name ) {
- VsqID ret = new VsqID( 0 );
- ret.type = VsqIDType.Singer;
- SingerConfig sc = null;
- for ( int i = 0; i < s_singer_configs2.size(); i++ ) {
- if ( s_singer_configs2.get( i ).VOICENAME.Equals( singer_name ) ) {
- sc = s_singer_configs2.get( i );
- break;
- }
- }
- if ( sc == null ) {
- sc = new SingerConfig();
- }
- int lang = 0;
- for ( Iterator itr = s_installed_singers2.iterator(); itr.hasNext(); ){
- SingerConfig sc2 = (SingerConfig)itr.next();
- if ( sc.VOICEIDSTR.Equals( sc2.VOICEIDSTR ) ) {
- lang = (int)getLanguageFromName( sc.VOICENAME );
- break;
- }
- }
- ret.IconHandle = new IconHandle();
- ret.IconHandle.IconID = "$0701" + sc.Program.ToString( "0000" );
- ret.IconHandle.IDS = sc.VOICENAME;
- ret.IconHandle.Index = 0;
- ret.IconHandle.Language = lang;
- ret.IconHandle.Length = 1;
- ret.IconHandle.Original = sc.Original;
- ret.IconHandle.Program = sc.Program;
- ret.IconHandle.Caption = "";
- return ret;
- }
-
- public static SingerConfig[] getSingerConfigs1() {
- return s_singer_configs1.toArray( new SingerConfig[]{} );
- }
-
- public static SingerConfig[] getSingerConfigs2() {
- return s_singer_configs2.toArray( new SingerConfig[]{} );
- }
-
- public static double getAmplifyCoeffFromPanLeft( int pan ) {
- return pan / -64.0 + 1.0;
- }
-
- public static double getAmplifyCoeffFromPanRight( int pan ) {
- return pan / 64.0 + 1.0;
- }
-
- public static double getAmplifyCoeffFromFeder( int feder ) {
- return Math.Exp( -1.26697245e-02 + 1.18448420e-01 * feder / 10.0 );
- }
-
- public static String getEditorPath2() {
- return s_editor_path2;
- }
-
- public static String getEditorPath1() {
- return s_editor_path1;
- }
-
- public static String getDllPathVsti2() {
- return s_dll_path2;
- }
-
- public static String getDllPathVsti1() {
- return s_dll_path1;
- }
-
- ///
- /// VOCALOID1システムのプロパティを取得
- ///
- private static void init_vocalo1() {
- // vocaloid1 dll path
- RegistryKey v1application = null;
- v1application = Registry.LocalMachine.OpenSubKey( "SOFTWARE\\VOCALOID\\APPLICATION", false );
- if ( v1application != null ) {
- String[] keys = v1application.GetSubKeyNames();
- for ( int i = 0; i < keys.Length; i++ ) {
- RegistryKey key = v1application.OpenSubKey( keys[i], false );
- if ( key != null ) {
- String name = (String)key.GetValue( "PATH" );
- if ( name.ToLower().EndsWith( "\\vocaloid.dll" ) ) {
- s_dll_path1 = name;
- } else if ( name.ToLower().EndsWith( "\\vocaloid.exe" ) ) {
- s_editor_path1 = name;
- }
- key.Close();
- }
- }
- v1application.Close();
- }
-
- // voicedbdir for vocaloid1
- RegistryKey v1database = Registry.LocalMachine.OpenSubKey( "SOFTWARE\\VOCALOID\\DATABASE\\VOICE", false );
- if ( v1database != null ) {
- s_voicedbdir1 = (String)v1database.GetValue( "VOICEDIR", "" );
-#if DEBUG
- Console.WriteLine( "s_voicedbdir1=" + s_voicedbdir1 );
-#endif
- // インストールされている歌手のVOICEIDSTRを列挙
- String[] singer_voiceidstrs = v1database.GetSubKeyNames();
- Vector vvoice_keys = new Vector();
- Vector vvoice_values = new Vector();
- foreach ( String voiceidstr in singer_voiceidstrs ) {
- RegistryKey singer = v1database.OpenSubKey( voiceidstr );
- if ( singer == null ) {
- continue;
- }
- RegistryKey vvoice = singer.OpenSubKey( "vvoice" );
- if ( vvoice != null ) {
- String[] vvoices = vvoice.GetValueNames();
-
- // インストールされた歌手の.vvdを読みにいく
- // installdir以下の、拡張子.vvdのファイルを探す
- foreach ( String file in Directory.GetFiles( Path.Combine( s_voicedbdir1, voiceidstr ), "*.vvd" ) ) {
- SingerConfig config = SingerConfig.fromVvd( file, 0 ); //とりあえずプログラムチェンジは0
- s_installed_singers1.add( config );
- }
-
- // vvoice*.vvdを読みにいく。
- foreach ( String s in vvoices ) {
-#if DEBUG
- Console.WriteLine( "s=" + s );
-#endif
- String file = Path.Combine( s_voicedbdir1, s + ".vvd" );
- if ( File.Exists( file ) ) {
- SingerConfig config = SingerConfig.fromVvd( file, 0 );
- vvoice_keys.add( s );
- vvoice_values.add( config );
- }
- }
- }
- singer.Close();
- }
-
- // voice.mapを読み込んで、s_singer_configs1のプログラムチェンジを更新する
- String map = Path.Combine( s_voicedbdir1, "voice.map" );
- if ( File.Exists( map ) ) {
- using ( FileStream fs = new FileStream( map, FileMode.Open, FileAccess.Read ) ) {
- byte[] dat = new byte[8];
- fs.Seek( 0x20, SeekOrigin.Begin );
- for ( int i = 0; i < MAX_SINGERS; i++ ) {
- fs.Read( dat, 0, 8 );
- ulong value = makelong_le( dat );
- if ( value >= 1 ) {
-#if DEBUG
- Console.WriteLine( "value=" + value );
-#endif
- for ( int j = 0; j < vvoice_keys.size(); j++ ) {
- if ( vvoice_keys.get( j ).Equals( "vvoice" + value ) ) {
- vvoice_values.get( j ).Program = i;
- }
- }
- }
- }
- }
- }
-
- // s_installed_singers1のSingerConfigのProgramとOriginalを適当に頒番する
- for ( int i = 0; i < s_installed_singers1.size(); i++ ) {
- s_installed_singers1.get( i ).Program = i;
- s_installed_singers1.get( i ).Original = i;
- }
-
- // s_singer_configs1を更新
- for ( int i = 0; i < vvoice_values.size(); i++ ) {
- for ( int j = 0; j < s_installed_singers1.size(); j++ ) {
- if ( vvoice_values.get( i ).VOICEIDSTR.Equals( s_installed_singers1.get( j ).VOICEIDSTR ) ) {
- vvoice_values.get( i ).Original = s_installed_singers1.get( j ).Program;
- break;
- }
- }
- s_singer_configs1.add( vvoice_values.get( i ) );
- }
- v1database.Close();
- }
-#if DEBUG
- Console.WriteLine( "installed" );
- for ( Iterator itr = s_installed_singers1.iterator(); itr.hasNext(); ){
- SingerConfig sc = (SingerConfig)itr.next();
- Console.WriteLine( "VOICENAME=" + sc.VOICENAME + "; VOICEIDSTR=" + sc.VOICEIDSTR + "; Program=" + sc.Program + "; Original=" + sc.Original );
- }
- Console.WriteLine( "singer configs" );
- for ( Iterator itr = s_singer_configs1.iterator(); itr.hasNext(); ){
- SingerConfig sc = (SingerConfig)itr.next();
- Console.WriteLine( "VOICENAME=" + sc.VOICENAME + "; VOICEIDSTR=" + sc.VOICEIDSTR + "; Program=" + sc.Program + "; Original=" + sc.Original );
- }
-#endif
- }
-
- ///
- /// VOCALOID2システムのプロパティを取得
- ///
- private static void init_vocalo2() {
- // 最初はvstiとeditorのパスを取得
- RegistryKey v2application = Registry.LocalMachine.OpenSubKey( "SOFTWARE\\VOCALOID2\\APPLICATION", false );
- if ( v2application == null ) {
- v2application = Registry.LocalMachine.OpenSubKey( "SOFTWARE\\VOCALOID2_DEMO\\APPLICATION", false );
- }
- if ( v2application != null ) {
- String[] keys = v2application.GetSubKeyNames();
- for ( int i = 0; i < keys.Length; i++ ) {
- RegistryKey key = v2application.OpenSubKey( keys[i], false );
- if ( key != null ) {
- String name = (String)key.GetValue( "PATH" );
- if ( name.ToLower().EndsWith( "\\vocaloid2.dll" ) ) {
- s_dll_path2 = name;
- } else if ( name.ToLower().EndsWith( "\\vocaloid2_demo.dll" ) ) {
- s_dll_path2 = name;
- } else if ( name.ToLower().EndsWith( "\\vocaloid2.exe" ) ) {
- s_editor_path2 = name;
- }
- key.Close();
- }
- }
- v2application.Close();
- }
-
- // 歌声データベースを取得
- RegistryKey v2database = Registry.LocalMachine.OpenSubKey( "SOFTWARE\\VOCALOID2\\DATABASE\\VOICE", false );
- if ( v2database != null ) {
- // データベース(というよりもvoice.map)が保存されているパスを取得
- s_voicedbdir2 = (String)v2database.GetValue( "VOICEDIR", "" );
- // インストールされている歌手のVOICEIDSTRを列挙
- String[] singer_voiceidstrs = v2database.GetSubKeyNames();
- Vector vvoice_keys = new Vector();
- Vector vvoice_values = new Vector();
- foreach ( String voiceidstr in singer_voiceidstrs ) {
- RegistryKey singer = v2database.OpenSubKey( voiceidstr );
- if ( singer == null ) {
- continue;
- }
- String installdir = (String)singer.GetValue( "INSTALLDIR", "" );
-#if DEBUG
- Console.WriteLine( "installdir=" + installdir );
-#endif
- RegistryKey vvoice = singer.OpenSubKey( "vvoice" );
- if ( vvoice != null ) {
- String[] vvoices = vvoice.GetValueNames();
-
- // インストールされた歌手の.vvdを読みにいく
- // installdir以下の、拡張子.vvdのファイルを探す
- foreach ( String file in Directory.GetFiles( Path.Combine( installdir, voiceidstr ), "*.vvd" ) ) {
- SingerConfig config = SingerConfig.fromVvd( file, 0 ); //とりあえずプログラムチェンジは0
- s_installed_singers2.add( config );
- }
-
- // vvoice*.vvdを読みにいく。場所は、installdirではなく、s_voicedbdir2
- foreach ( String s in vvoices ) {
- String file = Path.Combine( s_voicedbdir2, s + ".vvd" );
- if ( File.Exists( file ) ) {
- SingerConfig config = SingerConfig.fromVvd( file, 0 );
- vvoice_keys.add( s );
- vvoice_values.add( config );
- }
- }
- }
- singer.Close();
- }
-
- // voice.mapを読み込んで、s_singer_configs2のプログラムチェンジを更新する
- String map = Path.Combine( s_voicedbdir2, "voice.map" );
- if ( File.Exists( map ) ) {
- using ( FileStream fs = new FileStream( map, FileMode.Open, FileAccess.Read ) ) {
- byte[] dat = new byte[8];
- fs.Seek( 0x20, SeekOrigin.Begin );
- for ( int i = 0; i < MAX_SINGERS; i++ ) {
- fs.Read( dat, 0, 8 );
- ulong value = makelong_le( dat );
- if ( value >= 1 ) {
-#if DEBUG
- Console.WriteLine( "value=" + value );
-#endif
- for ( int j = 0; j < vvoice_keys.size(); j++ ) {
- if ( vvoice_keys.get( j ).Equals( "vvoice" + value ) ) {
- vvoice_values.get( j ).Program = i;
- }
- }
- }
- }
- }
- }
-
- // s_installed_singers2のSingerConfigのProgramとOriginalを適当に頒番する
- for ( int i = 0; i < s_installed_singers2.size(); i++ ) {
- s_installed_singers2.get( i ).Program = i;
- s_installed_singers2.get( i ).Original = i;
- }
-
- // s_singer_configs2を更新
- for ( int i = 0; i < vvoice_values.size(); i++ ) {
- for ( int j = 0; j < s_installed_singers2.size(); j++ ) {
- if ( vvoice_values.get( i ).VOICEIDSTR.Equals( s_installed_singers2.get( j ).VOICEIDSTR ) ) {
- vvoice_values.get( i ).Original = s_installed_singers2.get( j ).Program;
- break;
- }
- }
- s_singer_configs2.add( vvoice_values.get( i ) );
- }
- v2database.Close();
- }
-#if DEBUG
- Console.WriteLine( "installed" );
- for ( Iterator itr = s_installed_singers2.iterator(); itr.hasNext(); ){
- SingerConfig sc = (SingerConfig)itr.next();
- Console.WriteLine( "VOICENAME=" + sc.VOICENAME + "; VOICEIDSTR=" + sc.VOICEIDSTR + "; Program=" + sc.Program + "; Original=" + sc.Original );
- }
- Console.WriteLine( "singer configs" );
- for ( Iterator itr = s_singer_configs2.iterator(); itr.hasNext(); ){
- SingerConfig sc = (SingerConfig)itr.next();
- Console.WriteLine( "VOICENAME=" + sc.VOICENAME + "; VOICEIDSTR=" + sc.VOICEIDSTR + "; Program=" + sc.Program + "; Original=" + sc.Original );
- }
-#endif
- }
-
- ///
- /// Transform the byte array(length=8) to unsigned long, assuming that the byte array is little endian.
- ///
- ///
- ///
- public static ulong makelong_le( byte[] oct ) {
- return (ulong)oct[7] << 56 | (ulong)oct[6] << 48 | (ulong)oct[5] << 40 | (ulong)oct[4] << 32 | (ulong)oct[3] << 24 | (ulong)oct[2] << 16 | (ulong)oct[1] << 8 | (ulong)oct[0];
+ public static long makelong_le( byte[] oct ) {
+ return (long)oct[7] << 56 | (long)oct[6] << 48 | (long)oct[5] << 40 | (long)oct[4] << 32 | (long)oct[3] << 24 | (long)oct[2] << 16 | (long)oct[1] << 8 | (long)oct[0];
}
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/VsqBPList.cs b/trunk/Boare.Lib.Vsq/VsqBPList.cs
index 3a85226..9d066da 100644
--- a/trunk/Boare.Lib.Vsq/VsqBPList.cs
+++ b/trunk/Boare.Lib.Vsq/VsqBPList.cs
@@ -11,65 +11,89 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.IO;
+#if JAVA
+package org.kbinani.vsq;
+import java.util.*;
+import java.io.*;
+import org.kbinani.*;
+#else
+using System;
using bocoree;
+using bocoree.java.io;
+using bocoree.java.util;
namespace Boare.Lib.Vsq {
-
using boolean = System.Boolean;
+ using Integer = System.Int32;
+#endif
- ///
- /// BPListのデータ部分を取り扱うためのクラス。
- ///
+#if JAVA
+ public class VsqBPList implements Cloneable, Serializable{
+#else
[Serializable]
public class VsqBPList : ICloneable {
- private SortedList m_list = new SortedList();
+#endif
+ private Vector m_clock = new Vector();
+ private Vector m_items = new Vector();
private int m_default = 0;
private int m_maximum = 127;
private int m_minimum = 0;
- ///
- /// このリストに設定されたidの最大値.次にデータ点が追加されたときは,個の値+1がidとして利用される.削除された場合でも減らない
- ///
- private int m_max_id = 0;
+ private long m_max_id = 0;
- private class KeyClockIterator : Iterator {
- private SortedList m_list;
+ class KeyClockIterator : Iterator {
+ private VsqBPList m_list;
private int m_pos;
- public KeyClockIterator( SortedList list ) {
+ public KeyClockIterator( VsqBPList list ) {
m_list = list;
m_pos = -1;
}
public boolean hasNext() {
- if ( m_pos + 1 < m_list.Keys.Count ) {
+ if ( m_pos + 1 < m_list.m_clock.size() ) {
return true;
} else {
return false;
}
}
- public object next() {
+ public Object next() {
m_pos++;
- return m_list.Keys[m_pos];
+ return m_list.m_clock.get( m_pos );
}
public void remove() {
- if ( 0 <= m_pos && m_pos < m_list.Keys.Count ) {
- int key = m_list.Keys[m_pos];
- m_list.Remove( key );
+ if ( 0 <= m_pos && m_pos < m_list.m_clock.size() ) {
+ int key = m_list.m_clock.get( m_pos );
+ m_list.m_clock.removeElementAt( m_pos );
+ m_list.m_items.removeElementAt( m_pos );
}
}
}
- public VsqBPList()
- : this( 0, 0, 64 ) {
+
+ ///
+ /// コンストラクタ。デフォルト値はココで指定する。
+ ///
+ ///
+ public VsqBPList( int default_value, int minimum, int maximum ) {
+ m_default = default_value;
+ m_maximum = maximum;
+ m_minimum = minimum;
+ m_max_id = 0;
}
+#if JAVA
+ public VsqBPList(){
+ this( 0, 0, 64 );
+#else
+ public VsqBPList()
+ : this( 0, 0, 64 ) {
+#endif
+ }
+
+#if !JAVA
public int Default {
get {
return getDefault();
@@ -78,6 +102,11 @@ namespace Boare.Lib.Vsq {
setDefault( value );
}
}
+#endif
+
+ public long getMaxID() {
+ return m_max_id;
+ }
///
/// このBPListのデフォルト値を取得します
@@ -96,44 +125,60 @@ namespace Boare.Lib.Vsq {
///
public void renumberIDs() {
m_max_id = 0;
- for ( Iterator itr = keyClockIterator(); itr.hasNext(); ) {
- VsqBPPair item = (VsqBPPair)itr.next();
+ int count = m_items.size();
+ for ( int i = 0; i < count; i++ ) {
m_max_id++;
- item.id = m_max_id;
+ VsqBPPair v = m_items.get( i );
+ v.id = m_max_id;
+ m_items.set( i, v );
}
}
+#if !JAVA
///
/// XMLシリアライズ用
///
public String Data {
get {
- String ret = "";
- int count = -1;
- foreach ( int key in m_list.Keys ) {
- count++;
- ret += (count == 0 ? "" : "," ) + key + "=" + m_list[key].value;
- }
- return ret;
+ return getData();
}
set {
- m_list.Clear();
- m_max_id = 0;
- String[] spl = value.Split( ',' );
- for ( int i = 0; i < spl.Length; i++ ) {
- String[] spl2 = spl[i].Split( '=' );
- if ( spl2.Length < 2 ) {
- continue;
- }
- try {
- m_list.Add( int.Parse( spl2[0] ), new VsqBPPair( int.Parse( spl2[1] ), m_max_id + 1 ) );
- m_max_id++;
- } catch ( Exception ex ) {
-#if DEBUG
- Console.WriteLine( " ex=" + ex );
- Console.WriteLine( " i=" + i + "; spl2[0]=" + spl2[0] + "; spl2[1]=" + spl2[1] );
+ setData( value );
+ }
+ }
+#endif
+
+ public String getData() {
+ String ret = "";
+ int count = -1;
+ int size = m_clock.size();
+ for ( int i = 0; i < size; i++ ) {
+ count++;
+ ret += (count == 0 ? "" : ",") + m_clock.get( i ) + "=" + m_items.get( i ).value;
+ }
+ return ret;
+ }
+
+ public void setData( String value ) {
+ m_clock.clear();
+ m_items.clear();
+ m_max_id = 0;
+ String[] spl = PortUtil.splitString( value, ',' );
+ for ( int i = 0; i < spl.Length; i++ ) {
+ String[] spl2 = PortUtil.splitString( spl[i], '=' );
+ if ( spl2.Length < 2 ) {
+ continue;
+ }
+ try {
+ int clock = PortUtil.parseInt( spl2[0] );
+ m_clock.add( clock );
+ m_items.add( new VsqBPPair( PortUtil.parseInt( spl2[1] ), m_max_id + 1 ) );
+ m_max_id++;
+ } catch ( Exception ex ) {
+#if DEBUG
+ PortUtil.println( " ex=" + ex );
+ PortUtil.println( " i=" + i + "; spl2[0]=" + spl2[0] + "; spl2[1]=" + spl2[1] );
#endif
- }
}
}
}
@@ -143,29 +188,27 @@ namespace Boare.Lib.Vsq {
///
///
public Object clone() {
- VsqBPList res = new VsqBPList( getDefault(), getMinimum(), getMaximum() );
- foreach ( int key in m_list.Keys ) {
- res.m_list.Add( key, m_list[key] );
+ VsqBPList res = new VsqBPList( m_default, m_minimum, m_maximum );
+ int count = m_clock.size();
+ for ( int i = 0; i < count; i++ ) {
+ res.m_clock.add( m_clock.get( i ) );
+#if JAVA
+ res.m_items.add( (VsqBPPair)m_items.get( i ).clone() );
+#else
+ res.m_items.add( m_items.get( i ) );
+#endif
}
res.m_max_id = m_max_id;
return res;
}
+#if !JAVA
public object Clone() {
return clone();
}
+#endif
- ///
- /// コンストラクタ。デフォルト値はココで指定する。
- ///
- ///
- public VsqBPList( int default_value, int minimum, int maximum ) {
- m_default = default_value;
- m_maximum = maximum;
- m_minimum = minimum;
- m_max_id = 0;
- }
-
+#if !JAVA
public int Maximum {
get {
return getMaximum();
@@ -174,6 +217,7 @@ namespace Boare.Lib.Vsq {
setMaximum( value );
}
}
+#endif
///
/// このリストに設定された最大値を取得します。
@@ -182,10 +226,11 @@ namespace Boare.Lib.Vsq {
return m_maximum;
}
- public void setMaximum( int value ){
+ public void setMaximum( int value ) {
m_maximum = value;
}
+#if !JAVA
public int Minimum {
get {
return getMinimum();
@@ -194,6 +239,7 @@ namespace Boare.Lib.Vsq {
setMinimum( value );
}
}
+#endif
///
/// このリストに設定された最小値を取得します
@@ -206,31 +252,29 @@ namespace Boare.Lib.Vsq {
m_minimum = value;
}
- public Iterator keyClockIterator() {
- return new KeyClockIterator( m_list );
+ public void remove( int clock ) {
+ int index = m_clock.indexOf( clock );
+ removeElementAt( index );
}
- public void remove( int clock ) {
- if ( m_list.ContainsKey( clock ) ) {
- m_list.Remove( clock );
+ public void removeElementAt( int index ) {
+ if ( index >= 0 ) {
+ m_clock.removeElementAt( index );
+ m_items.removeElementAt( index );
}
}
public boolean isContainsKey( int clock ) {
- return m_list.ContainsKey( clock );
+ return m_clock.contains( clock );
}
- public int size() {
- return m_list.Count;
- }
-
- public int[] getKeys() {
- Vector t = new Vector();
+ /* public int[] getKeys() {
+ Vector t = new Vector();
foreach( int key in m_list.Keys ){
t.add( key );
}
- return t.toArray( new Int32[]{} );
- }
+ return t.toArray( new Integer[]{} );
+ }*/
///
/// 時刻clockのデータを時刻new_clockに移動します。
@@ -240,46 +284,30 @@ namespace Boare.Lib.Vsq {
///
///
public void move( int clock, int new_clock, int new_value ) {
- if ( !m_list.ContainsKey( clock ) ) {
+ int index = m_clock.indexOf( clock );
+ if ( index < 0 ) {
return;
}
- VsqBPPair item = m_list[clock];
- m_list.Remove( clock );
- if ( m_list.ContainsKey( new_clock ) ) {
- m_list.Remove( new_clock );
+ VsqBPPair item = m_items.get( index );
+ m_clock.removeElementAt( index );
+ m_items.removeElementAt( index );
+ int index_new = m_clock.indexOf( new_clock );
+ if ( index_new >= 0 ) {
+ item.value = new_value;
+ m_items.set( index_new, item );
+ return;
+ } else {
+ m_clock.add( new_clock );
+ Collections.sort( m_clock );
+ index_new = m_clock.indexOf( new_clock );
+ item.value = new_value;
+ m_items.insertElementAt( item, index_new );
}
- item.value = new_value;
- m_list.Add( new_clock, item );
}
public void clear() {
- m_list.Clear();
- }
-
- ///
- /// 新しいデータ点を追加します。
- /// 戻り値に、新しいデータ点のIDを返します
- ///
- ///
- ///
- ///
- public long add( int clock, int value ) {
- lock ( m_list ) {
- if ( m_list.ContainsKey( clock ) ) {
- VsqBPPair v = m_list[clock];
- v.value = value;
- m_list[clock] = v;
- return v.id;
- } else {
- VsqBPPair v = new VsqBPPair( value, m_max_id + 1 );
- m_max_id++;
-#if DEBUG
- //Console.WriteLine( "VsqBPList#add; m_max_id=" + m_max_id );
-#endif
- m_list.Add( clock, v );
- return m_max_id;
- }
- }
+ m_clock.clear();
+ m_items.clear();
}
public int getElement( int index ) {
@@ -287,22 +315,23 @@ namespace Boare.Lib.Vsq {
}
public int getElementA( int index ) {
- return m_list[m_list.Keys[index]].value;
+ return m_items.get( index ).value;
}
public VsqBPPair getElementB( int index ) {
- return m_list[m_list.Keys[index]];
+ return m_items.get( index );
}
public int getKeyClock( int index ) {
- return m_list.Keys[index];
+ return m_clock.get( index );
}
public int findValueFromID( long id ) {
- int c = m_list.Keys.Count;
- foreach ( int key in m_list.Keys ) {
- if ( m_list[key].id == id ) {
- return m_list[key].value;
+ int c = m_items.size();
+ for ( int i = 0; i < c; i++ ) {
+ VsqBPPair item = m_items.get( i );
+ if ( item.id == id ) {
+ return item.value;
}
}
return m_default;
@@ -315,12 +344,11 @@ namespace Boare.Lib.Vsq {
///
public VsqBPPairSearchContext findElement( long id ) {
VsqBPPairSearchContext context = new VsqBPPairSearchContext();
- int c = m_list.Keys.Count;
+ int c = m_items.size();
for ( int i = 0; i < c; i++ ) {
- int clock = m_list.Keys[i];
- VsqBPPair item = m_list[clock];
+ VsqBPPair item = m_items.get( i );
if ( item.id == id ) {
- context.clock = clock;
+ context.clock = m_clock.get( i );
context.index = i;
context.point = item;
return context;
@@ -333,94 +361,82 @@ namespace Boare.Lib.Vsq {
}
public void setValueForID( long id, int value ) {
- int c = m_list.Keys.Count;
- foreach ( int key in m_list.Keys ) {
- if ( m_list[key].id == id ) {
- VsqBPPair v = m_list[key];
- v.value = value;
- m_list[key] = v;
+ int c = m_items.size();
+ for ( int i = 0; i < c; i++ ) {
+ VsqBPPair item = m_items.get( i );
+ if ( item.id == id ) {
+ item.value = value;
+ m_items.set( i, item );
break;
}
}
}
- public int getValue( int clock, ref int index ) {
- if ( m_list.Count == 0 ) {
+ public int getValue( int clock, ByRef index ) {
+ int count = m_clock.size();
+ if ( count == 0 ) {
return m_default;
} else {
- if ( index < 0 ) {
- index = 0;
+ if ( index.value < 0 ) {
+ index.value = 0;
}
- for ( int i = index ; i < m_list.Keys.Count; i++ ) {
- int keyclock = m_list.Keys[i];
+ for ( int i = index.value; i < count; i++ ) {
+ int keyclock = m_clock.get( i );
if ( clock < keyclock ) {
if ( i > 0 ) {
- index = i;
- return m_list[m_list.Keys[i - 1]].value;
+ index.value = i;
+ return m_items.get( i - 1 ).value;
} else {
- index = i;
+ index.value = i;
return m_default;
}
}
}
- index = m_list.Keys.Count - 1;
- return m_list[m_list.Keys[m_list.Keys.Count - 1]].value;
+ index.value = count - 1;
+ return m_items.get( count - 1 ).value;
}
}
- public int getValue( int clock ) {
- if ( m_list.Count == 0 ) {
- return m_default;
- } else {
- for ( int i = 0; i < m_list.Keys.Count; i++ ) {
- int keyclock = m_list.Keys[i];
- if ( clock < keyclock ) {
- if ( i > 0 ) {
- return m_list[m_list.Keys[i - 1]].value;
- } else {
- return m_default;
- }
- }
- }
- return m_list[m_list.Keys[m_list.Keys.Count - 1]].value;
- }
- }
-
- ///
- /// このBPListの内容をテキストファイルに書き出します
- ///
- ///
- public void print( StreamWriter writer ) {
- boolean first = true;
- foreach ( int key in m_list.Keys ) {
- int val = m_list[key].value;
- if ( first ) {
- writer.WriteLine( key + "=" + val );
- first = false;
- } else {
- writer.WriteLine( key + "=" + val );
- }
- }
- }
-
- ///
- /// このBPListの内容をテキストファイルに書き出します
- ///
- ///
- public void print( TextMemoryStream writer, int start, String header ) {
- boolean first = true;
- foreach ( int key in m_list.Keys ) {
- if ( start <= key ) {
- if ( first ) {
- writer.writeLine( header );
- first = false;
- }
- int val = m_list[key].value;
+ private void printCor( ITextWriter writer, int start_clock, String header )
+#if JAVA
+ throws IOException
+#endif
+ {
+ writer.writeLine( header );
+ int c = m_clock.size();
+ for ( int i = 0; i < c; i++ ) {
+ int key = m_clock.get( i );
+ if ( start_clock <= key ) {
+ int val = m_items.get( i ).value;
writer.writeLine( key + "=" + val );
}
}
}
+ ///
+ /// このBPListの内容をテキストファイルに書き出します
+ ///
+ ///
+ public void print( BufferedWriter writer, int start, String header )
+#if JAVA
+ throws IOException
+#endif
+ {
+ printCor( new WrappedStreamWriter( writer ), start, header );
+ }
+
+ ///
+ /// このBPListの内容をテキストファイルに書き出します
+ ///
+ ///
+ public void print( TextMemoryStream writer, int start, String header )
+#if JAVA
+ throws IOException
+#endif
+ {
+ printCor( writer, start, header );
+ }
+
///
/// テキストファイルからデータ点を読込み、現在のリストに追加します
///
@@ -429,12 +445,10 @@ namespace Boare.Lib.Vsq {
public String appendFromText( TextMemoryStream reader ) {
String last_line = reader.readLine();
while ( !last_line.StartsWith( "[" ) ) {
- String[] spl = last_line.Split( new char[] { '=' } );
- int i1 = int.Parse( spl[0] );
- int i2 = int.Parse( spl[1] );
- VsqBPPair v = new VsqBPPair( i2, m_max_id + 1 );
- m_max_id++;
- m_list.Add( i1, v );
+ String[] spl = PortUtil.splitString( last_line, new char[] { '=' } );
+ int clock = PortUtil.parseInt( spl[0] );
+ int value = PortUtil.parseInt( spl[1] );
+ this.add( clock, value );
if ( reader.peek() < 0 ) {
break;
} else {
@@ -443,6 +457,86 @@ namespace Boare.Lib.Vsq {
}
return last_line;
}
+
+ public int size() {
+ return m_clock.size();
+ }
+
+ public Iterator keyClockIterator() {
+ return new KeyClockIterator( this );
+ }
+
+ public long add( int clock, int value ) {
+ int index = m_clock.indexOf( clock );
+ if ( index >= 0 ) {
+ VsqBPPair v = m_items.get( index );
+ v.value = value;
+ m_items.set( index, v );
+ return v.id;
+ } else {
+ m_clock.add( clock );
+ Collections.sort( m_clock );
+ index = m_clock.indexOf( clock );
+ m_max_id++;
+ m_items.insertElementAt( new VsqBPPair( value, m_max_id ), index );
+ return m_max_id;
+ }
+ }
+
+ public void addWithID( int clock, int value, long id ) {
+ int index = m_clock.indexOf( clock );
+ if ( index >= 0 ) {
+ VsqBPPair v = m_items.get( index );
+ v.value = value;
+ v.id = id;
+ m_items.set( index, v );
+ } else {
+ m_clock.add( clock );
+ Collections.sort( m_clock );
+ index = m_clock.indexOf( clock );
+ m_items.insertElementAt( new VsqBPPair( value, id ), index );
+ m_max_id = Math.Max( m_max_id, id );
+ }
+ }
+
+ public void removeWithID( long id ) {
+ int c = m_items.size();
+ for ( int i = 0; i < c; i++ ) {
+ if ( m_items.get( i ).id == id ) {
+ m_items.removeElementAt( i );
+ m_clock.removeElementAt( i );
+ break;
+ }
+ }
+ }
+
+ public int getValue( int clock ) {
+ int index = m_clock.indexOf( clock );
+ if ( index >= 0 ) {
+ return m_items.get( index ).value;
+ } else {
+ int count = m_clock.size();
+ if ( count <= 0 ) {
+ return m_default;
+ } else {
+ int draft = -1;
+ for ( int i = 0; i < count; i++ ) {
+ int c = m_clock.get( i );
+ if ( clock < c ) {
+ break;
+ }
+ draft = i;
+ }
+ if ( draft < 0 ) {
+ return m_default;
+ } else {
+ return m_items.get( draft ).value;
+ }
+ }
+ }
+ }
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/VsqBPPair.cs b/trunk/Boare.Lib.Vsq/VsqBPPair.cs
index 5b039c5..d706798 100644
--- a/trunk/Boare.Lib.Vsq/VsqBPPair.cs
+++ b/trunk/Boare.Lib.Vsq/VsqBPPair.cs
@@ -11,12 +11,22 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
+#if JAVA
+package org.kbinani.vsq;
+
+import java.io.*;
+#else
using System;
namespace Boare.Lib.Vsq {
+#endif
+#if JAVA
+ public class VsqBPPair implements Cloneable, Serializable {
+#else
[Serializable]
public struct VsqBPPair {
+#endif
public int value;
public long id;
@@ -24,6 +34,14 @@ namespace Boare.Lib.Vsq {
value = value_;
id = id_;
}
+
+#if JAVA
+ public Object clone(){
+ return new VsqBPPair( value, id );
+ }
+#endif
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/VsqBPPairSearchContext.cs b/trunk/Boare.Lib.Vsq/VsqBPPairSearchContext.cs
index 081401e..3c5ac43 100644
--- a/trunk/Boare.Lib.Vsq/VsqBPPairSearchContext.cs
+++ b/trunk/Boare.Lib.Vsq/VsqBPPairSearchContext.cs
@@ -1,4 +1,21 @@
-namespace Boare.Lib.Vsq {
+/*
+ * VsqBPPairSearchContext.cs
+ * Copyright (c) 2009 kbinani
+ *
+ * This file is part of Boare.Lib.Vsq.
+ *
+ * Boare.Lib.Vsq is free software; you can redistribute it and/or
+ * modify it under the terms of the BSD License.
+ *
+ * Boare.Lib.Vsq 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.vsq;
+#else
+namespace Boare.Lib.Vsq {
+#endif
public class VsqBPPairSearchContext {
public int clock;
@@ -6,4 +23,6 @@
public VsqBPPair point;
}
+#if !JAVA
}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/VsqBarLineType.cs b/trunk/Boare.Lib.Vsq/VsqBarLineType.cs
index 5e33612..f3e1f2d 100644
--- a/trunk/Boare.Lib.Vsq/VsqBarLineType.cs
+++ b/trunk/Boare.Lib.Vsq/VsqBarLineType.cs
@@ -11,11 +11,14 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
+#if JAVA
+package org.kbinani.vsq;
+#else
using System;
namespace Boare.Lib.Vsq {
-
using boolean = System.Boolean;
+#endif
public struct VsqBarLineType {
private int m_clock;
@@ -53,4 +56,6 @@ namespace Boare.Lib.Vsq {
}
}
-}
\ No newline at end of file
+#if !JAVA
+}
+#endif
diff --git a/trunk/Boare.Lib.Vsq/VsqCommand.cs b/trunk/Boare.Lib.Vsq/VsqCommand.cs
index 61819a2..cdd6682 100644
--- a/trunk/Boare.Lib.Vsq/VsqCommand.cs
+++ b/trunk/Boare.Lib.Vsq/VsqCommand.cs
@@ -11,27 +11,38 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
+#if JAVA
+package org.kbinani.vsq;
+
+import java.io.*;
+import java.util.*;
+import org.kbinani.*;
+#else
using System;
using System.Collections.Generic;
-
using bocoree;
+using bocoree.java.util;
namespace Boare.Lib.Vsq {
-
using boolean = System.Boolean;
using Integer = System.Int32;
using Long = System.Int64;
+#endif
///
///
///
+#if JAVA
+ public class VsqCommand implements Serializable {
+#else
[Serializable]
public class VsqCommand {
+#endif
public VsqCommandType Type;
///
/// コマンドの処理内容を保持します。Args具体的な内容は、処理するクラスごとに異なります
///
- public object[] Args;
+ public Object[] Args;
///
/// 後続するコマンド
///
@@ -56,25 +67,25 @@ namespace Boare.Lib.Vsq {
public static VsqCommand generateCommandReplace( VsqFile vsq ) {
VsqCommand command = new VsqCommand();
- command.Args = new object[1];
+ command.Args = new Object[1];
command.Type = VsqCommandType.REPLACE;
- command.Args[0] = (VsqFile)vsq.Clone();
+ command.Args[0] = (VsqFile)vsq.clone();
return command;
}
public static VsqCommand generateCommandTrackReplace( int track, VsqTrack item ) {
VsqCommand command = new VsqCommand();
command.Type = VsqCommandType.TRACK_REPLACE;
- command.Args = new object[2];
+ command.Args = new Object[2];
command.Args[0] = track;
- command.Args[1] = (VsqTrack)item.Clone();
+ command.Args[1] = (VsqTrack)item.clone();
return command;
}
public static VsqCommand generateCommandUpdateTimesig( int bar_count, int new_barcount, int numerator, int denominator ) {
VsqCommand command = new VsqCommand();
command.Type = VsqCommandType.UPDATE_TIMESIG;
- command.Args = new object[4];
+ command.Args = new Object[4];
command.Args[0] = bar_count;
command.Args[1] = numerator;
command.Args[2] = denominator;
@@ -85,28 +96,28 @@ namespace Boare.Lib.Vsq {
public static VsqCommand generateCommandUpdateTimesigRange( int[] bar_counts, int[] new_barcounts, int[] numerators, int[] denominators ) {
VsqCommand command = new VsqCommand();
command.Type = VsqCommandType.UPDATE_TIMESIG_RANGE;
- command.Args = new object[4];
- command.Args[0] = (int[])bar_counts.Clone();
- command.Args[1] = (int[])numerators.Clone();
- command.Args[2] = (int[])denominators.Clone();
- command.Args[3] = (int[])new_barcounts.Clone();
+ command.Args = new Object[4];
+ command.Args[0] = copyIntArray( bar_counts );
+ command.Args[1] = copyIntArray( numerators );
+ command.Args[2] = copyIntArray( denominators );
+ command.Args[3] = copyIntArray( new_barcounts );
return command;
}
public static VsqCommand generateCommandUpdateTempoRange( int[] clocks, int[] new_clocks, int[] tempos ) {
VsqCommand command = new VsqCommand();
command.Type = VsqCommandType.UPDATE_TEMPO_RANGE;
- command.Args = new object[3];
- command.Args[0] = (int[])clocks.Clone();
- command.Args[1] = (int[])tempos.Clone();
- command.Args[2] = (int[])new_clocks.Clone();
+ command.Args = new Object[3];
+ command.Args[0] = copyIntArray( clocks );
+ command.Args[1] = copyIntArray( tempos );
+ command.Args[2] = copyIntArray( new_clocks );
return command;
}
public static VsqCommand generateCommandUpdateTempo( int clock, int new_clock, int tempo ) {
VsqCommand command = new VsqCommand();
command.Type = VsqCommandType.UPDATE_TEMPO;
- command.Args = new object[3];
+ command.Args = new Object[3];
command.Args[0] = clock;
command.Args[1] = tempo;
command.Args[2] = new_clock;
@@ -116,7 +127,7 @@ namespace Boare.Lib.Vsq {
public static VsqCommand generateCommandChangePreMeasure( int pre_measure ) {
VsqCommand command = new VsqCommand();
command.Type = VsqCommandType.CHANGE_PRE_MEASURE;
- command.Args = new object[1];
+ command.Args = new Object[1];
command.Args[0] = pre_measure;
return command;
}
@@ -124,7 +135,7 @@ namespace Boare.Lib.Vsq {
public static VsqCommand generateCommandDeleteTrack( int track ) {
VsqCommand command = new VsqCommand();
command.Type = VsqCommandType.TRACK_DELETE;
- command.Args = new object[1];
+ command.Args = new Object[1];
command.Args[0] = track;
return command;
}
@@ -137,7 +148,7 @@ namespace Boare.Lib.Vsq {
public static VsqCommand generateCommandAddTrack( VsqTrack track, VsqMixerEntry mixer, int position ) {
VsqCommand command = new VsqCommand();
command.Type = VsqCommandType.TRACK_ADD;
- command.Args = new object[5];
+ command.Args = new Object[3];
command.Args[0] = track;
command.Args[1] = mixer;
command.Args[2] = position;
@@ -153,7 +164,7 @@ namespace Boare.Lib.Vsq {
public static VsqCommand generateCommandTrackChangeName( int track, String new_name ) {
VsqCommand command = new VsqCommand();
command.Type = VsqCommandType.TRACK_CHANGE_NAME;
- command.Args = new object[2];
+ command.Args = new Object[2];
command.Args[0] = track;
command.Args[1] = new_name;
return command;
@@ -162,7 +173,7 @@ namespace Boare.Lib.Vsq {
public static VsqCommand generateCommandTrackChangePlayMode( int track, int play_mode ) {
VsqCommand command = new VsqCommand();
command.Type = VsqCommandType.TRACK_CHANGE_PLAY_MODE;
- command.Args = new object[2];
+ command.Args = new Object[2];
command.Args[0] = track;
command.Args[1] = play_mode;
return command;
@@ -180,11 +191,15 @@ namespace Boare.Lib.Vsq {
VsqCommand command = new VsqCommand();
command.Type = VsqCommandType.EVENT_CHANGE_CLOCK_AND_ID_CONTAINTS_RANGE;
int count = internal_ids.Length;
- command.Args = new object[4];
+ command.Args = new Object[4];
command.Args[0] = track;
- command.Args[1] = (int[])internal_ids.Clone();
- command.Args[2] = (int[])clocks.Clone();
- command.Args[3] = (VsqID[])values.Clone();
+ command.Args[1] = copyIntArray( internal_ids );
+ command.Args[2] = copyIntArray( clocks );
+ VsqID[] cp_values = new VsqID[values.Length];
+ for ( int i = 0; i < values.Length; i++ ) {
+ cp_values[i] = (VsqID)values[i].clone();
+ }
+ command.Args[3] = cp_values;
return command;
}
@@ -199,7 +214,7 @@ namespace Boare.Lib.Vsq {
public static VsqCommand generateCommandEventChangeClockAndIDContaints( int track, int internal_id, int clock, VsqID value ) {
VsqCommand command = new VsqCommand();
command.Type = VsqCommandType.EVENT_CHANGE_CLOCK_AND_ID_CONTAINTS;
- command.Args = new object[4];
+ command.Args = new Object[4];
command.Args[0] = track;
command.Args[1] = internal_id;
command.Args[2] = clock;
@@ -217,9 +232,9 @@ namespace Boare.Lib.Vsq {
public static VsqCommand generateCommandEventChangeIDContaintsRange( int track, int[] internal_ids, VsqID[] values ) {
VsqCommand command = new VsqCommand();
command.Type = VsqCommandType.EVENT_CHANGE_ID_CONTAINTS_RANGE;
- command.Args = new object[3];
+ command.Args = new Object[3];
command.Args[0] = track;
- command.Args[1] = (int[])internal_ids.Clone();
+ command.Args[1] = copyIntArray( internal_ids );
VsqID[] list = new VsqID[values.Length];
for ( int i = 0; i < values.Length; i++ ) {
list[i] = (VsqID)values[i].clone();
@@ -238,7 +253,7 @@ namespace Boare.Lib.Vsq {
public static VsqCommand generateCommandEventChangeIDContaints( int track, int internal_id, VsqID value ) {
VsqCommand command = new VsqCommand();
command.Type = VsqCommandType.EVENT_CHANGE_ID_CONTAINTS;
- command.Args = new object[3];
+ command.Args = new Object[3];
command.Args[0] = track;
command.Args[1] = internal_id;
command.Args[2] = (VsqID)value.clone();
@@ -256,7 +271,7 @@ namespace Boare.Lib.Vsq {
public static VsqCommand generateCommandEventChangeClockAndLength( int track, int internal_id, int new_clock, int new_length ) {
VsqCommand command = new VsqCommand();
command.Type = VsqCommandType.EVENT_CHANGE_CLOCK_AND_LENGTH;
- command.Args = new object[4];
+ command.Args = new Object[4];
command.Args[0] = track;
command.Args[1] = internal_id;
command.Args[2] = new_clock;
@@ -274,7 +289,7 @@ namespace Boare.Lib.Vsq {
public static VsqCommand generateCommandEventChangeLength( int track, int internal_id, int new_length ) {
VsqCommand command = new VsqCommand();
command.Type = VsqCommandType.EVENT_CHANGE_LENGTH;
- command.Args = new object[3];
+ command.Args = new Object[3];
command.Args[0] = track;
command.Args[1] = internal_id;
command.Args[2] = new_length;
@@ -288,15 +303,15 @@ namespace Boare.Lib.Vsq {
///
///
///
- public static VsqCommand generateCommandEventChangeVelocity( int track, Vector> velocity ) {
+ public static VsqCommand generateCommandEventChangeVelocity( int track, Vector> velocity ) {
VsqCommand command = new VsqCommand();
command.Type = VsqCommandType.EVENT_CHANGE_VELOCITY;
- command.Args = new object[2];
+ command.Args = new Object[2];
command.Args[0] = track;
- Vector> list = new Vector>();
- for( Iterator itr = velocity.iterator(); itr.hasNext(); ){
- KeyValuePair item = (KeyValuePair)itr.next();
- list.add( new KeyValuePair( item.Key, item.Value ) );
+ Vector