2009-06-25 07:16:22 -07:00
|
|
|
|
/*
|
|
|
|
|
* VibratoBPList.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.
|
|
|
|
|
*/
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if JAVA
|
|
|
|
|
package org.kbinani.vsq;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import org.kbinani.*;
|
|
|
|
|
#else
|
|
|
|
|
using System;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
using bocoree;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
using bocoree.java.util;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
namespace Boare.Lib.Vsq {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if JAVA
|
|
|
|
|
public class VibratoBPList implements Cloneable, Serializable {
|
|
|
|
|
#else
|
2009-07-29 10:03:20 -07:00
|
|
|
|
[Serializable]
|
2009-06-25 07:16:22 -07:00
|
|
|
|
public class VibratoBPList : ICloneable {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|
2009-09-07 03:44:18 -07:00
|
|
|
|
private Vector<VibratoBPPair> m_list;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
|
|
|
|
public VibratoBPList() {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
m_list = new Vector<VibratoBPPair>();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public VibratoBPList( float[] x, int[] y )
|
|
|
|
|
#if JAVA
|
|
|
|
|
throws NullPointerException
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
if ( x == null ) {
|
|
|
|
|
#if JAVA
|
|
|
|
|
throw new NullPointerException( "x" );
|
|
|
|
|
#else
|
2009-06-25 07:16:22 -07:00
|
|
|
|
throw new ArgumentNullException( "x" );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( y == null ) {
|
|
|
|
|
#if JAVA
|
|
|
|
|
throw new NullPointerException( "y" );
|
|
|
|
|
#else
|
2009-06-25 07:16:22 -07:00
|
|
|
|
throw new ArgumentNullException( "y" );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
int len = Math.Min( x.Length, y.Length );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
m_list = new Vector<VibratoBPPair>( len );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
for ( int i = 0; i < len; i++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
m_list.add( new VibratoBPPair( x[i], y[i] ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Collections.sort( m_list );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-29 10:03:20 -07:00
|
|
|
|
public int getValue( float x, int default_value ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( m_list.size() <= 0 ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
return default_value;
|
|
|
|
|
}
|
|
|
|
|
int index = -1;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int size = m_list.size();
|
|
|
|
|
for ( int i = 0; i < size; i++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( x < m_list.get( i ).X ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
index = i;
|
|
|
|
|
}
|
|
|
|
|
if ( index == -1 ) {
|
|
|
|
|
return default_value;
|
|
|
|
|
} else {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
return m_list.get( index ).Y;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public Object clone() {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VibratoBPList ret = new VibratoBPList();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
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 ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if !JAVA
|
|
|
|
|
public object Clone() {
|
|
|
|
|
return clone();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
public int getCount() {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
return m_list.size();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public VibratoBPPair getElement( int index ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
return m_list.get( index );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setElement( int index, VibratoBPPair value ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
m_list.set( index, value );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2009-07-29 10:03:20 -07:00
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if !JAVA
|
2009-07-29 10:03:20 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// XMLシリアライズ用
|
|
|
|
|
/// </summary>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public String Data {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
get {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
return getData();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
set {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
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;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
m_list.add( new VibratoBPPair( PortUtil.parseFloat( spl2[0] ), PortUtil.parseInt( spl2[1] ) ) );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if !JAVA
|
|
|
|
|
}
|
|
|
|
|
#endif
|