2009-06-25 07:16:22 -07:00
|
|
|
|
/*
|
|
|
|
|
* VsqTrack.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
|
|
|
|
#if JAVA
|
|
|
|
|
package org.kbinani.vsq;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
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;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|
2009-09-07 03:44:18 -07:00
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Stores the data of a vsq track.
|
|
|
|
|
/// </summary>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if JAVA
|
|
|
|
|
public class VsqTrack implements Cloneable, Serializable {
|
|
|
|
|
#else
|
2009-06-25 07:16:22 -07:00
|
|
|
|
[Serializable]
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public class VsqTrack : ICloneable {
|
|
|
|
|
#endif
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public String Tag;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// トラックの名前。
|
|
|
|
|
/// </summary>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
//public String Name;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
public VsqMetaText MetaText;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
private int m_edited_start = int.MaxValue;
|
|
|
|
|
private int m_edited_end = int.MinValue;
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if JAVA
|
|
|
|
|
private class SingerEventIterator implements Iterator{
|
|
|
|
|
#else
|
2009-06-25 07:16:22 -07:00
|
|
|
|
private class SingerEventIterator : Iterator {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEventList m_list;
|
|
|
|
|
int m_pos;
|
|
|
|
|
|
|
|
|
|
public SingerEventIterator( VsqEventList list ) {
|
|
|
|
|
m_list = list;
|
|
|
|
|
m_pos = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public boolean hasNext() {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
for ( int i = m_pos + 1; i < m_list.getCount(); i++ ) {
|
|
|
|
|
if ( m_list.getElement( i ).ID.type == VsqIDType.Singer ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public Object next() {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
for ( int i = m_pos + 1; i < m_list.getCount(); i++ ) {
|
|
|
|
|
VsqEvent item = m_list.getElement( i );
|
|
|
|
|
if ( item.ID.type == VsqIDType.Singer ) {
|
|
|
|
|
m_pos = i;
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void remove() {
|
|
|
|
|
if ( 0 <= m_pos && m_pos < m_list.getCount() ) {
|
|
|
|
|
m_list.removeAt( m_pos );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if JAVA
|
|
|
|
|
private class NoteEventIterator implements Iterator{
|
|
|
|
|
#else
|
2009-06-25 07:16:22 -07:00
|
|
|
|
private class NoteEventIterator : Iterator {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEventList m_list;
|
|
|
|
|
int m_pos;
|
|
|
|
|
|
|
|
|
|
public NoteEventIterator( VsqEventList list ) {
|
|
|
|
|
m_list = list;
|
|
|
|
|
m_pos = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public boolean hasNext() {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int count = m_list.getCount();
|
|
|
|
|
for ( int i = m_pos + 1; i < count; i++ ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( m_list.getElement( i ).ID.type == VsqIDType.Anote ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public Object next() {
|
|
|
|
|
int count = m_list.getCount();
|
|
|
|
|
for ( int i = m_pos + 1; i < count; i++ ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqEvent item = m_list.getElement( i );
|
|
|
|
|
if ( item.ID.type == VsqIDType.Anote ) {
|
|
|
|
|
m_pos = i;
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void remove() {
|
|
|
|
|
if ( 0 <= m_pos && m_pos < m_list.getCount() ) {
|
|
|
|
|
m_list.removeAt( m_pos );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if JAVA
|
|
|
|
|
private class EventIterator implements Iterator{
|
|
|
|
|
#else
|
|
|
|
|
private class EventIterator : Iterator {
|
|
|
|
|
#endif
|
2009-06-25 07:16:22 -07:00
|
|
|
|
private VsqEventList m_list;
|
|
|
|
|
private int m_pos;
|
|
|
|
|
|
|
|
|
|
public EventIterator( VsqEventList list ) {
|
|
|
|
|
m_list = list;
|
|
|
|
|
m_pos = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public boolean hasNext() {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( 0 <= m_pos + 1 && m_pos + 1 < m_list.getCount() ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Object next() {
|
|
|
|
|
m_pos++;
|
|
|
|
|
return m_list.getElement( m_pos );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void remove() {
|
|
|
|
|
if ( 0 <= m_pos && m_pos < m_list.getCount() ) {
|
|
|
|
|
m_list.removeAt( m_pos );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public String getName() {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( MetaText == null || (MetaText != null && MetaText.Common == null) ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
return "Master Track";
|
|
|
|
|
} else {
|
|
|
|
|
return MetaText.Common.Name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setName( String value ) {
|
|
|
|
|
if ( MetaText != null ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
if ( MetaText.Common == null ) {
|
|
|
|
|
MetaText.Common = new VsqCommon();
|
|
|
|
|
}
|
2009-09-07 03:44:18 -07:00
|
|
|
|
MetaText.Common.Name = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if !JAVA
|
2009-09-07 03:44:18 -07:00
|
|
|
|
[Obsolete]
|
|
|
|
|
public String Name {
|
|
|
|
|
get {
|
|
|
|
|
return getName();
|
|
|
|
|
}
|
|
|
|
|
set {
|
|
|
|
|
setName( value );
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|
2009-09-07 03:44:18 -07:00
|
|
|
|
|
2009-07-30 08:02:59 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// ピッチベンド。Cent単位
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="clock"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public double getPitchAt( int clock ) {
|
|
|
|
|
double inv2_13 = 1.0 / 8192.0;
|
|
|
|
|
int pit = MetaText.PIT.getValue( clock );
|
|
|
|
|
int pbs = MetaText.PBS.getValue( clock );
|
|
|
|
|
return (double)pit * (double)pbs * inv2_13 * 100.0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定したクロック位置において、歌唱を担当している歌手のVsqEventを返します。
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="clock"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public VsqEvent getSingerEventAt( int clock ) {
|
|
|
|
|
VsqEvent last = null;
|
|
|
|
|
for ( Iterator itr = getSingerEventIterator(); itr.hasNext(); ) {
|
|
|
|
|
VsqEvent item = (VsqEvent)itr.next();
|
|
|
|
|
if ( clock < item.Clock ) {
|
|
|
|
|
return last;
|
|
|
|
|
}
|
|
|
|
|
last = item;
|
|
|
|
|
}
|
|
|
|
|
return last;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-29 10:03:20 -07:00
|
|
|
|
public void sortEvent() {
|
|
|
|
|
MetaText.Events.sort();
|
|
|
|
|
}
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 歌手変更イベントを,曲の先頭から順に返すIteratorを取得します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Iterator getSingerEventIterator() {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
return new SingerEventIterator( MetaText.getEventList() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 音符イベントを,曲の先頭から順に返すIteratorを取得します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Iterator getNoteEventIterator() {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
if ( MetaText == null ) {
|
|
|
|
|
return new NoteEventIterator( new VsqEventList() );
|
|
|
|
|
} else {
|
|
|
|
|
return new NoteEventIterator( MetaText.getEventList() );
|
|
|
|
|
}
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// メタテキストを,メモリー上のストリームに出力します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sw"></param>
|
|
|
|
|
/// <param name="encode"></param>
|
|
|
|
|
/// <param name="eos"></param>
|
|
|
|
|
/// <param name="start"></param>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public void printMetaText( TextMemoryStream sw, int eos, int start )
|
|
|
|
|
#if JAVA
|
|
|
|
|
throws IOException
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
MetaText.print( sw, eos, start );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// メタテキストを,指定されたファイルに出力します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="file"></param>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public void printMetaText( String file )
|
|
|
|
|
#if JAVA
|
|
|
|
|
throws IOException
|
|
|
|
|
#endif
|
|
|
|
|
{
|
2009-07-30 08:02:59 -07:00
|
|
|
|
TextMemoryStream tms = new TextMemoryStream();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
int count = MetaText.getEventList().getCount();
|
|
|
|
|
int clLast = MetaText.getEventList().getElement( count - 1 ).Clock + 480;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
MetaText.print( tms, clLast, 0 );
|
|
|
|
|
BufferedWriter sw = null;
|
|
|
|
|
try {
|
|
|
|
|
sw = new BufferedWriter( new FileWriter( file ) );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
tms.rewind();
|
|
|
|
|
while ( tms.peek() >= 0 ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String line = tms.readLine();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
sw.write( line );
|
|
|
|
|
sw.newLine();
|
|
|
|
|
}
|
|
|
|
|
} catch ( Exception ex ) {
|
|
|
|
|
} finally {
|
|
|
|
|
if ( sw != null ) {
|
|
|
|
|
try {
|
|
|
|
|
sw.close();
|
|
|
|
|
} catch ( Exception ex2 ) {
|
|
|
|
|
}
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Masterを取得します
|
|
|
|
|
/// </summary>
|
|
|
|
|
public VsqMaster getMaster() {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
return MetaText.master;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public void setMaster( VsqMaster value ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
MetaText.master = value;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Mixerを取得します
|
|
|
|
|
/// </summary>
|
|
|
|
|
public VsqMixer getMixer() {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
return MetaText.mixer;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public void setMixer( VsqMixer value ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
MetaText.mixer = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Commonを取得します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public VsqCommon getCommon() {
|
|
|
|
|
return MetaText.Common;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定したトラックのレンダラーを変更します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="track"></param>
|
|
|
|
|
/// <param name="new_renderer"></param>
|
|
|
|
|
/// <param name="singers"></param>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public void changeRenderer( String new_renderer, Vector<VsqID> singers ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
VsqID default_id = null;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int singers_size = singers.size();
|
|
|
|
|
if ( singers_size <= 0 ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
default_id = new VsqID();
|
|
|
|
|
default_id.type = VsqIDType.Singer;
|
|
|
|
|
default_id.IconHandle = new IconHandle();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
default_id.IconHandle.IconID = "$0701" + PortUtil.toHexString( 0, 4 );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
default_id.IconHandle.IDS = "Unknown";
|
|
|
|
|
default_id.IconHandle.Index = 0;
|
|
|
|
|
default_id.IconHandle.Language = 0;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
default_id.IconHandle.setLength( 1 );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
default_id.IconHandle.Original = 0;
|
|
|
|
|
default_id.IconHandle.Program = 0;
|
|
|
|
|
default_id.IconHandle.Caption = "";
|
|
|
|
|
} else {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
default_id = singers.get( 0 );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
|
2009-07-29 10:03:20 -07:00
|
|
|
|
for ( Iterator itr = getSingerEventIterator(); itr.hasNext(); ) {
|
|
|
|
|
VsqEvent ve = (VsqEvent)itr.next();
|
|
|
|
|
int program = ve.ID.IconHandle.Program;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
boolean found = false;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( int i = 0; i < singers_size; i++ ) {
|
|
|
|
|
VsqID id = singers.get( i );
|
|
|
|
|
if ( program == id.IconHandle.Program ) {
|
|
|
|
|
ve.ID = (VsqID)id.clone();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( !found ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqID add = (VsqID)default_id.clone();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
add.IconHandle.Program = program;
|
|
|
|
|
ve.ID = add;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
MetaText.Common.Version = new_renderer;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// このトラックが保持している,指定されたカーブのBPListを取得します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="curve"></param>
|
|
|
|
|
/// <returns></returns>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public VsqBPList getCurve( String curve ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
return MetaText.getElement( curve );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public void setCurve( String curve, VsqBPList value ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
MetaText.setElement( curve, value );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getEventCount() {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
return MetaText.getEventList().getCount();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public VsqEvent getEvent( int index ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
return MetaText.getEventList().getElement( index );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-30 08:02:59 -07:00
|
|
|
|
public VsqEvent findEventFromID( int internal_id ) {
|
|
|
|
|
return MetaText.getEventList().findFromID( internal_id );
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
public void setEvent( int index, VsqEvent item ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
MetaText.getEventList().setElement( index, item );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addEvent( VsqEvent item ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
MetaText.getEventList().add( item );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Iterator getEventIterator() {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
return new EventIterator( MetaText.getEventList() );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removeEvent( int index ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
MetaText.getEventList().removeAt( index );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// このトラックの,最後に編集が加えられた範囲の,開始位置(クロック)を取得します.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int getEditedStart() {
|
|
|
|
|
return m_edited_start;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-29 10:03:20 -07:00
|
|
|
|
public void setEditedStart( int value ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( value < m_edited_start ) {
|
|
|
|
|
m_edited_start = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// このトラックの,最後に編集が加えられた範囲の,終了位置(クロック)を取得します.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int getEditedEnd() {
|
|
|
|
|
return m_edited_end;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-29 10:03:20 -07:00
|
|
|
|
public void setEditedEnd( int value ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( m_edited_end < value ) {
|
|
|
|
|
m_edited_end = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// このトラックの,編集範囲(EditedStart, EditedEnd)をリセットします.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void resetEditedArea() {
|
|
|
|
|
m_edited_start = int.MaxValue;
|
|
|
|
|
m_edited_end = int.MinValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// このインスタンスのコピーを作成します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public Object clone() {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
VsqTrack res = new VsqTrack();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
res.setName( getName() );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
if ( MetaText != null ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
res.MetaText = (VsqMetaText)MetaText.clone();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
res.m_edited_start = m_edited_start;
|
|
|
|
|
res.m_edited_end = m_edited_end;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
res.Tag = Tag;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if !JAVA
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public object Clone() {
|
|
|
|
|
return clone();
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|
2009-09-07 03:44:18 -07:00
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Master Trackを構築
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="tempo"></param>
|
|
|
|
|
/// <param name="numerator"></param>
|
|
|
|
|
/// <param name="denominator"></param>
|
|
|
|
|
public VsqTrack( int tempo, int numerator, int denominator ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
//this.Name = "Master Track";
|
|
|
|
|
// metatextがnullのとき,トラック名はMaster Track
|
2009-07-29 10:03:20 -07:00
|
|
|
|
this.MetaText = null;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Master Trackでないトラックを構築。
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name"></param>
|
|
|
|
|
/// <param name="singer"></param>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public VsqTrack( String name, String singer ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
MetaText = new VsqMetaText( name, singer );
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if JAVA
|
|
|
|
|
public VsqTrack(){
|
|
|
|
|
this( "Voice1", "Miku" );
|
|
|
|
|
#else
|
2009-07-29 10:03:20 -07:00
|
|
|
|
public VsqTrack()
|
|
|
|
|
: this( "Voice1", "Miku" ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 歌詞の文字数を調べます
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int getLyricLength() {
|
|
|
|
|
int counter = 0;
|
2009-07-29 10:03:20 -07:00
|
|
|
|
for ( int i = 0; i < MetaText.getEventList().getCount(); i++ ) {
|
|
|
|
|
if ( MetaText.getEventList().getElement( i ).ID.type == VsqIDType.Anote ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
counter++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return counter;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
public VsqTrack( Vector<MidiEvent> midi_event, String encoding ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
#if DEBUG
|
|
|
|
|
bocoree.debug.push_log( "VsqTrack..ctor" );
|
|
|
|
|
#endif
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String track_name = "";
|
2010-03-16 20:14:08 -07:00
|
|
|
|
|
|
|
|
|
TextMemoryStream sw = null;
|
|
|
|
|
try {
|
|
|
|
|
sw = new TextMemoryStream();
|
|
|
|
|
int count = midi_event.size();
|
|
|
|
|
Vector<Byte> buffer = new Vector<Byte>();
|
|
|
|
|
for ( int i = 0; i < count; i++ ) {
|
|
|
|
|
MidiEvent item = midi_event.get( i );
|
|
|
|
|
if ( item.firstByte == 0xff && item.data.Length > 0 ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
// meta textを抽出
|
2010-03-16 20:14:08 -07:00
|
|
|
|
byte type = item.data[0];
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( type == 0x01 || type == 0x03 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
//String line = PortUtil.getDecodedString( encoding, dat, 1, dat.Length - 1 );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
if ( type == 0x01 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int colon_count = 0;
|
|
|
|
|
for ( int j = 0; j < item.data.Length - 1; j++ ) {
|
|
|
|
|
byte d = item.data[j + 1];
|
|
|
|
|
if ( d == 0x3a ) {
|
|
|
|
|
colon_count++;
|
|
|
|
|
if ( colon_count <= 2 ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( colon_count < 2 ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
buffer.add( d );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int index_0x0a = buffer.indexOf( 0x0a );
|
|
|
|
|
while ( index_0x0a >= 0 ) {
|
|
|
|
|
byte[] cpy = new byte[index_0x0a];
|
|
|
|
|
for ( int j = 0; j < index_0x0a; j++ ) {
|
|
|
|
|
cpy[j] = buffer.get( 0 );
|
|
|
|
|
buffer.removeElementAt( 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String line = PortUtil.getDecodedString( encoding, cpy );
|
|
|
|
|
sw.writeLine( line );
|
|
|
|
|
buffer.removeElementAt( 0 );
|
|
|
|
|
index_0x0a = buffer.indexOf( 0x0a );
|
|
|
|
|
}
|
|
|
|
|
/*int second_colon = line.IndexOf( ':', 3 );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
line = line.Substring( second_colon + 1 );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
line = line.Replace( "\\n", "\n" );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
String[] lines = PortUtil.splitString( line, '\n' );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
int c = lines.Length;
|
|
|
|
|
for ( int j = 0; j < c; j++ ) {
|
|
|
|
|
if ( j < c - 1 ) {
|
|
|
|
|
sw.writeLine( lines[j] );
|
|
|
|
|
} else {
|
|
|
|
|
sw.write( lines[j] );
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
}*/
|
2009-06-25 07:16:22 -07:00
|
|
|
|
} else {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( int j = 0; j < item.data.Length - 1; j++ ) {
|
|
|
|
|
buffer.add( item.data[j + 1] );
|
|
|
|
|
}
|
|
|
|
|
track_name = PortUtil.getDecodedString( encoding,
|
|
|
|
|
PortUtil.convertByteArray( buffer.toArray( new Byte[] { } ) ) );
|
|
|
|
|
#if DEBUG
|
|
|
|
|
Console.WriteLine( "VsqTrack#.ctor; track_name=" + track_name );
|
|
|
|
|
#endif
|
|
|
|
|
buffer.clear();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sw.rewind();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
MetaText = new VsqMetaText( sw );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
setName( track_name );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
} catch ( Exception ex ) {
|
|
|
|
|
PortUtil.println( "com.boare.vsq.VsqTrack#.ctor; ex=" + 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
|
|
|
|
#if !JAVA
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|