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.
|
|
|
|
|
*/
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
using bocoree;
|
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
namespace Boare.Lib.Vsq {
|
|
|
|
|
|
2009-07-29 10:03:20 -07:00
|
|
|
|
[Serializable]
|
2009-06-25 07:16:22 -07:00
|
|
|
|
public class VibratoBPList : ICloneable {
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public VibratoBPList( float[] x, int[] y ){
|
|
|
|
|
if ( x == null ){
|
|
|
|
|
throw new ArgumentNullException( "x" );
|
|
|
|
|
}
|
|
|
|
|
if ( y == null ){
|
|
|
|
|
throw new ArgumentNullException( "y" );
|
|
|
|
|
}
|
|
|
|
|
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;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int i = 0; i < m_list.size(); i++ ) {
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
public object Clone() {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// XMLシリアライズ用
|
|
|
|
|
/// </summary>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public String Data {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
get {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String ret = "";
|
|
|
|
|
for ( int i = 0; i < m_list.size(); i++ ) {
|
|
|
|
|
ret += (i == 0 ? "" : ",") + m_list.get( i ).X + "=" + m_list.get( i ).Y;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
set {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
m_list.clear();
|
|
|
|
|
String[] spl = value.Split( ',' );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
for ( int i = 0; i < spl.Length; i++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String[] spl2 = spl[i].Split( '=' );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
if ( spl2.Length < 2 ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
m_list.add( new VibratoBPPair( float.Parse( spl2[0] ), int.Parse( spl2[1] ) ) );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|