2009-06-25 07:16:22 -07:00
|
|
|
|
/*
|
|
|
|
|
* VsqFile.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.
|
|
|
|
|
*/
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#define NEW_IMPL
|
|
|
|
|
#if JAVA
|
|
|
|
|
package org.kbinani.vsq;
|
2009-09-07 03:44:18 -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;
|
|
|
|
|
using bocoree.java.io;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
|
|
|
|
namespace Boare.Lib.Vsq {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
using boolean = System.Boolean;
|
|
|
|
|
using Integer = Int32;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
using Long = System.Int64;
|
|
|
|
|
#endif
|
2009-09-07 03:44:18 -07:00
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// VSQファイルの内容を保持するクラス
|
|
|
|
|
/// </summary>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if JAVA
|
|
|
|
|
public class VsqFile implements Cloneable, Serializable{
|
|
|
|
|
#else
|
2009-06-25 07:16:22 -07:00
|
|
|
|
[Serializable]
|
|
|
|
|
public class VsqFile : ICloneable {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|
2009-06-25 07:16:22 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// トラックのリスト.最初のトラックはMasterTrackであり,通常の音符が格納されるトラックはインデックス1以降となる
|
|
|
|
|
/// </summary>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public Vector<VsqTrack> Track;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// テンポ情報を保持したテーブル
|
|
|
|
|
/// </summary>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public Vector<TempoTableEntry> TempoTable;
|
|
|
|
|
public Vector<TimeSigTableEntry> TimesigTable;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
protected int m_tpq;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 曲の長さを取得します。(クロック(4分音符は480クロック))
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int TotalClocks = 0;
|
|
|
|
|
protected int m_base_tempo;
|
|
|
|
|
public VsqMaster Master; // VsqMaster, VsqMixerは通常,最初の非Master Trackに記述されるが,可搬性のため,
|
|
|
|
|
public VsqMixer Mixer; // ここではVsqFileに直属するものとして取り扱う.
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public Object Tag;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
static readonly byte[] _MTRK = new byte[] { (byte)0x4d, (byte)0x54, (byte)0x72, (byte)0x6b };
|
|
|
|
|
static readonly byte[] _MTHD = new byte[] { (byte)0x4d, (byte)0x54, (byte)0x68, (byte)0x64 };
|
|
|
|
|
static readonly byte[] _MASTER_TRACK = new byte[] { (byte)0x4D, (byte)0x61, (byte)0x73, (byte)0x74, (byte)0x65, (byte)0x72, (byte)0x20, (byte)0x54, (byte)0x72, (byte)0x61, (byte)0x63, (byte)0x6B, };
|
2009-09-07 03:44:18 -07:00
|
|
|
|
static readonly String[] _CURVES = new String[] { "VEL", "DYN", "BRE", "BRI", "CLE", "OPE", "GEN", "POR", "PIT", "PBS" };
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if JAVA
|
|
|
|
|
public VsqFile( UstFile ust ){
|
|
|
|
|
this( "Miku", 1, 4, 4, ust.getBaseTempo() );
|
|
|
|
|
#else
|
|
|
|
|
public VsqFile( UstFile ust )
|
|
|
|
|
: this( "Miku", 1, 4, 4, ust.getBaseTempo() ) {
|
|
|
|
|
#endif
|
|
|
|
|
int clock_count = 480 * 4; //pre measure = 1、4分の4拍子としたので
|
|
|
|
|
VsqBPList pitch = new VsqBPList( 0, -2400, 2400 ); // ノートナンバー×100
|
|
|
|
|
for ( Iterator itr = ust.getTrack( 0 ).getNoteEventIterator(); itr.hasNext(); ) {
|
|
|
|
|
UstEvent ue = (UstEvent)itr.next();
|
|
|
|
|
if ( ue.Lyric != "R" ) {
|
|
|
|
|
VsqID id = new VsqID( 0 );
|
|
|
|
|
id.setLength( ue.getLength() );
|
|
|
|
|
ByRef<String> psymbol = new ByRef<String>( "a" );
|
|
|
|
|
if ( !SymbolTable.attatch( ue.Lyric, psymbol ) ) {
|
|
|
|
|
psymbol.value = "a";
|
|
|
|
|
}
|
|
|
|
|
id.LyricHandle = new LyricHandle( ue.Lyric, psymbol.value );
|
|
|
|
|
id.Note = ue.Note;
|
|
|
|
|
id.type = VsqIDType.Anote;
|
|
|
|
|
VsqEvent ve = new VsqEvent( clock_count, id );
|
|
|
|
|
ve.UstEvent = (UstEvent)ue.clone();
|
|
|
|
|
Track.get( 1 ).addEvent( ve );
|
|
|
|
|
|
|
|
|
|
if ( ue.Pitches != null ) {
|
|
|
|
|
// PBTypeクロックごとにデータポイントがある
|
|
|
|
|
int clock = clock_count - ue.PBType;
|
|
|
|
|
for ( int i = 0; i < ue.Pitches.Length; i++ ) {
|
|
|
|
|
clock += ue.PBType;
|
|
|
|
|
pitch.add( clock, (int)ue.Pitches[i] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( ue.Tempo > 0.0f ) {
|
|
|
|
|
TempoTable.add( new TempoTableEntry( clock_count, (int)(60e6 / ue.Tempo), 0.0 ) );
|
|
|
|
|
}
|
|
|
|
|
clock_count += ue.getLength();
|
|
|
|
|
}
|
|
|
|
|
updateTempoInfo();
|
|
|
|
|
updateTotalClocks();
|
|
|
|
|
updateTimesigInfo();
|
|
|
|
|
reflectPitch( this, 1, pitch );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// master==MasterPitchControl.Pitchの場合、m_pitchからPITとPBSを再構成。
|
|
|
|
|
/// master==MasterPitchControl.PITandPBSの場合、PITとPBSからm_pitchを再構成
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static void reflectPitch( VsqFile vsq, int track, VsqBPList pitch ) {
|
|
|
|
|
//double offset = AttachedCurves[track - 1].MasterTuningInCent * 100;
|
|
|
|
|
//Vector<Integer> keyclocks = new Vector<Integer>( pitch.getKeys() );
|
|
|
|
|
int keyclock_size = pitch.size();
|
|
|
|
|
VsqBPList pit = new VsqBPList( 0, -8192, 8191 );
|
|
|
|
|
VsqBPList pbs = new VsqBPList( 2, 0, 24 );
|
|
|
|
|
int premeasure_clock = vsq.getPreMeasureClocks();
|
|
|
|
|
int lastpit = pit.getDefault();
|
|
|
|
|
int lastpbs = pbs.getDefault();
|
|
|
|
|
int vpbs = 24;
|
|
|
|
|
int vpit = 0;
|
|
|
|
|
|
|
|
|
|
Vector<Integer> parts = new Vector<Integer>(); // 連続した音符ブロックの先頭音符のクロック位置。のリスト
|
|
|
|
|
parts.add( premeasure_clock );
|
|
|
|
|
int lastclock = premeasure_clock;
|
|
|
|
|
for ( Iterator itr = vsq.Track.get( track ).getNoteEventIterator(); itr.hasNext(); ) {
|
|
|
|
|
VsqEvent ve = (VsqEvent)itr.next();
|
|
|
|
|
if ( ve.Clock <= lastclock ) {
|
|
|
|
|
lastclock = Math.Max( lastclock, ve.Clock + ve.ID.getLength() );
|
|
|
|
|
} else {
|
|
|
|
|
parts.add( ve.Clock );
|
|
|
|
|
lastclock = ve.Clock + ve.ID.getLength();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int parts_size = parts.size();
|
|
|
|
|
for ( int i = 0; i < parts_size; i++ ) {
|
|
|
|
|
int partstart = parts.get( i );
|
|
|
|
|
int partend = int.MaxValue;
|
|
|
|
|
if ( i + 1 < parts.size() ) {
|
|
|
|
|
partend = parts.get( i + 1 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// まず、区間内の最大ピッチベンド幅を調べる
|
|
|
|
|
double max = 0;
|
|
|
|
|
for ( int j = 0; j < keyclock_size; j++ ) {
|
|
|
|
|
int clock = pitch.getKeyClock( j );
|
|
|
|
|
if ( clock < partstart ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ( partend <= clock ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
max = Math.Max( max, Math.Abs( pitch.getValue( clock ) / 100.0 ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 最大ピッチベンド幅を表現できる最小のPBSを計算
|
|
|
|
|
vpbs = (int)(Math.Ceiling( max * 8192.0 / 8191.0 ) + 0.1);
|
|
|
|
|
if ( vpbs <= 0 ) {
|
|
|
|
|
vpbs = 1;
|
|
|
|
|
}
|
|
|
|
|
double pitch2 = pitch.getValue( partstart ) / 100.0;
|
|
|
|
|
if ( lastpbs != vpbs ) {
|
|
|
|
|
pbs.add( partstart, vpbs );
|
|
|
|
|
lastpbs = vpbs;
|
|
|
|
|
}
|
|
|
|
|
vpit = (int)(pitch2 * 8192 / (double)vpbs);
|
|
|
|
|
if ( lastpit != vpit ) {
|
|
|
|
|
pit.add( partstart, vpit );
|
|
|
|
|
lastpit = vpit;
|
|
|
|
|
}
|
|
|
|
|
for ( int j = 0; j < keyclock_size; j++ ) {
|
|
|
|
|
int clock = pitch.getKeyClock( j );
|
|
|
|
|
if ( clock < partstart ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ( partend <= clock ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ( clock != partstart ) {
|
|
|
|
|
pitch2 = pitch.getElement( j ) / 100.0;
|
|
|
|
|
vpit = (int)(pitch2 * 8192 / (double)vpbs);
|
|
|
|
|
if ( lastpit != vpit ) {
|
|
|
|
|
pit.add( clock, vpit );
|
|
|
|
|
lastpit = vpit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
vsq.Track.get( track ).setCurve( "pit", pit );
|
|
|
|
|
vsq.Track.get( track ).setCurve( "pbs", pbs );
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// プリセンドタイムの妥当性を判定します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ms_pre_send_time"></param>
|
|
|
|
|
/// <returns></returns>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public boolean checkPreSendTimeValidity( int ms_pre_send_time ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int track_count = Track.size();
|
|
|
|
|
for ( int i = 1; i < track_count; i++ ) {
|
|
|
|
|
VsqTrack track = Track.get( i );
|
|
|
|
|
for ( Iterator itr = track.getNoteEventIterator(); itr.hasNext(); ) {
|
|
|
|
|
VsqEvent item = (VsqEvent)itr.next();
|
|
|
|
|
int presend_clock = getPresendClockAt( item.Clock, ms_pre_send_time );
|
|
|
|
|
if ( item.Clock - presend_clock < 0 ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
2009-07-29 10:03:20 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// テンポ値を一律order倍します。
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="order"></param>
|
|
|
|
|
public void speedingUp( double order ) {
|
|
|
|
|
lock ( TempoTable ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int c = TempoTable.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = 0; i < c; i++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTable.get( i ).Tempo = (int)(TempoTable.get( i ).Tempo / order);
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
updateTempoInfo();
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// このインスタンスに編集を行うコマンドを実行します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="command">実行するコマンド</param>
|
|
|
|
|
/// <returns>編集結果を元に戻すためのコマンドを返します</returns>
|
|
|
|
|
public VsqCommand executeCommand( VsqCommand command ) {
|
|
|
|
|
#if DEBUG
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.println( "VsqFile.Execute(VsqCommand)" );
|
|
|
|
|
PortUtil.println( " type=" + command.Type );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endif
|
|
|
|
|
VsqCommandType type = command.Type;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( type == VsqCommandType.CHANGE_PRE_MEASURE ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region CHANGE_PRE_MEASURE
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqCommand ret = VsqCommand.generateCommandChangePreMeasure( Master.PreMeasure );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int value = (Integer)command.Args[0];
|
2009-06-25 07:16:22 -07:00
|
|
|
|
Master.PreMeasure = value;
|
|
|
|
|
updateTimesigInfo();
|
|
|
|
|
return ret;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.TRACK_ADD ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region TRACK_ADD
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#if DEBUG
|
|
|
|
|
System.Diagnostics.Debug.WriteLine( " AddTrack" );
|
|
|
|
|
#endif
|
|
|
|
|
VsqTrack track = (VsqTrack)command.Args[0];
|
|
|
|
|
VsqMixerEntry mixer = (VsqMixerEntry)command.Args[1];
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int position = (Integer)command.Args[2];
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqCommand ret = VsqCommand.generateCommandDeleteTrack( position );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( Track.size() <= 17 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Track.insertElementAt( (VsqTrack)track.clone(), position );
|
|
|
|
|
Mixer.Slave.add( (VsqMixerEntry)mixer.clone() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
return ret;
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.TRACK_DELETE ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region TRACK_DELETE
|
|
|
|
|
int track = (Integer)command.Args[0];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqCommand ret = VsqCommand.generateCommandAddTrack( Track.get( track ), Mixer.Slave.get( track - 1 ), track );
|
|
|
|
|
Track.removeElementAt( track );
|
|
|
|
|
Mixer.Slave.removeElementAt( track - 1 );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
updateTotalClocks();
|
|
|
|
|
return ret;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.UPDATE_TEMPO ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region UPDATE_TEMPO
|
|
|
|
|
int clock = (Integer)command.Args[0];
|
|
|
|
|
int tempo = (Integer)command.Args[1];
|
|
|
|
|
int new_clock = (Integer)command.Args[2];
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
|
|
|
|
int index = -1;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int c = TempoTable.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = 0; i < c; i++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( TempoTable.get( i ).Clock == clock ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
index = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
VsqCommand ret = null;
|
|
|
|
|
if ( index >= 0 ) {
|
|
|
|
|
if ( tempo <= 0 ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
ret = VsqCommand.generateCommandUpdateTempo( clock, clock, TempoTable.get( index ).Tempo );
|
|
|
|
|
TempoTable.removeElementAt( index );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
} else {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
ret = VsqCommand.generateCommandUpdateTempo( new_clock, clock, TempoTable.get( index ).Tempo );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
TempoTable.get( index ).Tempo = tempo;
|
|
|
|
|
TempoTable.get( index ).Clock = new_clock;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ret = VsqCommand.generateCommandUpdateTempo( clock, clock, -1 );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTable.add( new TempoTableEntry( new_clock, tempo, 0.0 ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
updateTempoInfo();
|
|
|
|
|
updateTotalClocks();
|
|
|
|
|
|
|
|
|
|
// 編集領域を更新
|
|
|
|
|
int affected_clock = Math.Min( clock, new_clock );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
c = Track.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = 1; i < c; i++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( affected_clock < Track.get( i ).getEditedStart() ) {
|
|
|
|
|
Track.get( i ).setEditedStart( affected_clock );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( i ).setEditedEnd( (int)TotalClocks );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.UPDATE_TEMPO_RANGE ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region UPDATE_TEMPO_RANGE
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int[] clocks = (int[])command.Args[0];
|
|
|
|
|
int[] tempos = (int[])command.Args[1];
|
|
|
|
|
int[] new_clocks = (int[])command.Args[2];
|
|
|
|
|
int[] new_tempos = new int[tempos.Length];
|
|
|
|
|
int affected_clock = int.MaxValue;
|
|
|
|
|
for ( int i = 0; i < clocks.Length; i++ ) {
|
|
|
|
|
int index = -1;
|
|
|
|
|
affected_clock = Math.Min( affected_clock, clocks[i] );
|
|
|
|
|
affected_clock = Math.Min( affected_clock, new_clocks[i] );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int tempo_table_count = TempoTable.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int j = 0; j < tempo_table_count; j++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( TempoTable.get( j ).Clock == clocks[i] ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
index = j;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( index >= 0 ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
new_tempos[i] = TempoTable.get( index ).Tempo;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( tempos[i] <= 0 ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTable.removeElementAt( index );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
} else {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTable.get( index ).Tempo = tempos[i];
|
|
|
|
|
TempoTable.get( index ).Clock = new_clocks[i];
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
new_tempos[i] = -1;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTable.add( new TempoTableEntry( new_clocks[i], tempos[i], 0.0 ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
updateTempoInfo();
|
|
|
|
|
updateTotalClocks();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int track_count = Track.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = 1; i < track_count; i++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( affected_clock < Track.get( i ).getEditedStart() ) {
|
|
|
|
|
Track.get( i ).setEditedStart( affected_clock );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( i ).setEditedEnd( (int)TotalClocks );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
return VsqCommand.generateCommandUpdateTempoRange( new_clocks, clocks, new_tempos );
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.UPDATE_TIMESIG ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region UPDATE_TIMESIG
|
|
|
|
|
int barcount = (Integer)command.Args[0];
|
|
|
|
|
int numerator = (Integer)command.Args[1];
|
|
|
|
|
int denominator = (Integer)command.Args[2];
|
|
|
|
|
int new_barcount = (Integer)command.Args[3];
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int index = -1;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int timesig_table_count = TimesigTable.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = 0; i < timesig_table_count; i++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( barcount == TimesigTable.get( i ).BarCount ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
index = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
VsqCommand ret = null;
|
|
|
|
|
if ( index >= 0 ) {
|
|
|
|
|
if ( numerator <= 0 ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
ret = VsqCommand.generateCommandUpdateTimesig( barcount, barcount, TimesigTable.get( index ).Numerator, TimesigTable.get( index ).Denominator );
|
|
|
|
|
TimesigTable.removeElementAt( index );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
} else {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
ret = VsqCommand.generateCommandUpdateTimesig( new_barcount, barcount, TimesigTable.get( index ).Numerator, TimesigTable.get( index ).Denominator );
|
|
|
|
|
TimesigTable.get( index ).BarCount = new_barcount;
|
|
|
|
|
TimesigTable.get( index ).Numerator = numerator;
|
|
|
|
|
TimesigTable.get( index ).Denominator = denominator;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ret = VsqCommand.generateCommandUpdateTimesig( new_barcount, new_barcount, -1, -1 );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TimesigTable.add( new TimeSigTableEntry( 0, numerator, denominator, new_barcount ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
updateTimesigInfo();
|
|
|
|
|
updateTotalClocks();
|
|
|
|
|
return ret;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.UPDATE_TIMESIG_RANGE ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region UPDATE_TIMESIG_RANGE
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int[] barcounts = (int[])command.Args[0];
|
|
|
|
|
int[] numerators = (int[])command.Args[1];
|
|
|
|
|
int[] denominators = (int[])command.Args[2];
|
|
|
|
|
int[] new_barcounts = (int[])command.Args[3];
|
|
|
|
|
int[] new_numerators = new int[numerators.Length];
|
|
|
|
|
int[] new_denominators = new int[denominators.Length];
|
|
|
|
|
for ( int i = 0; i < barcounts.Length; i++ ) {
|
|
|
|
|
int index = -1;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
// すでに拍子が登録されているかどうかを検査
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int timesig_table_count = TimesigTable.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int j = 0; j < timesig_table_count; j++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( TimesigTable.get( j ).BarCount == barcounts[i] ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
index = j;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( index >= 0 ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
// 登録されている場合
|
2009-09-07 03:44:18 -07:00
|
|
|
|
new_numerators[i] = TimesigTable.get( index ).Numerator;
|
|
|
|
|
new_denominators[i] = TimesigTable.get( index ).Denominator;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( numerators[i] <= 0 ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TimesigTable.removeElementAt( index );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
} else {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TimesigTable.get( index ).BarCount = new_barcounts[i];
|
|
|
|
|
TimesigTable.get( index ).Numerator = numerators[i];
|
|
|
|
|
TimesigTable.get( index ).Denominator = denominators[i];
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
// 登録されていない場合
|
2009-06-25 07:16:22 -07:00
|
|
|
|
new_numerators[i] = -1;
|
|
|
|
|
new_denominators[i] = -1;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TimesigTable.add( new TimeSigTableEntry( 0, numerators[i], denominators[i], new_barcounts[i] ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
updateTimesigInfo();
|
|
|
|
|
updateTotalClocks();
|
|
|
|
|
return VsqCommand.generateCommandUpdateTimesigRange( new_barcounts, barcounts, new_numerators, new_denominators );
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.REPLACE ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region REPLACE
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqFile vsq = (VsqFile)command.Args[0];
|
2010-03-16 20:14:08 -07:00
|
|
|
|
VsqFile inv = (VsqFile)this.clone();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.clear();
|
|
|
|
|
int track_count = vsq.Track.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = 0; i < track_count; i++ ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Track.add( (VsqTrack)vsq.Track.get( i ).clone() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTable.clear();
|
|
|
|
|
int tempo_table_count = vsq.TempoTable.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = 0; i < tempo_table_count; i++ ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
TempoTable.add( (TempoTableEntry)vsq.TempoTable.get( i ).clone() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TimesigTable.clear();
|
|
|
|
|
int timesig_table_count = vsq.TimesigTable.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = 0; i < timesig_table_count; i++ ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
TimesigTable.add( (TimeSigTableEntry)vsq.TimesigTable.get( i ).clone() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
m_tpq = vsq.m_tpq;
|
|
|
|
|
TotalClocks = vsq.TotalClocks;
|
|
|
|
|
m_base_tempo = vsq.m_base_tempo;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Master = (VsqMaster)vsq.Master.clone();
|
|
|
|
|
Mixer = (VsqMixer)vsq.Mixer.clone();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
updateTotalClocks();
|
|
|
|
|
return VsqCommand.generateCommandReplace( inv );
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_ADD ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_ADD
|
|
|
|
|
int track = (Integer)command.Args[0];
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent item = (VsqEvent)command.Args[1];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).addEvent( item );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqCommand ret = VsqCommand.generateCommandEventDelete( track, item.InternalID );
|
|
|
|
|
updateTotalClocks();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( item.Clock < Track.get( track ).getEditedStart() ) {
|
|
|
|
|
Track.get( track ).setEditedStart( item.Clock );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( Track.get( track ).getEditedEnd() < item.Clock + item.ID.getLength() ) {
|
|
|
|
|
Track.get( track ).setEditedEnd( item.Clock + item.ID.getLength() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).sortEvent();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
return ret;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_ADD_RANGE ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_ADD_RANGE
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#if DEBUG
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.println( " TrackAddNoteRange" );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endif
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int track = (Integer)command.Args[0];
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent[] items = (VsqEvent[])command.Args[1];
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Vector<Integer> inv_ids = new Vector<Integer>();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int min_clock = (int)TotalClocks;
|
|
|
|
|
int max_clock = 0;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
VsqTrack target = Track.get( track );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
for ( int i = 0; i < items.Length; i++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqEvent item = (VsqEvent)items[i].clone();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
min_clock = Math.Min( min_clock, item.Clock );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
max_clock = Math.Max( max_clock, item.Clock + item.ID.getLength() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#if DEBUG
|
|
|
|
|
Console.Write( " i=" + i + "; item.InternalID=" + item.InternalID );
|
|
|
|
|
#endif
|
2010-03-16 20:14:08 -07:00
|
|
|
|
target.addEvent( item );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
inv_ids.add( item.InternalID );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#if DEBUG
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.println( " => " + item.InternalID );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
updateTotalClocks();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( min_clock < target.getEditedStart() ) {
|
|
|
|
|
target.setEditedStart( min_clock );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( target.getEditedEnd() < max_clock ) {
|
|
|
|
|
target.setEditedEnd( max_clock );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
target.sortEvent();
|
|
|
|
|
return VsqCommand.generateCommandEventDeleteRange( track, inv_ids );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_DELETE ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_DELETE
|
|
|
|
|
int track = (Integer)command.Args[0];
|
|
|
|
|
int internal_id = (Integer)command.Args[1];
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent[] original = new VsqEvent[1];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqTrack target = Track.get( track );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( Iterator itr = target.getEventIterator(); itr.hasNext(); ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent item = (VsqEvent)itr.next();
|
|
|
|
|
if ( item.InternalID == internal_id ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
original[0] = (VsqEvent)item.clone();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-30 08:02:59 -07:00
|
|
|
|
if ( original[0].Clock < target.getEditedStart() ) {
|
|
|
|
|
target.setEditedStart( original[0].Clock );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( target.getEditedEnd() < original[0].Clock + original[0].ID.getLength() ) {
|
|
|
|
|
target.setEditedEnd( original[0].Clock + original[0].ID.getLength() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
VsqCommand ret = VsqCommand.generateCommandEventAddRange( track, original );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
int count = target.getEventCount();
|
|
|
|
|
for ( int i = 0; i < count; i++ ) {
|
|
|
|
|
if ( target.getEvent( i ).InternalID == internal_id ) {
|
|
|
|
|
target.removeEvent( i );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
updateTotalClocks();
|
|
|
|
|
return ret;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_DELETE_RANGE ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_DELETE_RANGE
|
|
|
|
|
Vector<Integer> internal_ids = (Vector<Integer>)command.Args[1];
|
|
|
|
|
int track = (Integer)command.Args[0];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Vector<VsqEvent> inv = new Vector<VsqEvent>();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int min_clock = int.MaxValue;
|
|
|
|
|
int max_clock = int.MinValue;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqTrack target = this.Track.get( track );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int count = internal_ids.size();
|
|
|
|
|
for ( int j = 0; j < count; j++ ) {
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = 0; i < target.getEventCount(); i++ ) {
|
|
|
|
|
VsqEvent item = target.getEvent( i );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( internal_ids.get( j ) == item.InternalID ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
inv.add( (VsqEvent)item.clone() );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
min_clock = Math.Min( min_clock, item.Clock );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
max_clock = Math.Max( max_clock, item.Clock + item.ID.getLength() );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
target.removeEvent( i );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
updateTotalClocks();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
target.setEditedStart( min_clock );
|
|
|
|
|
target.setEditedEnd( max_clock );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
return VsqCommand.generateCommandEventAddRange( track, inv.toArray( new VsqEvent[] { } ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_CHANGE_CLOCK ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_CHANGE_CLOCK
|
|
|
|
|
int track = (Integer)command.Args[0];
|
|
|
|
|
int internal_id = (Integer)command.Args[1];
|
|
|
|
|
int value = (Integer)command.Args[2];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqTrack target = this.Track.get( track );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( Iterator itr = target.getEventIterator(); itr.hasNext(); ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent item = (VsqEvent)itr.next();
|
|
|
|
|
if ( item.InternalID == internal_id ) {
|
|
|
|
|
VsqCommand ret = VsqCommand.generateCommandEventChangeClock( track, internal_id, item.Clock );
|
|
|
|
|
int min = Math.Min( item.Clock, value );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int max = Math.Max( item.Clock + item.ID.getLength(), value + item.ID.getLength() );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
target.setEditedStart( min );
|
|
|
|
|
target.setEditedEnd( max );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
item.Clock = value;
|
|
|
|
|
updateTotalClocks();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
target.sortEvent();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_CHANGE_LYRIC ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_CHANGE_LYRIC
|
|
|
|
|
int track = (Integer)command.Args[0];
|
|
|
|
|
int internal_id = (Integer)command.Args[1];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String phrase = (String)command.Args[2];
|
|
|
|
|
String phonetic_symbol = (String)command.Args[3];
|
2010-03-16 20:14:08 -07:00
|
|
|
|
boolean protect_symbol = (Boolean)command.Args[4];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqTrack target = this.Track.get( track );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( Iterator itr = target.getEventIterator(); itr.hasNext(); ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent item = (VsqEvent)itr.next();
|
|
|
|
|
if ( item.InternalID == internal_id ) {
|
|
|
|
|
if ( item.ID.type == VsqIDType.Anote ) {
|
|
|
|
|
VsqCommand ret = VsqCommand.generateCommandEventChangeLyric( track, internal_id, item.ID.LyricHandle.L0.Phrase, item.ID.LyricHandle.L0.getPhoneticSymbol(), item.ID.LyricHandle.L0.PhoneticSymbolProtected );
|
|
|
|
|
item.ID.LyricHandle.L0.Phrase = phrase;
|
|
|
|
|
item.ID.LyricHandle.L0.setPhoneticSymbol( phonetic_symbol );
|
|
|
|
|
item.ID.LyricHandle.L0.PhoneticSymbolProtected = protect_symbol;
|
2009-07-30 08:02:59 -07:00
|
|
|
|
target.setEditedStart( item.Clock );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
target.setEditedEnd( item.Clock + item.ID.getLength() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
updateTotalClocks();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_CHANGE_NOTE ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_CHANGE_NOTE
|
|
|
|
|
int track = (Integer)command.Args[0];
|
|
|
|
|
int internal_id = (Integer)command.Args[1];
|
|
|
|
|
int note = (Integer)command.Args[2];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqTrack target = this.Track.get( track );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( Iterator itr = target.getEventIterator(); itr.hasNext(); ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent item = (VsqEvent)itr.next();
|
|
|
|
|
if ( item.InternalID == internal_id ) {
|
|
|
|
|
VsqCommand ret = VsqCommand.generateCommandEventChangeNote( track, internal_id, item.ID.Note );
|
|
|
|
|
item.ID.Note = note;
|
|
|
|
|
updateTotalClocks();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
target.setEditedStart( item.Clock );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
target.setEditedEnd( item.Clock + item.ID.getLength() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_CHANGE_CLOCK_AND_NOTE ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_CHANGE_CLOCK_AND_NOTE
|
|
|
|
|
int track = (Integer)command.Args[0];
|
|
|
|
|
int internal_id = (Integer)command.Args[1];
|
|
|
|
|
int clock = (Integer)command.Args[2];
|
|
|
|
|
int note = (Integer)command.Args[3];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqTrack target = this.Track.get( track );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( Iterator itr = target.getEventIterator(); itr.hasNext(); ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent item = (VsqEvent)itr.next();
|
|
|
|
|
if ( item.InternalID == internal_id ) {
|
|
|
|
|
VsqCommand ret = VsqCommand.generateCommandEventChangeClockAndNote( track, internal_id, item.Clock, item.ID.Note );
|
|
|
|
|
int min = Math.Min( item.Clock, clock );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int max = Math.Max( item.Clock + item.ID.getLength(), clock + item.ID.getLength() );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
target.setEditedStart( min );
|
|
|
|
|
target.setEditedEnd( max );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
item.Clock = clock;
|
|
|
|
|
item.ID.Note = note;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
target.sortEvent();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
updateTotalClocks();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.TRACK_CURVE_EDIT ) {
|
|
|
|
|
#region TRACK_CURVE_EDIT
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int track = (Integer)command.Args[0];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String curve = (String)command.Args[1];
|
|
|
|
|
Vector<BPPair> com = (Vector<BPPair>)command.Args[2];
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqCommand inv = null;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Vector<BPPair> edit = new Vector<BPPair>();
|
|
|
|
|
VsqBPList target_list = Track.get( track ).getCurve( curve );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( com != null ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( com.size() > 0 ) {
|
|
|
|
|
int start_clock = com.get( 0 ).Clock;
|
|
|
|
|
int end_clock = com.get( 0 ).Clock;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator itr = com.iterator(); itr.hasNext(); ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
BPPair item = (BPPair)itr.next();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
start_clock = Math.Min( start_clock, item.Clock );
|
|
|
|
|
end_clock = Math.Max( end_clock, item.Clock );
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).setEditedStart( start_clock );
|
|
|
|
|
Track.get( track ).setEditedEnd( end_clock );
|
|
|
|
|
int start_value = target_list.getValue( start_clock );
|
|
|
|
|
int end_value = target_list.getValue( end_clock );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator i = target_list.keyClockIterator(); i.hasNext(); ) {
|
|
|
|
|
int clock = (Integer)i.next();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( start_clock <= clock && clock <= end_clock ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
edit.add( new BPPair( clock, target_list.getValue( clock ) ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
boolean start_found = false;
|
|
|
|
|
boolean end_found = false;
|
|
|
|
|
int count = edit.size();
|
|
|
|
|
for ( int i = 0; i < count; i++ ) {
|
|
|
|
|
if ( edit.get( i ).Clock == start_clock ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
start_found = true;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
edit.get( i ).Value = start_value;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( start_found && end_found ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( edit.get( i ).Clock == end_clock ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
end_found = true;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
edit.get( i ).Value = end_value;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( start_found && end_found ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( !start_found ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
edit.add( new BPPair( start_clock, start_value ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
if ( !end_found ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
edit.add( new BPPair( end_clock, end_value ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 並べ替え
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Collections.sort( edit );
|
|
|
|
|
inv = VsqCommand.generateCommandTrackCurveEdit( track, curve, edit );
|
|
|
|
|
} else if ( com.size() == 0 ) {
|
|
|
|
|
inv = VsqCommand.generateCommandTrackCurveEdit( track, curve, new Vector<BPPair>() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateTotalClocks();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( com.size() == 0 ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
return inv;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( com.size() == 1 ) {
|
|
|
|
|
boolean found = false;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator itr = target_list.keyClockIterator(); itr.hasNext(); ) {
|
|
|
|
|
int clock = (Integer)itr.next();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( clock == com.get( 0 ).Clock ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
found = true;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
target_list.add( clock, com.get( 0 ).Value );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( !found ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
target_list.add( com.get( 0 ).Clock, com.get( 0 ).Value );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int start_clock = com.get( 0 ).Clock;
|
|
|
|
|
int end_clock = com.get( com.size() - 1 ).Clock;
|
|
|
|
|
boolean removed = true;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
while ( removed ) {
|
|
|
|
|
removed = false;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( Iterator itr = target_list.keyClockIterator(); itr.hasNext(); ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int clock = (Integer)itr.next();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( start_clock <= clock && clock <= end_clock ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
target_list.remove( clock );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
removed = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator itr = com.iterator(); itr.hasNext(); ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
BPPair item = (BPPair)itr.next();
|
|
|
|
|
target_list.add( item.Clock, item.Value );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return inv;
|
|
|
|
|
#endregion
|
2010-03-16 20:14:08 -07:00
|
|
|
|
} else if ( type == VsqCommandType.TRACK_CURVE_EDIT2 ) {
|
|
|
|
|
#region TRACK_CURVE_EDIT2
|
|
|
|
|
int track = (Integer)command.Args[0];
|
|
|
|
|
String curve = (String)command.Args[1];
|
|
|
|
|
Vector<Long> delete = (Vector<Long>)command.Args[2];
|
|
|
|
|
TreeMap<Integer, VsqBPPair> add = (TreeMap<Integer, VsqBPPair>)command.Args[3];
|
|
|
|
|
|
|
|
|
|
Vector<Long> inv_delete = new Vector<Long>();
|
|
|
|
|
TreeMap<Integer, VsqBPPair> inv_add = new TreeMap<Integer, VsqBPPair>();
|
|
|
|
|
processTrackCurveEdit( track, curve, delete, add, inv_delete, inv_add );
|
|
|
|
|
updateTotalClocks();
|
|
|
|
|
|
|
|
|
|
return VsqCommand.generateCommandTrackCurveEdit2( track, curve, inv_delete, inv_add );
|
|
|
|
|
#endregion
|
|
|
|
|
} else if ( type == VsqCommandType.TRACK_CURVE_EDIT2_ALL ) {
|
|
|
|
|
#region TRACK_CURVE_EDIT2_ALL
|
|
|
|
|
int track = (Integer)command.Args[0];
|
|
|
|
|
Vector<String> curve = (Vector<String>)command.Args[1];
|
|
|
|
|
Vector<Vector<Long>> delete = (Vector<Vector<Long>>)command.Args[2];
|
|
|
|
|
Vector<TreeMap<Integer, VsqBPPair>> add = (Vector<TreeMap<Integer, VsqBPPair>>)command.Args[3];
|
|
|
|
|
|
|
|
|
|
int c = curve.size();
|
|
|
|
|
Vector<Vector<Long>> inv_delete = new Vector<Vector<Long>>();
|
|
|
|
|
Vector<TreeMap<Integer, VsqBPPair>> inv_add = new Vector<TreeMap<Integer, VsqBPPair>>();
|
|
|
|
|
for ( int i = 0; i < c; i++ ) {
|
|
|
|
|
Vector<Long> part_inv_delete = new Vector<Long>();
|
|
|
|
|
TreeMap<Integer, VsqBPPair> part_inv_add = new TreeMap<Integer, VsqBPPair>();
|
|
|
|
|
processTrackCurveEdit( track, curve.get( i ), delete.get( i ), add.get( i ), part_inv_delete, part_inv_add );
|
|
|
|
|
inv_delete.add( part_inv_delete );
|
|
|
|
|
inv_add.add( part_inv_add );
|
|
|
|
|
}
|
|
|
|
|
updateTotalClocks();
|
|
|
|
|
|
|
|
|
|
return VsqCommand.generateCommandTrackCurveEdit2All( track, curve, inv_delete, inv_add );
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.TRACK_CURVE_REPLACE ) {
|
|
|
|
|
#region TRACK_CURVE_REPLACE
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int track = (Integer)command.Args[0];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String target_curve = (String)command.Args[1];
|
|
|
|
|
VsqBPList bplist = (VsqBPList)command.Args[2];
|
|
|
|
|
VsqCommand inv = VsqCommand.generateCommandTrackCurveReplace( track, target_curve, Track.get( track ).getCurve( target_curve ) );
|
|
|
|
|
Track.get( track ).setCurve( target_curve, bplist );
|
|
|
|
|
return inv;
|
|
|
|
|
#endregion
|
|
|
|
|
} else if ( type == VsqCommandType.TRACK_CURVE_REPLACE_RANGE ) {
|
|
|
|
|
#region TRACK_CURVE_REPLACE_RANGE
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int track = (Integer)command.Args[0];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String[] target_curve = (String[])command.Args[1];
|
|
|
|
|
VsqBPList[] bplist = (VsqBPList[])command.Args[2];
|
|
|
|
|
VsqBPList[] inv_bplist = new VsqBPList[bplist.Length];
|
|
|
|
|
VsqTrack work = Track.get( track );
|
|
|
|
|
for ( int i = 0; i < target_curve.Length; i++ ) {
|
|
|
|
|
inv_bplist[i] = work.getCurve( target_curve[i] );
|
|
|
|
|
}
|
|
|
|
|
VsqCommand inv = VsqCommand.generateCommandTrackCurveReplaceRange( track, target_curve, inv_bplist );
|
|
|
|
|
for ( int i = 0; i < target_curve.Length; i++ ) {
|
|
|
|
|
work.setCurve( target_curve[i], bplist[i] );
|
|
|
|
|
}
|
|
|
|
|
return inv;
|
|
|
|
|
#endregion
|
|
|
|
|
} else if ( type == VsqCommandType.TRACK_CURVE_EDIT_RANGE ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region TRACK_CURVE_EDIT_RANGE
|
|
|
|
|
int track = (Integer)command.Args[0];
|
|
|
|
|
Vector<String> curves = (Vector<String>)command.Args[1];
|
|
|
|
|
Vector<Vector<BPPair>> coms = (Vector<Vector<BPPair>>)command.Args[2];
|
|
|
|
|
Vector<Vector<BPPair>> inv_coms = new Vector<Vector<BPPair>>();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqCommand inv = null;
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int count = curves.size();
|
|
|
|
|
for ( int k = 0; k < count; k++ ) {
|
|
|
|
|
String curve = curves.get( k );
|
|
|
|
|
Vector<BPPair> com = coms.get( k );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
//SortedList<int, int> list = Tracks[track][curve].List;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Vector<BPPair> edit = new Vector<BPPair>();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( com != null ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( com.size() > 0 ) {
|
|
|
|
|
int start_clock = com.get( 0 ).Clock;
|
|
|
|
|
int end_clock = com.get( 0 ).Clock;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator itr = com.iterator(); itr.hasNext(); ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
BPPair item = (BPPair)itr.next();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
start_clock = Math.Min( start_clock, item.Clock );
|
|
|
|
|
end_clock = Math.Max( end_clock, item.Clock );
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).setEditedStart( start_clock );
|
|
|
|
|
Track.get( track ).setEditedEnd( end_clock );
|
|
|
|
|
int start_value = Track.get( track ).getCurve( curve ).getValue( start_clock );
|
|
|
|
|
int end_value = Track.get( track ).getCurve( curve ).getValue( end_clock );
|
|
|
|
|
for ( Iterator itr = Track.get( track ).getCurve( curve ).keyClockIterator(); itr.hasNext(); ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int clock = (Integer)itr.next();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( start_clock <= clock && clock <= end_clock ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
edit.add( new BPPair( clock, Track.get( track ).getCurve( curve ).getValue( clock ) ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
boolean start_found = false;
|
|
|
|
|
boolean end_found = false;
|
|
|
|
|
for ( int i = 0; i < edit.size(); i++ ) {
|
|
|
|
|
if ( edit.get( i ).Clock == start_clock ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
start_found = true;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
edit.get( i ).Value = start_value;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( start_found && end_found ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( edit.get( i ).Clock == end_clock ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
end_found = true;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
edit.get( i ).Value = end_value;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( start_found && end_found ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( !start_found ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
edit.add( new BPPair( start_clock, start_value ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
if ( !end_found ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
edit.add( new BPPair( end_clock, end_value ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 並べ替え
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Collections.sort( edit );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
inv_coms.add( edit );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
//inv = generateCommandTrackEditCurve( track, curve, edit );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( com.size() == 0 ) {
|
|
|
|
|
//inv = generateCommandTrackEditCurve( track, curve, new Vector<BPPair>() );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
inv_coms.add( new Vector<BPPair>() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateTotalClocks();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( com.size() == 0 ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
return inv;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( com.size() == 1 ) {
|
|
|
|
|
boolean found = false;
|
|
|
|
|
for ( Iterator itr = Track.get( track ).getCurve( curve ).keyClockIterator(); itr.hasNext(); ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int clock = (Integer)itr.next();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( clock == com.get( 0 ).Clock ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
found = true;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).getCurve( curve ).add( clock, com.get( 0 ).Value );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( !found ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).getCurve( curve ).add( com.get( 0 ).Clock, com.get( 0 ).Value );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int start_clock = com.get( 0 ).Clock;
|
|
|
|
|
int end_clock = com.get( com.size() - 1 ).Clock;
|
|
|
|
|
boolean removed = true;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
while ( removed ) {
|
|
|
|
|
removed = false;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( Iterator itr = Track.get( track ).getCurve( curve ).keyClockIterator(); itr.hasNext(); ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int clock = (Integer)itr.next();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( start_clock <= clock && clock <= end_clock ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).getCurve( curve ).remove( clock );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
removed = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator itr = com.iterator(); itr.hasNext(); ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
BPPair item = (BPPair)itr.next();
|
|
|
|
|
Track.get( track ).getCurve( curve ).add( item.Clock, item.Value );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
return VsqCommand.generateCommandTrackCurveEditRange( track, curves, inv_coms );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_CHANGE_VELOCITY ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_CHANGE_VELOCITY
|
|
|
|
|
int track = (Integer)command.Args[0];
|
|
|
|
|
Vector<ValuePair<Integer, Integer>> veloc = (Vector<ValuePair<Integer, Integer>>)command.Args[1];
|
|
|
|
|
Vector<ValuePair<Integer, Integer>> inv = new Vector<ValuePair<Integer, Integer>>();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( Iterator itr = Track.get( track ).getEventIterator(); itr.hasNext(); ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent ev = (VsqEvent)itr.next();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator itr2 = veloc.iterator(); itr2.hasNext(); ) {
|
|
|
|
|
ValuePair<Integer, Integer> add = (ValuePair<Integer, Integer>)itr2.next();
|
|
|
|
|
if ( ev.InternalID == add.getKey() ) {
|
|
|
|
|
inv.add( new ValuePair<Integer, Integer>( ev.InternalID, ev.ID.Dynamics ) );
|
|
|
|
|
ev.ID.Dynamics = add.getValue();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).setEditedStart( ev.Clock );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Track.get( track ).setEditedEnd( ev.Clock + ev.ID.getLength() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return VsqCommand.generateCommandEventChangeVelocity( track, inv );
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_CHANGE_ACCENT ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_CHANGE_ACCENT
|
|
|
|
|
int track = (Integer)command.Args[0];
|
|
|
|
|
Vector<ValuePair<Integer, Integer>> veloc = (Vector<ValuePair<Integer, Integer>>)command.Args[1];
|
|
|
|
|
Vector<ValuePair<Integer, Integer>> inv = new Vector<ValuePair<Integer, Integer>>();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( Iterator itr = Track.get( track ).getEventIterator(); itr.hasNext(); ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent ev = (VsqEvent)itr.next();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator itr2 = veloc.iterator(); itr2.hasNext(); ) {
|
|
|
|
|
ValuePair<Integer, Integer> add = (ValuePair<Integer, Integer>)itr2.next();
|
|
|
|
|
if ( ev.InternalID == add.getKey() ) {
|
|
|
|
|
inv.add( new ValuePair<Integer, Integer>( ev.InternalID, ev.ID.DEMaccent ) );
|
|
|
|
|
ev.ID.DEMaccent = add.getValue();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).setEditedStart( ev.Clock );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Track.get( track ).setEditedEnd( ev.Clock + ev.ID.getLength() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return VsqCommand.generateCommandEventChangeAccent( track, inv );
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_CHANGE_DECAY ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_CHANGE_DECAY
|
|
|
|
|
int track = (Integer)command.Args[0];
|
|
|
|
|
Vector<ValuePair<Integer, Integer>> veloc = (Vector<ValuePair<Integer, Integer>>)command.Args[1];
|
|
|
|
|
Vector<ValuePair<Integer, Integer>> inv = new Vector<ValuePair<Integer, Integer>>();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( Iterator itr = Track.get( track ).getEventIterator(); itr.hasNext(); ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent ev = (VsqEvent)itr.next();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator itr2 = veloc.iterator(); itr2.hasNext(); ) {
|
|
|
|
|
ValuePair<Integer, Integer> add = (ValuePair<Integer, Integer>)itr2.next();
|
|
|
|
|
if ( ev.InternalID == add.getKey() ) {
|
|
|
|
|
inv.add( new ValuePair<Integer, Integer>( ev.InternalID, ev.ID.DEMdecGainRate ) );
|
|
|
|
|
ev.ID.DEMdecGainRate = add.getValue();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).setEditedStart( ev.Clock );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Track.get( track ).setEditedEnd( ev.Clock + ev.ID.getLength() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return VsqCommand.generateCommandEventChangeDecay( track, inv );
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_CHANGE_LENGTH ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_CHANGE_LENGTH
|
|
|
|
|
int track = (Integer)command.Args[0];
|
|
|
|
|
int internal_id = (Integer)command.Args[1];
|
|
|
|
|
int new_length = (Integer)command.Args[2];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( Iterator itr = Track.get( track ).getEventIterator(); itr.hasNext(); ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent item = (VsqEvent)itr.next();
|
|
|
|
|
if ( item.InternalID == internal_id ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
VsqCommand ret = VsqCommand.generateCommandEventChangeLength( track, internal_id, item.ID.getLength() );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).setEditedStart( item.Clock );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int max = Math.Max( item.Clock + item.ID.getLength(), item.Clock + new_length );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).setEditedEnd( max );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
item.ID.setLength( new_length );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
updateTotalClocks();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_CHANGE_CLOCK_AND_LENGTH ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_CHANGE_CLOCK_AND_LENGTH
|
|
|
|
|
int track = (Integer)command.Args[0];
|
|
|
|
|
int internal_id = (Integer)command.Args[1];
|
|
|
|
|
int new_clock = (Integer)command.Args[2];
|
|
|
|
|
int new_length = (Integer)command.Args[3];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( Iterator itr = Track.get( track ).getEventIterator(); itr.hasNext(); ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent item = (VsqEvent)itr.next();
|
|
|
|
|
if ( item.InternalID == internal_id ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
VsqCommand ret = VsqCommand.generateCommandEventChangeClockAndLength( track, internal_id, item.Clock, item.ID.getLength() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int min = Math.Min( item.Clock, new_clock );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int max_length = Math.Max( item.ID.getLength(), new_length );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int max = Math.Max( item.Clock + max_length, new_clock + max_length );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).setEditedStart( min );
|
|
|
|
|
Track.get( track ).setEditedEnd( max );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
item.ID.setLength( new_length );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
item.Clock = new_clock;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).sortEvent();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
updateTotalClocks();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_CHANGE_ID_CONTAINTS ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_CHANGE_ID_CONTAINTS
|
|
|
|
|
int track = (Integer)command.Args[0];
|
|
|
|
|
int internal_id = (Integer)command.Args[1];
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqID value = (VsqID)command.Args[2];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( Iterator itr = Track.get( track ).getEventIterator(); itr.hasNext(); ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent item = (VsqEvent)itr.next();
|
|
|
|
|
if ( item.InternalID == internal_id ) {
|
|
|
|
|
VsqCommand ret = VsqCommand.generateCommandEventChangeIDContaints( track, internal_id, item.ID );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int max_length = Math.Max( item.ID.getLength(), value.getLength() );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).setEditedStart( item.Clock );
|
|
|
|
|
Track.get( track ).setEditedEnd( item.Clock + max_length );
|
|
|
|
|
item.ID = (VsqID)value.clone();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( item.ID.type == VsqIDType.Singer ) {
|
|
|
|
|
#if DEBUG
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.println( " EventChangeIDContaints" );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endif
|
|
|
|
|
// 歌手変更の場合、次に現れる歌手変更の位置まで編集の影響が及ぶ
|
2009-09-07 03:44:18 -07:00
|
|
|
|
boolean found = false;
|
|
|
|
|
for ( Iterator itr2 = Track.get( track ).getSingerEventIterator(); itr2.hasNext(); ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent item2 = (VsqEvent)itr2.next();
|
|
|
|
|
if ( item.Clock < item2.Clock ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).setEditedEnd( item2.Clock );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( !found ) {
|
|
|
|
|
// 変更対象が、該当トラック最後の歌手変更イベントだった場合
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( Track.get( track ).getEventCount() >= 1 ) {
|
|
|
|
|
VsqEvent last_event = Track.get( track ).getEvent( Track.get( track ).getEventCount() - 1 );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Track.get( track ).setEditedEnd( last_event.Clock + last_event.ID.getLength() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#if DEBUG
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.println( " EditedStart,EditedEnd=" + Track.get( track ).getEditedStart() + "," + Track.get( track ).getEditedEnd() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
updateTotalClocks();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_CHANGE_ID_CONTAINTS_RANGE ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_CHANGE_ID_CONTAINTS_RANGE
|
|
|
|
|
int track = (Integer)command.Args[0];
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int[] internal_ids = (int[])command.Args[1];
|
|
|
|
|
VsqID[] values = (VsqID[])command.Args[2];
|
|
|
|
|
VsqID[] inv_values = new VsqID[values.Length];
|
|
|
|
|
for ( int i = 0; i < internal_ids.Length; i++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( Iterator itr = Track.get( track ).getEventIterator(); itr.hasNext(); ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent item = (VsqEvent)itr.next();
|
|
|
|
|
if ( item.InternalID == internal_ids[i] ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
inv_values[i] = (VsqID)item.ID.clone();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int max_length = Math.Max( item.ID.getLength(), values[i].getLength() );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).setEditedStart( item.Clock );
|
|
|
|
|
Track.get( track ).setEditedEnd( item.Clock + max_length );
|
|
|
|
|
item.ID = (VsqID)values[i].clone();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( item.ID.type == VsqIDType.Singer ) {
|
|
|
|
|
// 歌手変更の場合、次に現れる歌手変更の位置まで編集の影響が及ぶ
|
2009-09-07 03:44:18 -07:00
|
|
|
|
boolean found = false;
|
|
|
|
|
for ( Iterator itr2 = Track.get( track ).getSingerEventIterator(); itr2.hasNext(); ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent item2 = (VsqEvent)itr2.next();
|
|
|
|
|
if ( item.Clock < item2.Clock ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).setEditedEnd( item2.Clock );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( !found ) {
|
|
|
|
|
// 変更対象が、該当トラック最後の歌手変更イベントだった場合
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( Track.get( track ).getEventCount() >= 1 ) {
|
|
|
|
|
VsqEvent last_event = Track.get( track ).getEvent( Track.get( track ).getEventCount() - 1 );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Track.get( track ).setEditedEnd( last_event.Clock + last_event.ID.getLength() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
updateTotalClocks();
|
|
|
|
|
return VsqCommand.generateCommandEventChangeIDContaintsRange( track, internal_ids, inv_values );
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_CHANGE_CLOCK_AND_ID_CONTAINTS ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_CHANGE_CLOCK_AND_ID_CONTAINTS
|
|
|
|
|
int track = (Integer)command.Args[0];
|
|
|
|
|
int internal_id = (Integer)command.Args[1];
|
|
|
|
|
int new_clock = (Integer)command.Args[2];
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqID value = (VsqID)command.Args[3];
|
2010-03-16 20:14:08 -07:00
|
|
|
|
VsqTrack target = Track.get( track );
|
|
|
|
|
for ( Iterator itr = target.getEventIterator(); itr.hasNext(); ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent item = (VsqEvent)itr.next();
|
|
|
|
|
if ( item.InternalID == internal_id ) {
|
|
|
|
|
VsqCommand ret = VsqCommand.generateCommandEventChangeClockAndIDContaints( track, internal_id, item.Clock, item.ID );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int max_length = Math.Max( item.ID.getLength(), value.getLength() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int min = Math.Min( item.Clock, new_clock );
|
|
|
|
|
int max = Math.Max( item.Clock + max_length, new_clock + max_length );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
item.ID = (VsqID)value.clone();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
item.Clock = new_clock;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
target.setEditedStart( min );
|
|
|
|
|
target.setEditedEnd( max );
|
|
|
|
|
target.sortEvent();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
updateTotalClocks();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_CHANGE_CLOCK_AND_ID_CONTAINTS_RANGE ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_CHANGE_CLOCK_AND_ID_CONTAINTS_RANGE
|
|
|
|
|
int track = (Integer)command.Args[0];
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int[] internal_ids = (int[])command.Args[1];
|
|
|
|
|
int[] clocks = (int[])command.Args[2];
|
|
|
|
|
VsqID[] values = (VsqID[])command.Args[3];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Vector<VsqID> inv_id = new Vector<VsqID>();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Vector<Integer> inv_clock = new Vector<Integer>();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
for ( int i = 0; i < internal_ids.Length; i++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( Iterator itr = Track.get( track ).getEventIterator(); itr.hasNext(); ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent item = (VsqEvent)itr.next();
|
|
|
|
|
if ( item.InternalID == internal_ids[i] ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
inv_id.add( (VsqID)item.ID.clone() );
|
|
|
|
|
inv_clock.add( item.Clock );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int max_length = Math.Max( item.ID.getLength(), values[i].getLength() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int min = Math.Min( item.Clock, clocks[i] );
|
|
|
|
|
int max = Math.Max( item.Clock + max_length, clocks[i] + max_length );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).setEditedStart( min );
|
|
|
|
|
Track.get( track ).setEditedEnd( max );
|
|
|
|
|
item.ID = (VsqID)values[i].clone();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
item.Clock = clocks[i];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).sortEvent();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
updateTotalClocks();
|
|
|
|
|
return VsqCommand.generateCommandEventChangeClockAndIDContaintsRange(
|
|
|
|
|
track,
|
|
|
|
|
internal_ids,
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.convertIntArray( inv_clock.toArray( new Integer[] { } ) ),
|
|
|
|
|
inv_id.toArray( new VsqID[] { } ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#if DEBUG
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.println( " TrackChangeClockAndIDContaintsRange" );
|
|
|
|
|
PortUtil.println( " track=" + track );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
for ( int i = 0; i < internal_ids.Length; i++ ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.println( " id=" + internal_ids[i] + "; clock=" + clocks[i] + "; ID=" + values[i].ToString() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.TRACK_CHANGE_NAME ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region TRACK_CHANGE_NAME
|
|
|
|
|
int track = (Integer)command.Args[0];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String new_name = (String)command.Args[1];
|
|
|
|
|
VsqCommand ret = VsqCommand.generateCommandTrackChangeName( track, Track.get( track ).getName() );
|
|
|
|
|
Track.get( track ).setName( new_name );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
return ret;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.TRACK_REPLACE ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region TRACK_REPLACE
|
|
|
|
|
int track = (Integer)command.Args[0];
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqTrack item = (VsqTrack)command.Args[1];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqCommand ret = VsqCommand.generateCommandTrackReplace( track, Track.get( track ) );
|
|
|
|
|
Track.set( track, item );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
updateTotalClocks();
|
|
|
|
|
return ret;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.TRACK_CHANGE_PLAY_MODE ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region TRACK_CHANGE_PLAY_MODE
|
|
|
|
|
int track = (Integer)command.Args[0];
|
|
|
|
|
int play_mode = (Integer)command.Args[1];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqCommand ret = VsqCommand.generateCommandTrackChangePlayMode( track, Track.get( track ).getCommon().PlayMode );
|
|
|
|
|
Track.get( track ).getCommon().PlayMode = play_mode;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
return ret;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_REPLACE ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_REPLACE
|
|
|
|
|
int track = (Integer)command.Args[0];
|
2009-07-29 10:03:20 -07:00
|
|
|
|
VsqEvent item = (VsqEvent)command.Args[1];
|
|
|
|
|
VsqCommand ret = null;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int i = 0; i < Track.get( track ).getEventCount(); i++ ) {
|
|
|
|
|
VsqEvent ve = Track.get( track ).getEvent( i );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
if ( ve.InternalID == item.InternalID ) {
|
|
|
|
|
ret = VsqCommand.generateCommandEventReplace( track, ve );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).setEvent( i, item );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).sortEvent();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
updateTotalClocks();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
return ret;
|
|
|
|
|
#endregion
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( type == VsqCommandType.EVENT_REPLACE_RANGE ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#region EVENT_REPLACE_RANGE
|
|
|
|
|
int track = (Integer)command.Args[0];
|
|
|
|
|
VsqEvent[] items = (VsqEvent[])command.Args[1];
|
2009-07-29 10:03:20 -07:00
|
|
|
|
VsqCommand ret = null;
|
|
|
|
|
VsqEvent[] reverse = new VsqEvent[items.Length];
|
|
|
|
|
for ( int i = 0; i < items.Length; i++ ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
VsqEvent ve = items[i];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int j = 0; j < Track.get( track ).getEventCount(); j++ ) {
|
|
|
|
|
VsqEvent ve2 = (VsqEvent)Track.get( track ).getEvent( j );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
if ( ve2.InternalID == ve.InternalID ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
reverse[i] = (VsqEvent)ve2.clone();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Track.get( track ).setEvent( j, items[i] );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).sortEvent();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
updateTotalClocks();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
ret = VsqCommand.generateCommandEventReplaceRange( track, reverse );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
return ret;
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
private void processTrackCurveEdit( int track,
|
|
|
|
|
String curve,
|
|
|
|
|
Vector<Long> delete,
|
|
|
|
|
TreeMap<Integer, VsqBPPair> add,
|
|
|
|
|
Vector<Long> inv_delete,
|
|
|
|
|
TreeMap<Integer, VsqBPPair> inv_add ){
|
|
|
|
|
VsqBPList list = Track.get( track ).getCurve( curve );
|
|
|
|
|
|
|
|
|
|
// 現在の編集範囲を取得
|
|
|
|
|
int edited_start = Track.get( track ).getEditedStart();
|
|
|
|
|
int edited_end = Track.get( track ).getEditedEnd();
|
|
|
|
|
|
|
|
|
|
// 逆コマンド発行用
|
|
|
|
|
inv_delete.clear();
|
|
|
|
|
inv_add.clear();
|
|
|
|
|
|
|
|
|
|
// 最初に削除コマンドを実行
|
|
|
|
|
for ( Iterator itr = delete.iterator(); itr.hasNext(); ) {
|
|
|
|
|
long id = (Long)itr.next();
|
|
|
|
|
VsqBPPairSearchContext item = list.findElement( id );
|
|
|
|
|
if ( item.index >= 0 ) {
|
|
|
|
|
int clock = item.clock;
|
|
|
|
|
list.removeElementAt( item.index );
|
|
|
|
|
inv_add.put( clock, new VsqBPPair( item.point.value, item.point.id ) );
|
|
|
|
|
edited_start = Math.Min( edited_start, clock );
|
|
|
|
|
edited_end = Math.Max( edited_end, clock );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 追加コマンドを実行
|
|
|
|
|
for ( Iterator itr = add.keySet().iterator(); itr.hasNext(); ) {
|
|
|
|
|
int clock = (Integer)itr.next();
|
|
|
|
|
VsqBPPair item = add.get( clock );
|
|
|
|
|
list.addWithID( clock, item.value, item.id );
|
|
|
|
|
inv_delete.add( item.id );
|
|
|
|
|
edited_start = Math.Min( edited_start, clock );
|
|
|
|
|
edited_end = Math.Max( edited_end, clock );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 編集範囲の更新
|
|
|
|
|
Track.get( track ).setEditedStart( edited_start );
|
|
|
|
|
Track.get( track ).setEditedEnd( edited_end );
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// VSQファイルの指定されたクロック範囲のイベント等を削除します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="vsq">編集対象のVsqFileインスタンス</param>
|
|
|
|
|
/// <param name="clock_start">削除を行う範囲の開始クロック</param>
|
|
|
|
|
/// <param name="clock_end">削除を行う範囲の終了クロック</param>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public void removePart( int clock_start, int clock_end ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int dclock = clock_end - clock_start;
|
|
|
|
|
|
|
|
|
|
// テンポ情報の削除、シフト
|
2009-09-07 03:44:18 -07:00
|
|
|
|
boolean changed = true;
|
|
|
|
|
Vector<TempoTableEntry> buf = new Vector<TempoTableEntry>( TempoTable );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
int tempo_at_clock_start = getTempoAt( clock_start );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
int tempo_at_clock_end = getTempoAt( clock_end );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTable.clear();
|
|
|
|
|
boolean just_on_clock_end_added = false;
|
|
|
|
|
for ( int i = 0; i < buf.size(); i++ ) {
|
|
|
|
|
if ( buf.get( i ).Clock < clock_start ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
TempoTable.add( (TempoTableEntry)buf.get( i ).clone() );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else if ( clock_end <= buf.get( i ).Clock ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
TempoTableEntry tte = (TempoTableEntry)buf.get( i ).clone();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
tte.Clock = tte.Clock - dclock;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( clock_end == buf.get( i ).Clock ) {
|
|
|
|
|
TempoTable.add( tte );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
just_on_clock_end_added = true;
|
|
|
|
|
} else {
|
2009-07-30 08:02:59 -07:00
|
|
|
|
if ( tempo_at_clock_start != tempo_at_clock_end ) {
|
|
|
|
|
if ( !just_on_clock_end_added ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTable.add( new TempoTableEntry( clock_start, tempo_at_clock_end, 0.0 ) );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
just_on_clock_end_added = true;
|
|
|
|
|
}
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTable.add( tte );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-30 08:02:59 -07:00
|
|
|
|
if ( tempo_at_clock_start != tempo_at_clock_end && !just_on_clock_end_added ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTable.add( new TempoTableEntry( clock_start, tempo_at_clock_end, 0.0 ) );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
updateTempoInfo();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int track = 1; track < Track.size(); track++ ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
// 削除する範囲に歌手変更イベントが存在するかどうかを検査。
|
|
|
|
|
VsqEvent t_last_singer = null;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( Iterator itr = Track.get( track ).getSingerEventIterator(); itr.hasNext(); ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent ve = (VsqEvent)itr.next();
|
|
|
|
|
if ( clock_start <= ve.Clock && ve.Clock < clock_end ) {
|
|
|
|
|
t_last_singer = ve;
|
|
|
|
|
}
|
|
|
|
|
if ( ve.Clock == clock_end ) {
|
|
|
|
|
t_last_singer = null; // 後でclock_endの位置に補うが、そこにに既に歌手変更イベントがあるとまずいので。
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
VsqEvent last_singer = null;
|
|
|
|
|
if ( t_last_singer != null ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
last_singer = (VsqEvent)t_last_singer.clone();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
last_singer.Clock = clock_end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
changed = true;
|
|
|
|
|
// イベントの削除
|
|
|
|
|
while ( changed ) {
|
|
|
|
|
changed = false;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int i = 0; i < Track.get( track ).getEventCount(); i++ ) {
|
|
|
|
|
if ( clock_start <= Track.get( track ).getEvent( i ).Clock && Track.get( track ).getEvent( i ).Clock < clock_end ) {
|
|
|
|
|
Track.get( track ).removeEvent( i );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
changed = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// クロックのシフト
|
|
|
|
|
if ( last_singer != null ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).addEvent( last_singer ); //歌手変更イベントを補う
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int i = 0; i < Track.get( track ).getEventCount(); i++ ) {
|
|
|
|
|
if ( clock_end <= Track.get( track ).getEvent( i ).Clock ) {
|
|
|
|
|
Track.get( track ).getEvent( i ).Clock -= dclock;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( int i = 0; i < _CURVES.Length; i++ ) {
|
|
|
|
|
String curve = _CURVES[i];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( curve.Equals( "VEL" ) ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
VsqBPList buf_bplist = (VsqBPList)Track.get( track ).getCurve( curve ).clone();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).getCurve( curve ).clear();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
int value_at_end = buf_bplist.getValue( clock_end );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
boolean at_end_added = false;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
for ( Iterator itr = buf_bplist.keyClockIterator(); itr.hasNext(); ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int key = (Integer)itr.next();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( key < clock_start ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).getCurve( curve ).add( key, buf_bplist.getValue( key ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
} else if ( clock_end <= key ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
if ( key == clock_end ) {
|
|
|
|
|
at_end_added = true;
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).getCurve( curve ).add( key - dclock, buf_bplist.getValue( key ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-29 10:03:20 -07:00
|
|
|
|
if ( !at_end_added ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).getCurve( curve ).add( clock_end - dclock, value_at_end );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// vsqファイル全体のイベントを,指定したクロックだけ遅らせます.
|
|
|
|
|
/// ただし,曲頭のテンポ変更イベントと歌手変更イベントはクロック0から移動しません.
|
|
|
|
|
/// この操作を行うことで,TimesigTableの情報は破綻します(仕様です).
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="delta_clock"></param>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public static void shift( VsqFile vsq, int delta_clock ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( delta_clock == 0 ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int dclock = (int)delta_clock;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int i = 0; i < vsq.TempoTable.size(); i++ ) {
|
|
|
|
|
if ( vsq.TempoTable.get( i ).Clock > 0 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
vsq.TempoTable.get( i ).Clock = vsq.TempoTable.get( i ).Clock + dclock;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
vsq.updateTempoInfo();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int track = 1; track < vsq.Track.size(); track++ ) {
|
|
|
|
|
for ( int i = 0; i < vsq.Track.get( track ).getEventCount(); i++ ) {
|
|
|
|
|
if ( vsq.Track.get( track ).getEvent( i ).Clock > 0 ) {
|
|
|
|
|
vsq.Track.get( track ).getEvent( i ).Clock += dclock;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( int i = 0; i < _CURVES.Length; i++ ) {
|
|
|
|
|
String curve = _CURVES[i];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( curve.Equals( "VEL" ) ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
continue;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
// 順番に+=dclockしていくとVsqBPList内部のSortedListの値がかぶる可能性がある.
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqBPList edit = vsq.Track.get( track ).getCurve( curve );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqBPList new_one = new VsqBPList( edit.getDefault(), edit.getMinimum(), edit.getMaximum() );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator itr2 = edit.keyClockIterator(); itr2.hasNext(); ) {
|
|
|
|
|
int key = (Integer)itr2.next();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
new_one.add( key + dclock, edit.getValue( key ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
vsq.Track.get( track ).setCurve( curve, new_one );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
vsq.updateTotalClocks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// このインスタンスのコピーを作成します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>このインスタンスのコピー</returns>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public Object clone() {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqFile ret = new VsqFile();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
ret.Track = new Vector<VsqTrack>();
|
|
|
|
|
for ( int i = 0; i < Track.size(); i++ ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
ret.Track.add( (VsqTrack)Track.get( i ).clone() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
ret.TempoTable = new Vector<TempoTableEntry>();
|
|
|
|
|
for ( int i = 0; i < TempoTable.size(); i++ ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
ret.TempoTable.add( (TempoTableEntry)TempoTable.get( i ).clone() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
ret.TimesigTable = new Vector<TimeSigTableEntry>();
|
|
|
|
|
for ( int i = 0; i < TimesigTable.size(); i++ ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
ret.TimesigTable.add( (TimeSigTableEntry)TimesigTable.get( i ).clone() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
ret.m_tpq = m_tpq;
|
|
|
|
|
ret.TotalClocks = TotalClocks;
|
|
|
|
|
ret.m_base_tempo = m_base_tempo;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
ret.Master = (VsqMaster)Master.clone();
|
|
|
|
|
ret.Mixer = (VsqMixer)Mixer.clone();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
//ret.m_premeasure_clocks = m_premeasure_clocks;
|
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
|
|
|
|
private VsqFile() {
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if JAVA
|
|
|
|
|
private class BarLineIterator implements Iterator{
|
|
|
|
|
#else
|
2009-06-25 07:16:22 -07:00
|
|
|
|
private class BarLineIterator : Iterator {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|
2009-09-07 03:44:18 -07:00
|
|
|
|
private Vector<TimeSigTableEntry> m_list;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
private int m_end_clock;
|
|
|
|
|
private int i;
|
|
|
|
|
private int clock;
|
|
|
|
|
int local_denominator;
|
|
|
|
|
int local_numerator;
|
|
|
|
|
int clock_step;
|
|
|
|
|
int t_end;
|
|
|
|
|
int local_clock;
|
|
|
|
|
int bar_counter;
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public BarLineIterator( Vector<TimeSigTableEntry> list, int end_clock ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
m_list = list;
|
|
|
|
|
m_end_clock = end_clock;
|
|
|
|
|
i = 0;
|
|
|
|
|
t_end = -1;
|
|
|
|
|
clock = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Object next() {
|
|
|
|
|
int mod = clock_step * local_numerator;
|
|
|
|
|
if ( clock < t_end ) {
|
|
|
|
|
if ( (clock - local_clock) % mod == 0 ) {
|
|
|
|
|
bar_counter++;
|
|
|
|
|
VsqBarLineType ret = new VsqBarLineType( clock, true, local_denominator, local_numerator, bar_counter );
|
|
|
|
|
clock += clock_step;
|
|
|
|
|
return ret;
|
|
|
|
|
} else {
|
|
|
|
|
VsqBarLineType ret = new VsqBarLineType( clock, false, local_denominator, local_numerator, bar_counter );
|
|
|
|
|
clock += clock_step;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( i < m_list.size() ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
local_denominator = m_list.get( i ).Denominator;
|
|
|
|
|
local_numerator = m_list.get( i ).Numerator;
|
|
|
|
|
local_clock = m_list.get( i ).Clock;
|
|
|
|
|
int local_bar_count = m_list.get( i ).BarCount;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
clock_step = 480 * 4 / local_denominator;
|
|
|
|
|
mod = clock_step * local_numerator;
|
|
|
|
|
bar_counter = local_bar_count - 1;
|
|
|
|
|
t_end = m_end_clock;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( i + 1 < m_list.size() ) {
|
|
|
|
|
t_end = m_list.get( i + 1 ).Clock;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
clock = local_clock;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( clock < t_end ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( (clock - local_clock) % mod == 0 ) {
|
|
|
|
|
bar_counter++;
|
|
|
|
|
VsqBarLineType ret = new VsqBarLineType( clock, true, local_denominator, local_numerator, bar_counter );
|
|
|
|
|
clock += clock_step;
|
|
|
|
|
return ret;
|
|
|
|
|
} else {
|
|
|
|
|
VsqBarLineType ret = new VsqBarLineType( clock, false, local_denominator, local_numerator, bar_counter );
|
|
|
|
|
clock += clock_step;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void remove() {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
//throw new Exception( "com.boare.vsq.VsqFile.BarLineIterator#remove; not implemented" );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public boolean hasNext() {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( clock < m_end_clock ) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 小節の区切りを順次返すIterator。
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Iterator getBarLineIterator( int end_clock ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
return new BarLineIterator( TimesigTable, end_clock );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 基本テンポ値を取得します
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int getBaseTempo() {
|
|
|
|
|
return m_base_tempo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// プリメジャー値を取得します
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int getPreMeasure() {
|
|
|
|
|
return Master.PreMeasure;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// プリメジャー部分の長さをクロックに変換した値を取得します.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int getPreMeasureClocks() {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
return calculatePreMeasureInClock();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// プリメジャーの長さ(クロック)を計算します。
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int calculatePreMeasureInClock() {
|
|
|
|
|
int pre_measure = Master.PreMeasure;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int last_bar_count = TimesigTable.get( 0 ).BarCount;
|
|
|
|
|
int last_clock = TimesigTable.get( 0 ).Clock;
|
|
|
|
|
int last_denominator = TimesigTable.get( 0 ).Denominator;
|
|
|
|
|
int last_numerator = TimesigTable.get( 0 ).Numerator;
|
|
|
|
|
for ( int i = 1; i < TimesigTable.size(); i++ ) {
|
|
|
|
|
if ( TimesigTable.get( i ).BarCount >= pre_measure ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
break;
|
|
|
|
|
} else {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
last_bar_count = TimesigTable.get( i ).BarCount;
|
|
|
|
|
last_clock = TimesigTable.get( i ).Clock;
|
|
|
|
|
last_denominator = TimesigTable.get( i ).Denominator;
|
|
|
|
|
last_numerator = TimesigTable.get( i ).Numerator;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int remained = pre_measure - last_bar_count;//プリメジャーの終わりまでの残り小節数
|
|
|
|
|
return last_clock + remained * last_numerator * 480 * 4 / last_denominator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定したクロックにおける、clock=0からの演奏経過時間(sec)を取得します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="clock"></param>
|
|
|
|
|
/// <returns></returns>
|
2009-07-29 10:03:20 -07:00
|
|
|
|
public double getSecFromClock( double clock ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int c = TempoTable.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = c - 1; i >= 0; i-- ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTableEntry item = TempoTable.get( i );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
if ( item.Clock < clock ) {
|
|
|
|
|
double init = item.Time;
|
|
|
|
|
double dclock = clock - item.Clock;
|
|
|
|
|
double sec_per_clock1 = item.Tempo * 1e-6 / 480.0;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
return init + dclock * sec_per_clock1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double sec_per_clock = m_base_tempo * 1e-6 / 480.0;
|
|
|
|
|
return clock * sec_per_clock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定した時刻における、クロックを取得します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="time"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public double getClockFromSec( double time ) {
|
|
|
|
|
// timeにおけるテンポを取得
|
|
|
|
|
int tempo = m_base_tempo;
|
|
|
|
|
double base_clock = 0;
|
|
|
|
|
double base_time = 0f;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int c = TempoTable.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
if ( c == 0 ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
tempo = m_base_tempo;
|
|
|
|
|
base_clock = 0;
|
|
|
|
|
base_time = 0f;
|
2009-07-30 08:02:59 -07:00
|
|
|
|
} else if ( c == 1 ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
tempo = TempoTable.get( 0 ).Tempo;
|
|
|
|
|
base_clock = TempoTable.get( 0 ).Clock;
|
|
|
|
|
base_time = TempoTable.get( 0 ).Time;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
} else {
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = c - 1; i >= 0; i-- ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTableEntry item = TempoTable.get( i );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
if ( item.Time < time ) {
|
|
|
|
|
return item.Clock + (time - item.Time) * m_tpq * 1000000.0 / item.Tempo;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
double dt = time - base_time;
|
|
|
|
|
return base_clock + dt * m_tpq * 1000000.0 / (double)tempo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定したクロックにおける拍子を取得します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="clock"></param>
|
|
|
|
|
/// <param name="numerator"></param>
|
|
|
|
|
/// <param name="denominator"></param>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public Timesig getTimesigAt( int clock ) {
|
|
|
|
|
Timesig ret = new Timesig();
|
|
|
|
|
ret.numerator = 4;
|
|
|
|
|
ret.denominator = 4;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int index = 0;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int c = TimesigTable.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = c - 1; i >= 0; i-- ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
index = i;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( TimesigTable.get( i ).Clock <= clock ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
ret.numerator = TimesigTable.get( index ).Numerator;
|
|
|
|
|
ret.denominator = TimesigTable.get( index ).Denominator;
|
|
|
|
|
return ret;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public Timesig getTimesigAt( int clock, ByRef<Integer> bar_count ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
int index = 0;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int c = TimesigTable.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = c - 1; i >= 0; i-- ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
index = i;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( TimesigTable.get( i ).Clock <= clock ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TimeSigTableEntry item = TimesigTable.get( index );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Timesig ret = new Timesig();
|
|
|
|
|
ret.numerator = item.Numerator;
|
|
|
|
|
ret.denominator = item.Denominator;
|
2009-07-30 08:02:59 -07:00
|
|
|
|
int diff = clock - item.Clock;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int clock_per_bar = 480 * 4 / ret.denominator * ret.numerator;
|
|
|
|
|
bar_count.value = item.BarCount + diff / clock_per_bar;
|
|
|
|
|
return ret;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定したクロックにおけるテンポを取得します。
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="clock"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int getTempoAt( int clock ) {
|
|
|
|
|
int index = 0;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int c = TempoTable.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = c - 1; i >= 0; i-- ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
index = i;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( TempoTable.get( i ).Clock <= clock ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
return TempoTable.get( index ).Tempo;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定した小節の開始クロックを調べます。ここで使用する小節数は、プリメジャーを考慮しない。即ち、曲頭の小節が0である。
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bar_count"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int getClockFromBarCount( int bar_count ) {
|
|
|
|
|
int index = 0;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int c = TimesigTable.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = c - 1; i >= 0; i-- ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
index = i;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( TimesigTable.get( i ).BarCount <= bar_count ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TimeSigTableEntry item = TimesigTable.get( index );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
int numerator = item.Numerator;
|
|
|
|
|
int denominator = item.Denominator;
|
|
|
|
|
int init_clock = item.Clock;
|
|
|
|
|
int init_bar_count = item.BarCount;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int clock_per_bar = numerator * 480 * 4 / denominator;
|
|
|
|
|
return init_clock + (bar_count - init_bar_count) * clock_per_bar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定したクロックが、曲頭から何小節目に属しているかを調べます。ここで使用する小節数は、プリメジャーを考慮しない。即ち、曲頭の小節が0である。
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="clock"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int getBarCountFromClock( int clock ) {
|
|
|
|
|
int index = 0;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int c = TimesigTable.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = c - 1; i >= 0; i-- ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
index = i;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( TimesigTable.get( i ).Clock <= clock ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int bar_count = 0;
|
|
|
|
|
if ( index >= 0 ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int last_clock = TimesigTable.get( index ).Clock;
|
|
|
|
|
int t_bar_count = TimesigTable.get( index ).BarCount;
|
|
|
|
|
int numerator = TimesigTable.get( index ).Numerator;
|
|
|
|
|
int denominator = TimesigTable.get( index ).Denominator;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int clock_per_bar = numerator * 480 * 4 / denominator;
|
|
|
|
|
bar_count = t_bar_count + (clock - last_clock) / clock_per_bar;
|
|
|
|
|
}
|
|
|
|
|
return bar_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 4分の1拍子1音あたりのクロック数を取得します
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int getTickPerQuarter() {
|
|
|
|
|
return m_tpq;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 空のvsqファイルを構築します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pre_measure"></param>
|
|
|
|
|
/// <param name="numerator"></param>
|
|
|
|
|
/// <param name="denominator"></param>
|
|
|
|
|
/// <param name="tempo"></param>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public VsqFile( String singer, int pre_measure, int numerator, int denominator, int tempo ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
TotalClocks = pre_measure * 480 * 4 / denominator * numerator;
|
|
|
|
|
m_tpq = 480;
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track = new Vector<VsqTrack>();
|
|
|
|
|
Track.add( new VsqTrack( tempo, numerator, denominator ) );
|
|
|
|
|
Track.add( new VsqTrack( "Voice1", singer ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
Master = new VsqMaster( pre_measure );
|
|
|
|
|
#if DEBUG
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.println( "VsqFile.ctor()" );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endif
|
|
|
|
|
Mixer = new VsqMixer( 0, 0, 0, 0 );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Mixer.Slave.add( new VsqMixerEntry( 0, 0, 0, 0 ) );
|
|
|
|
|
TimesigTable = new Vector<TimeSigTableEntry>();
|
|
|
|
|
TimesigTable.add( new TimeSigTableEntry( 0, numerator, denominator, 0 ) );
|
|
|
|
|
TempoTable = new Vector<TempoTableEntry>();
|
|
|
|
|
TempoTable.add( new TempoTableEntry( 0, tempo, 0.0 ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
m_base_tempo = tempo;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
//m_premeasure_clocks = calculatePreMeasureInClock();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// vsqファイルからのコンストラクタ
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="_fpath"></param>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public VsqFile( String _fpath, String encoding )
|
|
|
|
|
#if JAVA
|
|
|
|
|
throws FileNotFoundException
|
|
|
|
|
#endif
|
|
|
|
|
{
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTable = new Vector<TempoTableEntry>();
|
|
|
|
|
TimesigTable = new Vector<TimeSigTableEntry>();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
m_tpq = 480;
|
|
|
|
|
|
|
|
|
|
// SMFをコンバートしたテキストファイルを作成
|
2010-03-16 20:14:08 -07:00
|
|
|
|
MidiFile mf = new MidiFile( _fpath );
|
|
|
|
|
Track = new Vector<VsqTrack>();
|
|
|
|
|
int num_track = mf.getTrackCount();
|
|
|
|
|
#if DEBUG
|
|
|
|
|
PortUtil.println( "VsqFile#.ctor; num_track=" + num_track );
|
|
|
|
|
#endif
|
|
|
|
|
for ( int i = 0; i < num_track; i++ ) {
|
|
|
|
|
Track.add( new VsqTrack( mf.getMidiEventList( i ), encoding ) );
|
|
|
|
|
}
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Master = (VsqMaster)Track.get( 1 ).getMaster().clone();
|
|
|
|
|
Mixer = (VsqMixer)Track.get( 1 ).getMixer().clone();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( 1 ).setMaster( null );
|
|
|
|
|
Track.get( 1 ).setMixer( null );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
System.Diagnostics.Debug.WriteLine( "VsqFile.ctor()" );
|
|
|
|
|
#endif
|
|
|
|
|
int master_track = -1;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int i = 0; i < Track.size(); i++ ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#if DEBUG
|
2009-09-07 03:44:18 -07:00
|
|
|
|
System.Diagnostics.Debug.WriteLine( " m_tracks[i].Name=" + Track.get( i ).getName() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endif
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( Track.get( i ).getName().Equals( "Master Track" ) ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
master_track = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int prev_tempo;
|
|
|
|
|
int prev_index;
|
|
|
|
|
double prev_time;
|
|
|
|
|
if ( master_track >= 0 ) {
|
|
|
|
|
#region TempoListの作成
|
|
|
|
|
// MIDI event リストの取得
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Vector<MidiEvent> midi_event = mf.getMidiEventList( master_track );//.TempoTable;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
// とりあえずtempo_tableに格納
|
2009-07-29 10:03:20 -07:00
|
|
|
|
m_base_tempo = 500000;
|
|
|
|
|
prev_tempo = 500000;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
prev_index = 0;
|
|
|
|
|
double thistime;
|
|
|
|
|
prev_time = 0.0;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
int count = -1;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int midi_event_size = midi_event.size();
|
|
|
|
|
for ( int j = 0; j < midi_event_size; j++ ) {
|
|
|
|
|
MidiEvent itemj = midi_event.get( j );
|
|
|
|
|
if ( itemj.firstByte == (byte)0xff && itemj.data.Length >= 4 && itemj.data[0] == (byte)0x51 ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
count++;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( count == 0 && itemj.clock != 0 ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTable.add( new TempoTableEntry( 0, 500000, 0.0 ) );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
m_base_tempo = 500000;
|
|
|
|
|
prev_tempo = 500000;
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int current_tempo = itemj.data[1] << 16 | itemj.data[2] << 8 | itemj.data[3];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int current_index = (int)midi_event.get( j ).clock;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
thistime = prev_time + (double)(prev_tempo) * (double)(current_index - prev_index) / (m_tpq * 1000000.0);
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTable.add( new TempoTableEntry( current_index, current_tempo, thistime ) );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
prev_tempo = current_tempo;
|
|
|
|
|
prev_index = current_index;
|
|
|
|
|
prev_time = thistime;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Collections.sort( TempoTable );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region TimeSigTableの作成
|
2009-09-07 03:44:18 -07:00
|
|
|
|
//Vector<MidiEvent> time_sigs = mf.getMidiEventList( master_track );//].TimesigTable;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
int dnomi = 4;// time_sigs[0].Data[1];
|
|
|
|
|
int numer = 4;
|
|
|
|
|
/*for ( int i = 0; i < time_sigs[0].Data[2]; i++ ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
numer = numer * 2;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}*/
|
|
|
|
|
//m_timesig_table.Add( new TimeSigTableEntry( 0, numer, dnomi, 0 ) );
|
|
|
|
|
count = -1;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int j = 0; j < midi_event.size(); j++ ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( midi_event.get( j ).firstByte == (byte)0xff && midi_event.get( j ).data.Length >= 5 && midi_event.get( j ).data[0] == (byte)0x58 ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
count++;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
numer = midi_event.get( j ).data[1];
|
2009-07-29 10:03:20 -07:00
|
|
|
|
dnomi = 1;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int i = 0; i < midi_event.get( j ).data[2]; i++ ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
dnomi = dnomi * 2;
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( count == 0 ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
int numerator = 4;
|
|
|
|
|
int denominator = 4;
|
|
|
|
|
int clock = 0;
|
|
|
|
|
int bar_count = 0;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( midi_event.get( j ).clock == 0 ) {
|
|
|
|
|
TimesigTable.add( new TimeSigTableEntry( 0, numer, dnomi, 0 ) );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
} else {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TimesigTable.add( new TimeSigTableEntry( 0, 4, 4, 0 ) );
|
|
|
|
|
TimesigTable.add( new TimeSigTableEntry( 0, numer, dnomi, (int)midi_event.get( j ).clock / (480 * 4) ) );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int numerator = TimesigTable.get( count - 1 ).Numerator;
|
|
|
|
|
int denominator = TimesigTable.get( count - 1 ).Denominator;
|
|
|
|
|
int clock = TimesigTable.get( count - 1 ).Clock;
|
|
|
|
|
int bar_count = TimesigTable.get( count - 1 ).BarCount;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
int dif = 480 * 4 / denominator * numerator;//1小節が何クロックか?
|
2009-09-07 03:44:18 -07:00
|
|
|
|
bar_count += ((int)midi_event.get( j ).clock - clock) / dif;
|
|
|
|
|
TimesigTable.add( new TimeSigTableEntry( (int)midi_event.get( j ).clock, numer, dnomi, bar_count ) );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 曲の長さを計算
|
|
|
|
|
updateTempoInfo();
|
|
|
|
|
updateTimesigInfo();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
//m_premeasure_clocks = calculatePreMeasureInClock();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
updateTotalClocks();
|
|
|
|
|
#if DEBUG
|
|
|
|
|
System.Diagnostics.Debug.WriteLine( " m_total_clocks=" + TotalClocks );
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// TimeSigTableの[*].Clockの部分を更新します
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void updateTimesigInfo() {
|
|
|
|
|
#if DEBUG
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.println( "VsqFile.UpdateTimesigInfo()" );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endif
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( TimesigTable.get( 0 ).Clock != 0 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
return;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TimesigTable.get( 0 ).Clock = 0;
|
|
|
|
|
Collections.sort( TimesigTable );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int count = TimesigTable.size();
|
|
|
|
|
for ( int j = 1; j < count; j++ ) {
|
|
|
|
|
TimeSigTableEntry item = TimesigTable.get( j - 1 );
|
|
|
|
|
int numerator = item.Numerator;
|
|
|
|
|
int denominator = item.Denominator;
|
|
|
|
|
int clock = item.Clock;
|
|
|
|
|
int bar_count = item.BarCount;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int dif = 480 * 4 / denominator * numerator;//1小節が何クロックか?
|
2009-09-07 03:44:18 -07:00
|
|
|
|
clock += (TimesigTable.get( j ).BarCount - bar_count) * dif;
|
|
|
|
|
TimesigTable.get( j ).Clock = clock;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
#if DEBUG
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.println( "TimesigTable;" );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int i = 0; i < TimesigTable.size(); i++ ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.println( " " + TimesigTable.get( i ).Clock + " " + TimesigTable.get( i ).Numerator + "/" + TimesigTable.get( i ).Denominator );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// TempoTableの[*].Timeの部分を更新します
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void updateTempoInfo() {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( TempoTable.size() == 0 ) {
|
|
|
|
|
TempoTable.add( new TempoTableEntry( 0, getBaseTempo(), 0.0 ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Collections.sort( TempoTable );
|
|
|
|
|
if ( TempoTable.get( 0 ).Clock != 0 ) {
|
|
|
|
|
TempoTable.get( 0 ).Time = (double)getBaseTempo() * (double)TempoTable.get( 0 ).Clock / (getTickPerQuarter() * 1000000.0);
|
2009-06-25 07:16:22 -07:00
|
|
|
|
} else {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTable.get( 0 ).Time = 0.0;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
double prev_time = TempoTable.get( 0 ).Time;
|
|
|
|
|
int prev_clock = TempoTable.get( 0 ).Clock;
|
|
|
|
|
int prev_tempo = TempoTable.get( 0 ).Tempo;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
double inv_tpq_sec = 1.0 / (getTickPerQuarter() * 1000000.0);
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int i = 1; i < TempoTable.size(); i++ ) {
|
|
|
|
|
TempoTable.get( i ).Time = prev_time + (double)prev_tempo * (double)(TempoTable.get( i ).Clock - prev_clock) * inv_tpq_sec;
|
|
|
|
|
prev_time = TempoTable.get( i ).Time;
|
|
|
|
|
prev_tempo = TempoTable.get( i ).Tempo;
|
|
|
|
|
prev_clock = TempoTable.get( i ).Clock;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// VsqFile.Executeの実行直後などに、m_total_clocksの値を更新する
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void updateTotalClocks() {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
int max = getPreMeasureClocks();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( int i = 1; i < Track.size(); i++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqTrack track = Track.get( i );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
for ( Iterator itr = track.getEventIterator(); itr.hasNext(); ) {
|
|
|
|
|
VsqEvent ve = (VsqEvent)itr.next();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
max = Math.Max( max, ve.Clock + ve.ID.getLength() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( int j = 0; j < _CURVES.Length; j++ ) {
|
|
|
|
|
String vct = _CURVES[j];
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( vct.Equals( "VEL" ) ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqBPList list = track.getCurve( vct );
|
|
|
|
|
if ( list != null && list.size() > 0 ) {
|
|
|
|
|
int keys = list.size();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int last_key = list.getKeyClock( keys - 1 );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
max = Math.Max( max, last_key );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
TotalClocks = max;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 曲の長さを取得する。(sec)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double getTotalSec() {
|
|
|
|
|
return getSecFromClock( (int)TotalClocks );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定された番号のトラックに含まれる歌詞を指定されたファイルに出力します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="track"></param>
|
|
|
|
|
/// <param name="fpath"></param>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public void printLyricTable( int track, String fpath ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
BufferedWriter sw = null;
|
|
|
|
|
try {
|
|
|
|
|
sw = new BufferedWriter( new FileWriter( fpath ) );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int i = 0; i < Track.get( track ).getEventCount(); i++ ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int Length;
|
|
|
|
|
// timesignal
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int time_signal = Track.get( track ).getEvent( i ).Clock;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
// イベントで指定されたIDがLyricであった場合
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( Track.get( track ).getEvent( i ).ID.type == VsqIDType.Anote ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
// 発音長を取得
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Length = Track.get( track ).getEvent( i ).ID.getLength();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
|
|
|
|
// tempo_tableから、発音開始時のtempoを取得
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int last = TempoTable.size() - 1;
|
|
|
|
|
int tempo = TempoTable.get( last ).Tempo;
|
|
|
|
|
int prev_index = TempoTable.get( last ).Clock;
|
|
|
|
|
double prev_time = TempoTable.get( last ).Time;
|
|
|
|
|
for ( int j = 1; j < TempoTable.size(); j++ ) {
|
|
|
|
|
if ( TempoTable.get( j ).Clock > time_signal ) {
|
|
|
|
|
tempo = TempoTable.get( j - 1 ).Tempo;
|
|
|
|
|
prev_index = TempoTable.get( j - 1 ).Clock;
|
|
|
|
|
prev_time = TempoTable.get( j - 1 ).Time;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int current_index = Track.get( track ).getEvent( i ).Clock;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
double start_time = prev_time + (double)(current_index - prev_index) * (double)tempo / (m_tpq * 1000000.0);
|
|
|
|
|
// TODO: 単純に + Lengthしただけではまずいはず。要検討
|
|
|
|
|
double end_time = start_time + ((double)Length) * ((double)tempo) / (m_tpq * 1000000.0);
|
2010-03-16 20:14:08 -07:00
|
|
|
|
sw.write( Track.get( track ).getEvent( i ).Clock + "," +
|
|
|
|
|
PortUtil.formatDecimal( "0.000000", start_time ) + "," +
|
|
|
|
|
PortUtil.formatDecimal( "0.000000", end_time ) + "," +
|
|
|
|
|
Track.get( track ).getEvent( i ).ID.LyricHandle.L0.Phrase + "," +
|
|
|
|
|
Track.get( track ).getEvent( i ).ID.LyricHandle.L0.getPhoneticSymbol() );
|
|
|
|
|
sw.newLine();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
} catch ( Exception ex ) {
|
|
|
|
|
} finally {
|
|
|
|
|
if ( sw != null ) {
|
|
|
|
|
try {
|
|
|
|
|
sw.close();
|
|
|
|
|
} catch ( Exception ex2 ) {
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public Vector<MidiEvent> generateMetaTextEvent( int track, String encoding ) {
|
|
|
|
|
String _NL = "" + (char)(byte)0x0a;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Vector<MidiEvent> ret = new Vector<MidiEvent>();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
TextMemoryStream sr = null;
|
|
|
|
|
try {
|
|
|
|
|
sr = new TextMemoryStream();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Track.get( track ).printMetaText( sr, TotalClocks + 120, calculatePreMeasureInClock() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
sr.rewind();
|
|
|
|
|
int line_count = -1;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String tmp = "";
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( sr.peek() >= 0 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if NEW_IMPL
|
|
|
|
|
Vector<Byte> buffer = new Vector<Byte>();
|
|
|
|
|
boolean first = true;
|
|
|
|
|
while ( sr.peek() >= 0 ) {
|
|
|
|
|
if ( first ) {
|
|
|
|
|
tmp = sr.readLine();
|
|
|
|
|
first = false;
|
|
|
|
|
} else {
|
|
|
|
|
tmp = _NL + sr.readLine();
|
|
|
|
|
}
|
|
|
|
|
Byte[] linebytes = PortUtil.convertByteArray( PortUtil.getEncodedByte( encoding, tmp ) );
|
|
|
|
|
buffer.addAll( Arrays.asList( linebytes ) );
|
|
|
|
|
while ( getLinePrefixBytes( line_count + 1 ).Length + buffer.size() >= 127 ) {
|
|
|
|
|
line_count++;
|
|
|
|
|
byte[] prefix = getLinePrefixBytes( line_count );
|
|
|
|
|
MidiEvent add = new MidiEvent();
|
|
|
|
|
add.clock = 0;
|
|
|
|
|
add.firstByte = (byte)0xff;
|
|
|
|
|
add.data = new byte[128];
|
|
|
|
|
add.data[0] = (byte)0x01;
|
|
|
|
|
int remain = 127;
|
|
|
|
|
for ( int i = 0; i < prefix.Length; i++ ) {
|
|
|
|
|
add.data[i + 1] = prefix[i];
|
|
|
|
|
}
|
|
|
|
|
for ( int i = prefix.Length; i < remain; i++ ) {
|
|
|
|
|
byte d = buffer.get( 0 );
|
|
|
|
|
add.data[i + 1] = d;
|
|
|
|
|
buffer.removeElementAt( 0 );
|
|
|
|
|
}
|
|
|
|
|
ret.add( add );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( buffer.size() > 0 ) {
|
|
|
|
|
while ( getLinePrefixBytes( line_count + 1 ).Length + buffer.size() >= 127 ) {
|
|
|
|
|
line_count++;
|
|
|
|
|
byte[] prefix = getLinePrefixBytes( line_count );
|
|
|
|
|
MidiEvent add = new MidiEvent();
|
|
|
|
|
add.clock = 0;
|
|
|
|
|
add.firstByte = (byte)0xff;
|
|
|
|
|
add.data = new byte[128];
|
|
|
|
|
add.data[0] = (byte)0x01;
|
|
|
|
|
int remain = 127;
|
|
|
|
|
for ( int i = 0; i < prefix.Length; i++ ) {
|
|
|
|
|
add.data[i + 1] = prefix[i];
|
|
|
|
|
}
|
|
|
|
|
for ( int i = prefix.Length; i < remain; i++ ) {
|
|
|
|
|
add.data[i + 1] = buffer.get( 0 );
|
|
|
|
|
buffer.removeElementAt( 0 );
|
|
|
|
|
}
|
|
|
|
|
ret.add( add );
|
|
|
|
|
}
|
|
|
|
|
if ( buffer.size() > 0 ) {
|
|
|
|
|
line_count++;
|
|
|
|
|
byte[] prefix = getLinePrefixBytes( line_count );
|
|
|
|
|
MidiEvent add = new MidiEvent();
|
|
|
|
|
add.clock = 0;
|
|
|
|
|
add.firstByte = (byte)0xff;
|
|
|
|
|
int remain = prefix.Length + buffer.size();
|
|
|
|
|
add.data = new byte[remain + 1];
|
|
|
|
|
add.data[0] = (byte)0x01;
|
|
|
|
|
for ( int i = 0; i < prefix.Length; i++ ) {
|
|
|
|
|
add.data[i + 1] = prefix[i];
|
|
|
|
|
}
|
|
|
|
|
for ( int i = prefix.Length; i < remain; i++ ) {
|
|
|
|
|
add.data[i + 1] = buffer.get( 0 );
|
|
|
|
|
buffer.removeElementAt( 0 );
|
|
|
|
|
}
|
|
|
|
|
ret.add( add );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#else
|
2009-06-25 07:16:22 -07:00
|
|
|
|
tmp = sr.readLine();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
byte[] line_bytes;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
while ( sr.peek() >= 0 ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
tmp += _NL + sr.readLine();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
while ( PortUtil.getEncodedByteCount( encoding, tmp + getLinePrefix( line_count + 1 ) ) >= 127 ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
line_count++;
|
|
|
|
|
tmp = getLinePrefix( line_count ) + tmp;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String work = substring127Bytes( tmp, encoding );// tmp.Substring( 0, 127 );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
tmp = tmp.Substring( PortUtil.getStringLength( work ) );
|
|
|
|
|
line_bytes = PortUtil.getEecodedByte( encoding, work );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
MidiEvent add = new MidiEvent();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
add.clock = 0;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add.firstByte = (byte)0xff; //ステータス メタ*
|
2009-09-07 03:44:18 -07:00
|
|
|
|
add.data = new byte[line_bytes.Length + 1];
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add.data[0] = (byte)0x01; //メタテキスト
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int i = 0; i < line_bytes.Length; i++ ) {
|
|
|
|
|
add.data[i + 1] = line_bytes[i];
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
ret.add( add );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 残りを出力
|
|
|
|
|
line_count++;
|
|
|
|
|
tmp = getLinePrefix( line_count ) + tmp + _NL;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
while ( PortUtil.getEncodedByteCount( encoding, tmp ) > 127 ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String work = substring127Bytes( tmp, encoding );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
tmp = tmp.Substring( PortUtil.getStringLength( work ) );
|
|
|
|
|
line_bytes = PortUtil.getEecodedByte( encoding, work );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
MidiEvent add = new MidiEvent();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
add.clock = 0;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add.firstByte = (byte)0xff;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
add.data = new byte[line_bytes.Length + 1];
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add.data[0] = (byte)0x01;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int i = 0; i < line_bytes.Length; i++ ) {
|
|
|
|
|
add.data[i + 1] = line_bytes[i];
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
ret.add( add );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
line_count++;
|
|
|
|
|
tmp = getLinePrefix( line_count );
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
line_bytes = PortUtil.getEecodedByte( encoding, tmp );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
MidiEvent add0 = new MidiEvent();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add0.firstByte = (byte)0xff;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
add0.data = new byte[line_bytes.Length + 1];
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add0.data[0] = (byte)0x01;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int i = 0; i < line_bytes.Length; i++ ) {
|
|
|
|
|
add0.data[i + 1] = line_bytes[i];
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
ret.add( add0 );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
} catch ( Exception ex ) {
|
|
|
|
|
} finally {
|
|
|
|
|
if ( sr != null ) {
|
|
|
|
|
try {
|
|
|
|
|
sr.close();
|
|
|
|
|
} catch ( Exception ex2 ) {
|
|
|
|
|
}
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if DEBUG
|
|
|
|
|
Console.WriteLine( "VsqFile#generateMetaTextEvent; ret.size()=" + ret.size() );
|
|
|
|
|
#endif
|
2009-07-29 10:03:20 -07:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 文字列sの先頭から文字列を切り取るとき,切り取った文字列をencodingによりエンコードした結果が127Byte以下になるように切り取ります.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="s"></param>
|
|
|
|
|
/// <param name="encoding"></param>
|
|
|
|
|
/// <returns></returns>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
private static String substring127Bytes( String s, String encoding ) {
|
|
|
|
|
int count = Math.Min( 127, PortUtil.getStringLength( s ) );
|
|
|
|
|
int c = PortUtil.getEncodedByteCount( encoding, s.Substring( 0, count ) );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( c == 127 ) {
|
|
|
|
|
return s.Substring( 0, count );
|
|
|
|
|
}
|
|
|
|
|
int delta = c > 127 ? -1 : 1;
|
|
|
|
|
while ( (delta == -1 && c > 127) || (delta == 1 && c < 127) ) {
|
|
|
|
|
count += delta;
|
|
|
|
|
if ( delta == -1 && count == 0 ) {
|
|
|
|
|
break;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
} else if ( delta == 1 && count == PortUtil.getStringLength( s ) ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
c = PortUtil.getEncodedByteCount( encoding, s.Substring( 0, count ) );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
}
|
|
|
|
|
return s.Substring( 0, count );
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
private static void printTrack( VsqFile vsq, int track, RandomAccessFile fs, int msPreSend, String encoding )
|
|
|
|
|
#if JAVA
|
|
|
|
|
throws IOException
|
|
|
|
|
#endif
|
|
|
|
|
{
|
2009-07-29 10:03:20 -07:00
|
|
|
|
#if DEBUG
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.println( "PrintTrack" );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
#endif
|
|
|
|
|
//VsqTrack item = Tracks[track];
|
2010-03-16 20:14:08 -07:00
|
|
|
|
String _NL = "" + (char)(byte)0x0a;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
//ヘッダ
|
2010-03-16 20:14:08 -07:00
|
|
|
|
fs.write( _MTRK, 0, 4 );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
//データ長。とりあえず0
|
2010-03-16 20:14:08 -07:00
|
|
|
|
fs.write( new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, 0, 4 );
|
|
|
|
|
long first_position = fs.getFilePointer();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
//トラック名
|
2010-03-16 20:14:08 -07:00
|
|
|
|
writeFlexibleLengthUnsignedLong( fs, (byte)0x00 );//デルタタイム
|
|
|
|
|
fs.write( (byte)0xff );//ステータスタイプ
|
|
|
|
|
fs.write( (byte)0x03 );//イベントタイプSequence/Track Name
|
|
|
|
|
byte[] seq_name = PortUtil.getEncodedByte( encoding, vsq.Track.get( track ).getName() );
|
|
|
|
|
writeFlexibleLengthUnsignedLong( fs, (long)seq_name.Length );//seq_nameの文字数
|
|
|
|
|
fs.write( seq_name, 0, seq_name.Length );
|
|
|
|
|
|
2009-07-29 10:03:20 -07:00
|
|
|
|
//Meta Textを準備
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Vector<MidiEvent> meta = vsq.generateMetaTextEvent( track, encoding );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
long lastclock = 0;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int i = 0; i < meta.size(); i++ ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
writeFlexibleLengthUnsignedLong( fs, (long)(meta.get( i ).clock - lastclock) );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
meta.get( i ).writeData( fs );
|
|
|
|
|
lastclock = meta.get( i ).clock;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
|
|
|
|
int last = 0;
|
|
|
|
|
VsqNrpn[] data = generateNRPN( vsq, track, msPreSend );
|
|
|
|
|
NrpnData[] nrpns = VsqNrpn.convert( data );
|
|
|
|
|
for ( int i = 0; i < nrpns.Length; i++ ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
writeFlexibleLengthUnsignedLong( fs, (long)(nrpns[i].getClock() - last) );
|
|
|
|
|
fs.write( (byte)0xb0 );
|
|
|
|
|
fs.write( nrpns[i].getParameter() );
|
|
|
|
|
fs.write( nrpns[i].Value );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
last = nrpns[i].getClock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//トラックエンド
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqEvent last_event = vsq.Track.get( track ).getEvent( vsq.Track.get( track ).getEventCount() - 1 );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int last_clock = last_event.Clock + last_event.ID.getLength();
|
|
|
|
|
writeFlexibleLengthUnsignedLong( fs, (long)last_clock );
|
|
|
|
|
fs.write( (byte)0xff );
|
|
|
|
|
fs.write( (byte)0x2f );
|
|
|
|
|
fs.write( (byte)0x00 );
|
|
|
|
|
long pos = fs.getFilePointer();
|
|
|
|
|
fs.seek( first_position - 4 );
|
|
|
|
|
writeUnsignedInt( fs, (long)(pos - first_position) );
|
|
|
|
|
fs.seek( pos );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定したクロックにおけるプリセンド・クロックを取得します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="clock"></param>
|
|
|
|
|
/// <param name="msPreSend"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int getPresendClockAt( int clock, int msPreSend ) {
|
|
|
|
|
double clock_msec = getSecFromClock( clock ) * 1000.0;
|
|
|
|
|
float draft_clock_sec = (float)(clock_msec - msPreSend) / 1000.0f;
|
|
|
|
|
int draft_clock = (int)Math.Floor( getClockFromSec( draft_clock_sec ) );
|
|
|
|
|
return clock - draft_clock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定したトラックから、Expression(DYN)のNRPNリストを作成します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="track"></param>
|
|
|
|
|
/// <param name="msPreSend"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static VsqNrpn[] generateExpressionNRPN( VsqFile vsq, int track, int msPreSend ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Vector<VsqNrpn> ret = new Vector<VsqNrpn>();
|
|
|
|
|
VsqBPList dyn = vsq.Track.get( track ).getCurve( "DYN" );
|
|
|
|
|
int count = dyn.size();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
for ( int i = 0; i < count; i++ ) {
|
|
|
|
|
int clock = dyn.getKeyClock( i );
|
|
|
|
|
int c = clock - vsq.getPresendClockAt( clock, msPreSend );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( c >= 0 ) {
|
|
|
|
|
VsqNrpn add = new VsqNrpn( c,
|
2009-07-29 10:03:20 -07:00
|
|
|
|
NRPN.CC_E_EXPRESSION,
|
|
|
|
|
(byte)dyn.getElement( i ) );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
ret.add( add );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
return ret.toArray( new VsqNrpn[] { } );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static VsqNrpn[] generateFx2DepthNRPN( VsqFile vsq, int track, int msPreSend ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Vector<VsqNrpn> ret = new Vector<VsqNrpn>();
|
|
|
|
|
VsqBPList fx2depth = vsq.Track.get( track ).getCurve( "fx2depth" );
|
|
|
|
|
int count = fx2depth.size();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
for ( int i = 0; i < count; i++ ) {
|
|
|
|
|
int clock = fx2depth.getKeyClock( i );
|
|
|
|
|
int c = clock - vsq.getPresendClockAt( clock, msPreSend );
|
|
|
|
|
if ( c >= 0 ) {
|
|
|
|
|
VsqNrpn add = new VsqNrpn( c,
|
|
|
|
|
NRPN.CC_FX2_EFFECT2_DEPTH,
|
|
|
|
|
(byte)fx2depth.getElement( i ) );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
ret.add( add );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
return ret.toArray( new VsqNrpn[] { } );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 先頭に記録されるNRPNを作成します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static VsqNrpn generateHeaderNRPN() {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
VsqNrpn ret = new VsqNrpn( 0, NRPN.CC_BS_VERSION_AND_DEVICE, (byte)0x00, (byte)0x00 );
|
|
|
|
|
ret.append( NRPN.CC_BS_DELAY, (byte)0x00, (byte)0x00 );
|
|
|
|
|
ret.append( NRPN.CC_BS_LANGUAGE_TYPE, (byte)0x00 );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 歌手変更イベントから,NRPNを作成します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="vsq"></param>
|
|
|
|
|
/// <param name="ve"></param>
|
|
|
|
|
/// <param name="msPreSend"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static VsqNrpn[] generateSingerNRPN( VsqFile vsq, VsqEvent ve, int msPreSend ) {
|
|
|
|
|
int clock = ve.Clock;
|
|
|
|
|
|
|
|
|
|
double clock_msec = vsq.getSecFromClock( clock ) * 1000.0;
|
|
|
|
|
|
|
|
|
|
int ttempo = vsq.getTempoAt( clock );
|
|
|
|
|
double tempo = 6e7 / ttempo;
|
|
|
|
|
//double sStart = SecFromClock( ve.Clock );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
double msEnd = vsq.getSecFromClock( ve.Clock + ve.ID.getLength() ) * 1000.0;
|
|
|
|
|
int duration = (int)Math.Ceiling( msEnd - clock_msec );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#if DEBUG
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.println( "GenerateNoteNRPN" );
|
|
|
|
|
PortUtil.println( " duration=" + duration );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endif
|
2010-03-16 20:14:08 -07:00
|
|
|
|
ValuePair<Byte, Byte> d = getMsbAndLsb( duration );
|
|
|
|
|
byte duration0 = d.getKey();
|
|
|
|
|
byte duration1 = d.getValue();
|
|
|
|
|
ValuePair<Byte, Byte> d2 = getMsbAndLsb( msPreSend );
|
|
|
|
|
byte delay0 = d2.getKey();
|
|
|
|
|
byte delay1 = d2.getValue();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Vector<VsqNrpn> ret = new Vector<VsqNrpn>();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
|
|
|
|
int i = clock - vsq.getPresendClockAt( clock, msPreSend );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
VsqNrpn add = new VsqNrpn( i, NRPN.CC_BS_VERSION_AND_DEVICE, (byte)0x00, (byte)0x00 );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
add.append( NRPN.CC_BS_DELAY, delay0, delay1, true );
|
|
|
|
|
add.append( NRPN.CC_BS_LANGUAGE_TYPE, (byte)ve.ID.IconHandle.Language, true );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
add.append( NRPN.PC_VOICE_TYPE, (byte)ve.ID.IconHandle.Program );
|
|
|
|
|
return new VsqNrpn[] { add };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 音符イベントから,NRPNを作成します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ve"></param>
|
|
|
|
|
/// <param name="msPreSend"></param>
|
|
|
|
|
/// <param name="note_loc"></param>
|
|
|
|
|
/// <returns></returns>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public static VsqNrpn generateNoteNRPN( VsqFile vsq, int track, VsqEvent ve, int msPreSend, byte note_loc, boolean add_delay_sign ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int clock = ve.Clock;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String renderer = vsq.Track.get( track ).getCommon().Version;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
|
|
|
|
double clock_msec = vsq.getSecFromClock( clock ) * 1000.0;
|
|
|
|
|
|
|
|
|
|
int ttempo = vsq.getTempoAt( clock );
|
|
|
|
|
double tempo = 6e7 / ttempo;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
double msEnd = vsq.getSecFromClock( ve.Clock + ve.ID.getLength() ) * 1000.0;
|
|
|
|
|
int duration = (int)(msEnd - clock_msec);
|
|
|
|
|
ValuePair<Byte, Byte> dur = getMsbAndLsb( duration );
|
|
|
|
|
byte duration0 = dur.getKey();
|
|
|
|
|
byte duration1 = dur.getValue();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
2009-07-29 10:03:20 -07:00
|
|
|
|
VsqNrpn add;
|
|
|
|
|
if ( add_delay_sign ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
ValuePair<Byte, Byte> msp = getMsbAndLsb( msPreSend );
|
|
|
|
|
byte delay0 = msp.getKey();
|
|
|
|
|
byte delay1 = msp.getValue();
|
|
|
|
|
add = new VsqNrpn( clock - vsq.getPresendClockAt( clock, msPreSend ), NRPN.CVM_NM_VERSION_AND_DEVICE, (byte)0x00, (byte)0x00 );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
add.append( NRPN.CVM_NM_DELAY, delay0, delay1, true );
|
|
|
|
|
add.append( NRPN.CVM_NM_NOTE_NUMBER, (byte)ve.ID.Note, true ); // Note number
|
2009-07-29 10:03:20 -07:00
|
|
|
|
} else {
|
|
|
|
|
add = new VsqNrpn( clock - vsq.getPresendClockAt( clock, msPreSend ), NRPN.CVM_NM_NOTE_NUMBER, (byte)ve.ID.Note ); // Note number
|
|
|
|
|
}
|
2009-07-30 08:02:59 -07:00
|
|
|
|
add.append( NRPN.CVM_NM_VELOCITY, (byte)ve.ID.Dynamics, true ); // Velocity
|
|
|
|
|
add.append( NRPN.CVM_NM_NOTE_DURATION, duration0, duration1, true ); // Note duration
|
|
|
|
|
add.append( NRPN.CVM_NM_NOTE_LOCATION, note_loc, true ); // Note Location
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
|
|
|
|
if ( ve.ID.VibratoHandle != null ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add.append( NRPN.CVM_NM_INDEX_OF_VIBRATO_DB, (byte)0x00, (byte)0x00, true );
|
|
|
|
|
String icon_id = ve.ID.VibratoHandle.IconID;
|
|
|
|
|
String num = icon_id.Substring( PortUtil.getStringLength( icon_id ) - 4 );
|
|
|
|
|
int vibrato_type = (int)PortUtil.fromHexString( num );
|
|
|
|
|
int note_length = ve.ID.getLength();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int vibrato_delay = ve.ID.VibratoDelay;
|
|
|
|
|
byte bVibratoDuration = (byte)((float)(note_length - vibrato_delay) / (float)note_length * 127);
|
2010-03-16 20:14:08 -07:00
|
|
|
|
byte bVibratoDelay = (byte)((byte)0x7f - bVibratoDuration);
|
2009-07-30 08:02:59 -07:00
|
|
|
|
add.append( NRPN.CVM_NM_VIBRATO_CONFIG, (byte)vibrato_type, bVibratoDuration, true );
|
|
|
|
|
add.append( NRPN.CVM_NM_VIBRATO_DELAY, bVibratoDelay, true );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String[] spl = ve.ID.LyricHandle.L0.getPhoneticSymbolList();
|
|
|
|
|
String s = "";
|
2009-06-25 07:16:22 -07:00
|
|
|
|
for ( int j = 0; j < spl.Length; j++ ) {
|
|
|
|
|
s += spl[j];
|
|
|
|
|
}
|
|
|
|
|
char[] symbols = s.ToCharArray();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
if ( renderer.StartsWith( "DSB2" ) ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add.append( 0x5011, (byte)0x01, true );//TODO: (byte)0x5011の意味は解析中
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add.append( NRPN.CVM_NM_PHONETIC_SYMBOL_BYTES, (byte)symbols.Length, true );// (byte)0x12(Number of phonetic symbols in bytes)
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int count = -1;
|
|
|
|
|
for ( int j = 0; j < spl.Length; j++ ) {
|
|
|
|
|
char[] chars = spl[j].ToCharArray();
|
|
|
|
|
for ( int k = 0; k < chars.Length; k++ ) {
|
|
|
|
|
count++;
|
|
|
|
|
if ( k == 0 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add.append( (0x50 << 8) | (0x13 + count), (byte)chars[k], (byte)ve.ID.LyricHandle.L0.getConsonantAdjustment()[j], true ); // Phonetic symbol j
|
2009-07-29 10:03:20 -07:00
|
|
|
|
} else {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add.append( (0x50 << 8) | (0x13 + count), (byte)chars[k], true ); // Phonetic symbol j
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( !renderer.StartsWith( "DSB2" ) ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add.append( NRPN.CVM_NM_PHONETIC_SYMBOL_CONTINUATION, (byte)0x7f, true ); // End of phonetic symbols
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
if ( renderer.StartsWith( "DSB3" ) ) {
|
|
|
|
|
int v1mean = ve.ID.PMBendDepth * 60 / 100;
|
|
|
|
|
if ( v1mean < 0 ) {
|
|
|
|
|
v1mean = 0;
|
|
|
|
|
}
|
|
|
|
|
if ( 60 < v1mean ) {
|
|
|
|
|
v1mean = 60;
|
|
|
|
|
}
|
|
|
|
|
int d1mean = (int)(0.3196 * ve.ID.PMBendLength + 8.0);
|
|
|
|
|
int d2mean = (int)(0.92 * ve.ID.PMBendLength + 28.0);
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add.append( NRPN.CVM_NM_V1MEAN, (byte)v1mean, true );// (byte)0x50(v1mean)
|
|
|
|
|
add.append( NRPN.CVM_NM_D1MEAN, (byte)d1mean, true );// (byte)0x51(d1mean)
|
|
|
|
|
add.append( NRPN.CVM_NM_D1MEAN_FIRST_NOTE, (byte)0x14, true );// (byte)0x52(d1meanFirstNote)
|
|
|
|
|
add.append( NRPN.CVM_NM_D2MEAN, (byte)d2mean, true );// (byte)0x53(d2mean)
|
|
|
|
|
add.append( NRPN.CVM_NM_D4MEAN, (byte)ve.ID.d4mean, true );// (byte)0x54(d4mean)
|
2009-07-30 08:02:59 -07:00
|
|
|
|
add.append( NRPN.CVM_NM_PMEAN_ONSET_FIRST_NOTE, (byte)ve.ID.pMeanOnsetFirstNote, true ); // 055(pMeanOnsetFirstNote)
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add.append( NRPN.CVM_NM_VMEAN_NOTE_TRNSITION, (byte)ve.ID.vMeanNoteTransition, true ); // (byte)0x56(vMeanNoteTransition)
|
|
|
|
|
add.append( NRPN.CVM_NM_PMEAN_ENDING_NOTE, (byte)ve.ID.pMeanEndingNote, true );// (byte)0x57(pMeanEndingNote)
|
|
|
|
|
add.append( NRPN.CVM_NM_ADD_PORTAMENTO, (byte)ve.ID.PMbPortamentoUse, true );// (byte)0x58(AddScoopToUpInternals&AddPortamentoToDownIntervals)
|
|
|
|
|
byte decay = (byte)(ve.ID.DEMdecGainRate / 100.0 * (byte)0x64);
|
|
|
|
|
add.append( NRPN.CVM_NM_CHANGE_AFTER_PEAK, decay, true );// (byte)0x59(changeAfterPeak)
|
|
|
|
|
byte accent = (byte)((byte)0x64 * ve.ID.DEMaccent / 100.0);
|
|
|
|
|
add.append( NRPN.CVM_NM_ACCENT, accent, true );// (byte)0x5a(Accent)
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
if ( renderer.StartsWith( "UTU0" ) ) {
|
|
|
|
|
// エンベロープ
|
|
|
|
|
if ( ve.UstEvent != null ) {
|
|
|
|
|
UstEnvelope env = null;
|
|
|
|
|
if ( ve.UstEvent.Envelope != null ) {
|
|
|
|
|
env = ve.UstEvent.Envelope;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
} else {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
env = new UstEnvelope();
|
|
|
|
|
}
|
|
|
|
|
int[] vals = null;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
vals = new int[10];
|
2009-07-29 10:03:20 -07:00
|
|
|
|
vals[0] = env.p1;
|
|
|
|
|
vals[1] = env.p2;
|
|
|
|
|
vals[2] = env.p3;
|
|
|
|
|
vals[3] = env.v1;
|
|
|
|
|
vals[4] = env.v2;
|
|
|
|
|
vals[5] = env.v3;
|
|
|
|
|
vals[6] = env.v4;
|
2009-07-30 08:02:59 -07:00
|
|
|
|
vals[7] = env.p4;
|
|
|
|
|
vals[8] = env.p5;
|
|
|
|
|
vals[9] = env.v5;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
for ( int i = 0; i < vals.Length; i++ ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
//(value3.msb & (byte)0xf) << 28 | (value2.msb & (byte)0x7f) << 21 | (value2.lsb & (byte)0x7f) << 14 | (value1.msb & (byte)0x7f) << 7 | (value1.lsb & (byte)0x7f)
|
2009-07-29 10:03:20 -07:00
|
|
|
|
byte msb, lsb;
|
|
|
|
|
int v = vals[i];
|
2010-03-16 20:14:08 -07:00
|
|
|
|
lsb = (byte)(v & (byte)0x7f);
|
2009-07-29 10:03:20 -07:00
|
|
|
|
v = v >> 7;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
msb = (byte)(v & (byte)0x7f);
|
2009-07-29 10:03:20 -07:00
|
|
|
|
v = v >> 7;
|
|
|
|
|
add.append( NRPN.CVM_EXNM_ENV_DATA1, msb, lsb );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
lsb = (byte)(v & (byte)0x7f);
|
2009-07-29 10:03:20 -07:00
|
|
|
|
v = v >> 7;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
msb = (byte)(v & (byte)0x7f);
|
2009-07-29 10:03:20 -07:00
|
|
|
|
v = v >> 7;
|
|
|
|
|
add.append( NRPN.CVM_EXNM_ENV_DATA2, msb, lsb );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
msb = (byte)(v & (byte)0xf);
|
2009-07-29 10:03:20 -07:00
|
|
|
|
add.append( NRPN.CVM_EXNM_ENV_DATA3, msb );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add.append( NRPN.CVM_EXNM_ENV_DATA_CONTINUATION, (byte)0x00 );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add.append( NRPN.CVM_EXNM_ENV_DATA_CONTINUATION, (byte)0x7f );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
|
|
|
|
|
// モジュレーション
|
2010-03-16 20:14:08 -07:00
|
|
|
|
ValuePair<Byte, Byte> m;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
if ( -100 <= ve.UstEvent.Moduration && ve.UstEvent.Moduration <= 100 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
m = getMsbAndLsb( ve.UstEvent.Moduration + 100 );
|
|
|
|
|
add.append( NRPN.CVM_EXNM_MODURATION, m.getKey(), m.getValue() );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 先行発声
|
|
|
|
|
if ( ve.UstEvent.PreUtterance != 0 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
m = getMsbAndLsb( ve.UstEvent.PreUtterance + 8192 );
|
|
|
|
|
add.append( NRPN.CVM_EXNM_PRE_UTTERANCE, m.getKey(), m.getValue() );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Flags
|
|
|
|
|
if ( ve.UstEvent.Flags != "" ) {
|
|
|
|
|
char[] arr = ve.UstEvent.Flags.ToCharArray();
|
|
|
|
|
add.append( NRPN.CVM_EXNM_FLAGS_BYTES, (byte)arr.Length );
|
|
|
|
|
for ( int i = 0; i < arr.Length; i++ ) {
|
|
|
|
|
byte b = (byte)arr[i];
|
|
|
|
|
add.append( NRPN.CVM_EXNM_FLAGS, b );
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add.append( NRPN.CVM_EXNM_FLAGS_CONINUATION, (byte)0x7f );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// オーバーラップ
|
|
|
|
|
if ( ve.UstEvent.VoiceOverlap != 0 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
m = getMsbAndLsb( ve.UstEvent.VoiceOverlap + 8192 );
|
|
|
|
|
add.append( NRPN.CVM_EXNM_VOICE_OVERLAP, m.getKey(), m.getValue() );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add.append( NRPN.CVM_NM_NOTE_MESSAGE_CONTINUATION, (byte)0x7f, true );// (byte)0x7f(Note message continuation)
|
2009-06-25 07:16:22 -07:00
|
|
|
|
return add;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定したトラックのデータから,NRPNを作成します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="vsq"></param>
|
|
|
|
|
/// <param name="track"></param>
|
|
|
|
|
/// <param name="msPreSend"></param>
|
|
|
|
|
/// <param name="clock_start"></param>
|
|
|
|
|
/// <param name="clock_end"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static VsqNrpn[] generateNRPN( VsqFile vsq, int track, int msPreSend, int clock_start, int clock_end ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
VsqFile temp = (VsqFile)vsq.clone();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
temp.removePart( clock_end, vsq.TotalClocks );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( 0 < clock_start ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
temp.removePart( 0, clock_start );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
temp.Master.PreMeasure = 1;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
//temp.m_premeasure_clocks = temp.getClockFromBarCount( 1 );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqNrpn[] ret = generateNRPN( temp, track, msPreSend );
|
|
|
|
|
temp = null;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定したトラックのデータから,NRPNを作成します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="vsq"></param>
|
|
|
|
|
/// <param name="track"></param>
|
|
|
|
|
/// <param name="msPreSend"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static VsqNrpn[] generateNRPN( VsqFile vsq, int track, int msPreSend ) {
|
|
|
|
|
#if DEBUG
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.println( "GenerateNRPN(VsqTrack,int,int,int,int)" );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endif
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Vector<VsqNrpn> list = new Vector<VsqNrpn>();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqTrack target = vsq.Track.get( track );
|
|
|
|
|
String version = target.getCommon().Version;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
|
|
|
|
|
int count = target.getEventCount();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int note_start = 0;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
int note_end = target.getEventCount() - 1;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( int i = 0; i < count; i++ ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
if ( 0 <= target.getEvent( i ).Clock ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
note_start = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
note_start = i;
|
|
|
|
|
}
|
2009-07-29 10:03:20 -07:00
|
|
|
|
for ( int i = target.getEventCount() - 1; i >= 0; i-- ) {
|
|
|
|
|
if ( target.getEvent( i ).Clock <= vsq.TotalClocks ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
note_end = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 最初の歌手を決める
|
|
|
|
|
int singer_event = -1;
|
|
|
|
|
for ( int i = note_start; i >= 0; i-- ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
if ( target.getEvent( i ).ID.type == VsqIDType.Singer ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
singer_event = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( singer_event >= 0 ) { //見つかった場合
|
2010-03-16 20:14:08 -07:00
|
|
|
|
list.addAll( Arrays.asList( generateSingerNRPN( vsq, target.getEvent( singer_event ), 0 ) ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
} else { //多分ありえないと思うが、歌手が不明の場合。
|
2010-03-16 20:14:08 -07:00
|
|
|
|
//throw new Exception( "first singer was not specified" );
|
|
|
|
|
list.add( new VsqNrpn( 0, NRPN.CC_BS_LANGUAGE_TYPE, (byte)0x0 ) );
|
|
|
|
|
list.add( new VsqNrpn( 0, NRPN.PC_VOICE_TYPE, (byte)0x0 ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2009-07-29 10:03:20 -07:00
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
list.addAll( Arrays.asList( generateVoiceChangeParameterNRPN( vsq, track, msPreSend ) ) );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
if ( version.StartsWith( "DSB2" ) ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
list.addAll( Arrays.asList( generateFx2DepthNRPN( vsq, track, msPreSend ) ) );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ms_presend = msPreSend;
|
|
|
|
|
if ( version.StartsWith( "UTU0" ) ) {
|
|
|
|
|
double sec_maxlen = 0.0;
|
|
|
|
|
for ( Iterator itr = target.getNoteEventIterator(); itr.hasNext(); ) {
|
|
|
|
|
VsqEvent ve = (VsqEvent)itr.next();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
double len = vsq.getSecFromClock( ve.Clock + ve.ID.getLength() ) - vsq.getSecFromClock( ve.Clock );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
sec_maxlen = Math.Max( sec_maxlen, len );
|
|
|
|
|
}
|
|
|
|
|
ms_presend += (int)(sec_maxlen * 1000.0);
|
|
|
|
|
}
|
|
|
|
|
VsqBPList dyn = target.getCurve( "dyn" );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( dyn.size() > 0 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Vector<VsqNrpn> listdyn = new Vector<VsqNrpn>( Arrays.asList( generateExpressionNRPN( vsq, track, ms_presend ) ) );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( listdyn.size() > 0 ) {
|
|
|
|
|
list.addAll( listdyn );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
VsqBPList pbs = target.getCurve( "pbs" );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( pbs.size() > 0 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Vector<VsqNrpn> listpbs = new Vector<VsqNrpn>( Arrays.asList( generatePitchBendSensitivityNRPN( vsq, track, ms_presend ) ) );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( listpbs.size() > 0 ) {
|
|
|
|
|
list.addAll( listpbs );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
VsqBPList pit = target.getCurve( "pit" );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( pit.size() > 0 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Vector<VsqNrpn> listpit = new Vector<VsqNrpn>( Arrays.asList( generatePitchBendNRPN( vsq, track, ms_presend ) ) );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( listpit.size() > 0 ) {
|
|
|
|
|
list.addAll( listpit );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
boolean first = true;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
int last_note_end = 0;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
for ( int i = note_start; i <= note_end; i++ ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
VsqEvent item = target.getEvent( i );
|
|
|
|
|
if ( item.ID.type == VsqIDType.Anote ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
byte note_loc = (byte)0x03;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
if ( item.Clock == last_note_end ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
note_loc -= (byte)0x02;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 次に現れる音符イベントを探す
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int nextclock = item.Clock + item.ID.getLength() + 1;
|
|
|
|
|
int event_count = target.getEventCount();
|
|
|
|
|
for ( int j = i + 1; j < event_count; j++ ) {
|
|
|
|
|
VsqEvent itemj = target.getEvent( j );
|
|
|
|
|
if ( itemj.ID.type == VsqIDType.Anote ) {
|
|
|
|
|
nextclock = itemj.Clock;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( item.Clock + item.ID.getLength() == nextclock ) {
|
|
|
|
|
note_loc -= (byte)0x01;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
list.add( generateNoteNRPN( vsq,
|
2009-07-29 10:03:20 -07:00
|
|
|
|
track,
|
|
|
|
|
item,
|
2009-06-25 07:16:22 -07:00
|
|
|
|
msPreSend,
|
2009-07-29 10:03:20 -07:00
|
|
|
|
note_loc,
|
|
|
|
|
first ) );
|
|
|
|
|
first = false;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
list.addAll( Arrays.asList( generateVibratoNRPN( vsq,
|
|
|
|
|
item,
|
|
|
|
|
msPreSend ) ) );
|
|
|
|
|
last_note_end = item.Clock + item.ID.getLength();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
} else if ( item.ID.type == VsqIDType.Singer ) {
|
|
|
|
|
if ( i > note_start && i != singer_event ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
list.addAll( Arrays.asList( generateSingerNRPN( vsq, item, msPreSend ) ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-29 10:03:20 -07:00
|
|
|
|
list = VsqNrpn.sort( list );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Vector<VsqNrpn> merged = new Vector<VsqNrpn>();
|
|
|
|
|
for ( int i = 0; i < list.size(); i++ ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
merged.addAll( Arrays.asList( list.get( i ).expand() ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
return merged.toArray( new VsqNrpn[] { } );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定したトラックから、PitchBendのNRPNを作成します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="vsq"></param>
|
|
|
|
|
/// <param name="track"></param>
|
|
|
|
|
/// <param name="msPreSend"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static VsqNrpn[] generatePitchBendNRPN( VsqFile vsq, int track, int msPreSend ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Vector<VsqNrpn> ret = new Vector<VsqNrpn>();
|
|
|
|
|
VsqBPList pit = vsq.Track.get( track ).getCurve( "PIT" );
|
|
|
|
|
int count = pit.size();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
for ( int i = 0; i < count; i++ ) {
|
|
|
|
|
int clock = pit.getKeyClock( i );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int value = pit.getElement( i ) + 0x2000;
|
|
|
|
|
|
|
|
|
|
ValuePair<Byte, Byte> val = getMsbAndLsb( value );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
int c = clock - vsq.getPresendClockAt( clock, msPreSend );
|
|
|
|
|
if ( c >= 0 ) {
|
|
|
|
|
VsqNrpn add = new VsqNrpn( c,
|
|
|
|
|
NRPN.PB_PITCH_BEND,
|
2010-03-16 20:14:08 -07:00
|
|
|
|
val.getKey(),
|
|
|
|
|
val.getValue() );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
ret.add( add );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
return ret.toArray( new VsqNrpn[] { } );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定したトラックからPitchBendSensitivityのNRPNを作成します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="vsq"></param>
|
|
|
|
|
/// <param name="track"></param>
|
|
|
|
|
/// <param name="msPreSend"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static VsqNrpn[] generatePitchBendSensitivityNRPN( VsqFile vsq, int track, int msPreSend ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Vector<VsqNrpn> ret = new Vector<VsqNrpn>();
|
|
|
|
|
VsqBPList pbs = vsq.Track.get( track ).getCurve( "PBS" );
|
|
|
|
|
int count = pbs.size();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
for ( int i = 0; i < count; i++ ) {
|
|
|
|
|
int clock = pbs.getKeyClock( i );
|
|
|
|
|
int c = clock - vsq.getPresendClockAt( clock, msPreSend );
|
|
|
|
|
if ( c >= 0 ) {
|
|
|
|
|
VsqNrpn add = new VsqNrpn( c,
|
|
|
|
|
NRPN.CC_PBS_PITCH_BEND_SENSITIVITY,
|
|
|
|
|
(byte)pbs.getElement( i ),
|
2010-03-16 20:14:08 -07:00
|
|
|
|
(byte)0x00 );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
ret.add( add );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
return ret.toArray( new VsqNrpn[] { } );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定した音符イベントから,ビブラート出力用のNRPNを作成します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="vsq"></param>
|
|
|
|
|
/// <param name="ve"></param>
|
|
|
|
|
/// <param name="msPreSend"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static VsqNrpn[] generateVibratoNRPN( VsqFile vsq, VsqEvent ve, int msPreSend ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Vector<VsqNrpn> ret = new Vector<VsqNrpn>();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( ve.ID.VibratoHandle != null ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int vclock = ve.Clock + ve.ID.VibratoDelay;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
ValuePair<Byte, Byte> del = getMsbAndLsb( msPreSend );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqNrpn add2 = new VsqNrpn( vclock - vsq.getPresendClockAt( vclock, msPreSend ),
|
2009-07-29 10:03:20 -07:00
|
|
|
|
NRPN.CC_VD_VERSION_AND_DEVICE,
|
2010-03-16 20:14:08 -07:00
|
|
|
|
(byte)0x00,
|
|
|
|
|
(byte)0x00 );
|
|
|
|
|
add2.append( NRPN.CC_VD_DELAY, del.getKey(), del.getValue(), true );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
add2.append( NRPN.CC_VD_VIBRATO_DEPTH, (byte)ve.ID.VibratoHandle.StartDepth, true );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
add2.append( NRPN.CC_VR_VIBRATO_RATE, (byte)ve.ID.VibratoHandle.StartRate );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
ret.add( add2 );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int vlength = ve.ID.getLength() - ve.ID.VibratoDelay;
|
|
|
|
|
int count = ve.ID.VibratoHandle.RateBP.getCount();
|
|
|
|
|
if ( count > 0 ) {
|
|
|
|
|
for ( int i = 0; i < count; i++ ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
float percent = ve.ID.VibratoHandle.RateBP.getElement( i ).X;
|
|
|
|
|
int cl = vclock + (int)(percent * vlength);
|
2010-03-16 20:14:08 -07:00
|
|
|
|
ret.add( new VsqNrpn( cl - vsq.getPresendClockAt( cl, msPreSend ),
|
|
|
|
|
NRPN.CC_VR_VIBRATO_RATE,
|
|
|
|
|
(byte)ve.ID.VibratoHandle.RateBP.getElement( i ).Y ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
count = ve.ID.VibratoHandle.DepthBP.getCount();
|
|
|
|
|
if ( count > 0 ) {
|
|
|
|
|
for ( int i = 0; i < count; i++ ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
float percent = ve.ID.VibratoHandle.DepthBP.getElement( i ).X;
|
|
|
|
|
int cl = vclock + (int)(percent * vlength);
|
2010-03-16 20:14:08 -07:00
|
|
|
|
ret.add( new VsqNrpn( cl - vsq.getPresendClockAt( cl, msPreSend ),
|
|
|
|
|
NRPN.CC_VD_VIBRATO_DEPTH,
|
|
|
|
|
(byte)ve.ID.VibratoHandle.DepthBP.getElement( i ).Y ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Collections.sort( ret );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
return ret.toArray( new VsqNrpn[] { } );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定したトラックから、VoiceChangeParameterのNRPNのリストを作成します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="vsq"></param>
|
|
|
|
|
/// <param name="track"></param>
|
|
|
|
|
/// <param name="msPreSend"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static VsqNrpn[] generateVoiceChangeParameterNRPN( VsqFile vsq, int track, int msPreSend ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
int premeasure_clock = vsq.getPreMeasureClocks();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String renderer = vsq.Track.get( track ).getCommon().Version;
|
|
|
|
|
Vector<VsqNrpn> res = new Vector<VsqNrpn>();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String[] curves;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
if ( renderer.StartsWith( "DSB3" ) ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
curves = new String[] { "BRE", "BRI", "CLE", "POR", "OPE", "GEN" };
|
2009-07-29 10:03:20 -07:00
|
|
|
|
} else if ( renderer.StartsWith( "DSB2" ) ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
curves = new String[] { "BRE", "BRI", "CLE", "POR", "GEN", "harmonics",
|
2009-07-29 10:03:20 -07:00
|
|
|
|
"reso1amp", "reso1bw", "reso1freq",
|
|
|
|
|
"reso2amp", "reso2bw", "reso2freq",
|
|
|
|
|
"reso3amp", "reso3bw", "reso3freq",
|
|
|
|
|
"reso4amp", "reso4bw", "reso4freq" };
|
|
|
|
|
} else {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
curves = new String[] { "BRE", "BRI", "CLE", "POR", "GEN" };
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < curves.Length; i++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqBPList vbpl = vsq.Track.get( track ).getCurve( curves[i] );
|
|
|
|
|
if ( vbpl.size() > 0 ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
byte lsb = NRPN.getVoiceChangeParameterID( curves[i] );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int count = vbpl.size();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
for ( int j = 0; j < count; j++ ) {
|
|
|
|
|
int clock = vbpl.getKeyClock( j );
|
|
|
|
|
int c = clock - vsq.getPresendClockAt( clock, msPreSend );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( c >= 0 ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
VsqNrpn add = new VsqNrpn( c,
|
|
|
|
|
NRPN.VCP_VOICE_CHANGE_PARAMETER_ID,
|
|
|
|
|
lsb );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
add.append( NRPN.VCP_VOICE_CHANGE_PARAMETER, (byte)vbpl.getElement( j ), true );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
res.add( add );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Collections.sort( res );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
return res.toArray( new VsqNrpn[] { } );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
private static ValuePair<Byte, Byte> getMsbAndLsb( int value ) {
|
|
|
|
|
ValuePair<Byte, Byte> ret = new ValuePair<Byte, Byte>();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( 0x3fff < value ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
ret.setKey( (byte)0x7f );
|
|
|
|
|
ret.setValue( (byte)0x7f );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
} else {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
byte msb = (byte)(value >> 7);
|
|
|
|
|
ret.setKey( msb );
|
|
|
|
|
ret.setValue( (byte)(value - (msb << 7)) );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
return ret;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public Vector<MidiEvent> generateTimeSig() {
|
|
|
|
|
Vector<MidiEvent> events = new Vector<MidiEvent>();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator itr = TimesigTable.iterator(); itr.hasNext(); ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TimeSigTableEntry entry = (TimeSigTableEntry)itr.next();
|
|
|
|
|
events.add( MidiEvent.generateTimeSigEvent( entry.Clock, entry.Numerator, entry.Denominator ) );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
return events;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public Vector<MidiEvent> generateTempoChange() {
|
|
|
|
|
Vector<MidiEvent> events = new Vector<MidiEvent>();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator itr = TempoTable.iterator(); itr.hasNext(); ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTableEntry entry = (TempoTableEntry)itr.next();
|
|
|
|
|
events.add( MidiEvent.generateTempoChangeEvent( entry.Clock, entry.Tempo ) );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
//last_clock = Math.Max( last_clock, entry.Clock );
|
|
|
|
|
}
|
|
|
|
|
return events;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// このインスタンスをファイルに出力します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="file"></param>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public void write( String file ) {
|
|
|
|
|
write( file, 500, "Shift_JIS" );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// このインスタンスをファイルに出力します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
/// <param name="msPreSend">プリセンドタイム(msec)</param>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public void write( String file, int msPreSend, String encoding ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#if DEBUG
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.println( "VsqFile.Write(String)" );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endif
|
|
|
|
|
int last_clock = 0;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int track_size = Track.size();
|
|
|
|
|
for ( int track = 1; track < track_size; track++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( Track.get( track ).getEventCount() > 0 ) {
|
|
|
|
|
int index = Track.get( track ).getEventCount() - 1;
|
|
|
|
|
VsqEvent last = Track.get( track ).getEvent( index );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
last_clock = Math.Max( last_clock, last.Clock + last.ID.getLength() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( PortUtil.isFileExists( file ) ) {
|
|
|
|
|
try {
|
|
|
|
|
PortUtil.deleteFile( file );
|
|
|
|
|
} catch ( Exception ex ) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RandomAccessFile fs = null;
|
|
|
|
|
try {
|
|
|
|
|
fs = new RandomAccessFile( file, "rw" );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
long first_position;//チャンクの先頭のファイル位置
|
|
|
|
|
|
|
|
|
|
#region ヘッダ
|
|
|
|
|
//チャンクタイプ
|
2010-03-16 20:14:08 -07:00
|
|
|
|
fs.write( _MTHD, 0, 4 );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
//データ長
|
2010-03-16 20:14:08 -07:00
|
|
|
|
fs.write( (byte)0x00 );
|
|
|
|
|
fs.write( (byte)0x00 );
|
|
|
|
|
fs.write( (byte)0x00 );
|
|
|
|
|
fs.write( (byte)0x06 );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
//フォーマット
|
2010-03-16 20:14:08 -07:00
|
|
|
|
fs.write( (byte)0x00 );
|
|
|
|
|
fs.write( (byte)0x01 );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
//トラック数
|
2010-03-16 20:14:08 -07:00
|
|
|
|
writeUnsignedShort( fs, Track.size() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
//時間単位
|
2010-03-16 20:14:08 -07:00
|
|
|
|
fs.write( (byte)0x01 );
|
|
|
|
|
fs.write( (byte)0xe0 );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Master Track
|
|
|
|
|
//チャンクタイプ
|
2010-03-16 20:14:08 -07:00
|
|
|
|
fs.write( _MTRK, 0, 4 );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
//データ長。とりあえず0を入れておく
|
2010-03-16 20:14:08 -07:00
|
|
|
|
fs.write( new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, 0, 4 );
|
|
|
|
|
first_position = fs.getFilePointer();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
//トラック名
|
|
|
|
|
writeFlexibleLengthUnsignedLong( fs, 0 );//デルタタイム
|
2010-03-16 20:14:08 -07:00
|
|
|
|
fs.write( (byte)0xff );//ステータスタイプ
|
|
|
|
|
fs.write( (byte)0x03 );//イベントタイプSequence/Track Name
|
|
|
|
|
fs.write( (byte)_MASTER_TRACK.Length );//トラック名の文字数。これは固定
|
|
|
|
|
fs.write( _MASTER_TRACK, 0, _MASTER_TRACK.Length );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Vector<MidiEvent> events = new Vector<MidiEvent>();
|
|
|
|
|
for ( Iterator itr = TimesigTable.iterator(); itr.hasNext(); ) {
|
|
|
|
|
TimeSigTableEntry entry = (TimeSigTableEntry)itr.next();
|
|
|
|
|
events.add( MidiEvent.generateTimeSigEvent( entry.Clock, entry.Numerator, entry.Denominator ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
last_clock = Math.Max( last_clock, entry.Clock );
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator itr = TempoTable.iterator(); itr.hasNext(); ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
TempoTableEntry entry = (TempoTableEntry)itr.next();
|
|
|
|
|
events.add( MidiEvent.generateTempoChangeEvent( entry.Clock, entry.Tempo ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
last_clock = Math.Max( last_clock, entry.Clock );
|
|
|
|
|
}
|
|
|
|
|
#if DEBUG
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.println( " events.Count=" + events.size() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endif
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Collections.sort( events );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
long last = 0;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator itr = events.iterator(); itr.hasNext(); ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
MidiEvent me = (MidiEvent)itr.next();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#if DEBUG
|
2010-03-16 20:14:08 -07:00
|
|
|
|
PortUtil.println( "me.Clock=" + me.clock );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endif
|
2010-03-16 20:14:08 -07:00
|
|
|
|
writeFlexibleLengthUnsignedLong( fs, (long)(me.clock - last) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
me.writeData( fs );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
last = me.clock;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//WriteFlexibleLengthUnsignedLong( fs, (ulong)(last_clock + 120 - last) );
|
|
|
|
|
writeFlexibleLengthUnsignedLong( fs, 0 );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
fs.write( (byte)0xff );
|
|
|
|
|
fs.write( (byte)0x2f );//イベントタイプEnd of Track
|
|
|
|
|
fs.write( (byte)0x00 );
|
|
|
|
|
long pos = fs.getFilePointer();
|
|
|
|
|
fs.seek( first_position - 4 );
|
|
|
|
|
writeUnsignedInt( fs, pos - first_position );
|
|
|
|
|
fs.seek( pos );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region トラック
|
2010-03-16 20:14:08 -07:00
|
|
|
|
VsqFile temp = (VsqFile)this.clone();
|
|
|
|
|
temp.Track.get( 1 ).setMaster( (VsqMaster)Master.clone() );
|
|
|
|
|
temp.Track.get( 1 ).setMixer( (VsqMixer)Mixer.clone() );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
printTrack( temp, 1, fs, msPreSend, encoding );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int count = Track.size();
|
|
|
|
|
for ( int track = 2; track < count; track++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
printTrack( this, track, fs, msPreSend, encoding );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
2010-03-16 20:14:08 -07:00
|
|
|
|
} catch ( Exception ex ) {
|
|
|
|
|
} finally {
|
|
|
|
|
if ( fs != null ) {
|
|
|
|
|
try {
|
|
|
|
|
fs.close();
|
|
|
|
|
} catch ( Exception ex2 ) {
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// メタテキストの行番号から、各行先頭のプレフィクス文字列("DM:0123:"等)を作成します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="count"></param>
|
|
|
|
|
/// <returns></returns>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public static String getLinePrefix( int count ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int digits = getHowManyDigits( count );
|
|
|
|
|
int c = (digits - 1) / 4 + 1;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String format = "";
|
2009-06-25 07:16:22 -07:00
|
|
|
|
for ( int i = 0; i < c; i++ ) {
|
|
|
|
|
format += "0000";
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
return "DM:" + PortUtil.formatDecimal( format, count ) + ":";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static byte[] getLinePrefixBytes( int count ) {
|
|
|
|
|
int digits = getHowManyDigits( count );
|
|
|
|
|
int c = (digits - 1) / 4 + 1;
|
|
|
|
|
String format = "";
|
|
|
|
|
for ( int i = 0; i < c; i++ ) {
|
|
|
|
|
format += "0000";
|
|
|
|
|
}
|
|
|
|
|
String str = "DM:" + PortUtil.formatDecimal( format, count ) + ":";
|
|
|
|
|
byte[] ret = PortUtil.getEncodedByte( "ASCII", str );
|
|
|
|
|
return ret;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 数numberの桁数を調べます。(10進数のみ)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="number"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private static int getHowManyDigits( int number ) {
|
|
|
|
|
int val;
|
|
|
|
|
if ( number > 0 ) {
|
|
|
|
|
val = number;
|
|
|
|
|
} else {
|
|
|
|
|
val = -number;
|
|
|
|
|
}
|
|
|
|
|
int i = 1;
|
|
|
|
|
int digits = 1;
|
|
|
|
|
while ( true ) {
|
|
|
|
|
i++;
|
|
|
|
|
digits *= 10;
|
|
|
|
|
if ( val < digits ) {
|
|
|
|
|
return i - 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// char[]を書き込む。
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="fs"></param>
|
|
|
|
|
/// <param name="item"></param>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public static void writeCharArray( RandomAccessFile fs, char[] item )
|
|
|
|
|
#if JAVA
|
|
|
|
|
throws IOException
|
|
|
|
|
#endif
|
|
|
|
|
{
|
2009-06-25 07:16:22 -07:00
|
|
|
|
for ( int i = 0; i < item.Length; i++ ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
fs.write( (byte)item[i] );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// ushort値をビッグエンディアンでfsに書き込みます
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="data"></param>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public static void writeUnsignedShort( RandomAccessFile fs, int data )
|
|
|
|
|
#if JAVA
|
|
|
|
|
throws IOException
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
byte[] dat = PortUtil.getbytes_uint16_be( data );
|
|
|
|
|
fs.write( dat, 0, dat.Length );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// uint値をビッグエンディアンでfsに書き込みます
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="data"></param>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public static void writeUnsignedInt( RandomAccessFile fs, long data )
|
|
|
|
|
#if JAVA
|
|
|
|
|
throws IOException
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
byte[] dat = PortUtil.getbytes_uint32_be( data );
|
|
|
|
|
fs.write( dat, 0, dat.Length );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// SMFの可変長数値表現を使って、ulongをbyte[]に変換します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="number"></param>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public static byte[] getBytesFlexibleLengthUnsignedLong( long number ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
boolean[] bits = new boolean[64];
|
2010-03-16 20:14:08 -07:00
|
|
|
|
long val = (byte)0x1;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
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;
|
|
|
|
|
byte[] ret = new byte[bytes];
|
|
|
|
|
for ( int i = 1; i <= bytes; i++ ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int num = 0;
|
|
|
|
|
int count = (byte)0x80;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
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 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
num += (byte)0x80;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
ret[i - 1] = (byte)num;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 整数を書き込む。フォーマットはSMFの可変長数値表現。
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="fs"></param>
|
|
|
|
|
/// <param name="number"></param>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public static void writeFlexibleLengthUnsignedLong( RandomAccessFile fs, long number )
|
|
|
|
|
#if JAVA
|
|
|
|
|
throws IOException
|
|
|
|
|
#endif
|
|
|
|
|
{
|
2009-06-25 07:16:22 -07:00
|
|
|
|
byte[] bytes = getBytesFlexibleLengthUnsignedLong( number );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
fs.write( bytes, 0, bytes.Length );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if !JAVA
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|