Created
November 2, 2017 17:59
-
-
Save tatmos/16632d643ff0f40a06fe4f6c6ec793a7 to your computer and use it in GitHub Desktop.
2016年くらいのADX2LEのプレーヤーのSoundManager。CPU負荷とかも表示してる。簡易なファイルブラウザやOSC(OpenSoundControl)も。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.UI; | |
using System.Collections; | |
using System.Collections.Generic; // 配列用 | |
using System; | |
using System.IO; | |
using System.Net; | |
using System.Threading; | |
using System.Net.Sockets; | |
public class OscPlayer | |
{ | |
public OscPlayer() | |
{ | |
} | |
public CriAtomSource atomSource; | |
public float[] aisaControlValue = new float[8]; | |
public CriAtomExPlayback playback; | |
public int selCueNo = 0; | |
public int selBlockNo = 0; | |
public int currentBlockNo = 0; | |
} | |
public class SoundManager : MonoBehaviour { | |
public Text memoryUsage; | |
public Text fsMemoryUsage; | |
public Text cpuLoad; | |
public GameObject filePanel; | |
public GameObject fileButton; | |
public InputField filePathInputField; | |
public Text loadFileName; | |
public Text textCueName; | |
public Text textCueTime; | |
private string cueSheetName = "CueSheet_0"; | |
private string lastCueSheetPath = "CueSheet_0"; | |
private string acfName = "NewProject"; | |
static List<OscPlayer> oscPlayerList = new List<OscPlayer>(); | |
// static List<CriAtomSource> atomSourceSeList = new List<CriAtomSource>(); | |
// static List<int> selCueNo = new List<int>(); | |
// static List<int> selBlockNo = new List<int>(); | |
static Dictionary<int,CriAtomEx.CueInfo> cueIdCueInfoDictionary = new Dictionary<int, CriAtomEx.CueInfo>(); | |
static Dictionary<int,CriAtomEx.CueInfo> cueIndexCueInfoDictionary = new Dictionary<int, CriAtomEx.CueInfo>(); | |
CriAtomEx.CueInfo[] cueInfoList; | |
public Texture2D _debugLevelTex; | |
void Awake () | |
{ | |
//_debugLevelTex = new Texture2D(16,16); | |
} | |
void Start () | |
{ | |
DefaultLoadPath(); | |
AcbSetUp(); | |
memoryUsage = GameObject.Find("MemoryUsage").GetComponent<Text>(); | |
fsMemoryUsage = GameObject.Find("FsMemoryUsage").GetComponent<Text>(); | |
cpuLoad = GameObject.Find("CPULoad").GetComponent<Text>(); | |
filePathInputField = GameObject.Find("FilePathInputField").GetComponent<InputField>(); | |
loadFileName = GameObject.Find("LoadFileNameText").GetComponent<Text>(); | |
filePanel = GameObject.Find("FilePanel"); | |
fileButton = GameObject.Find ("ButtonFile"); | |
filePanel.GetComponent<RectTransform>().localScale = new Vector3(0,0,0); | |
fileButton.gameObject.SetActive(false); | |
} | |
void DefaultLoadPath() | |
{ | |
loadPath = Application.dataPath; | |
if (Application.platform == RuntimePlatform.OSXEditor){ | |
loadPath += "/StreamingAssets"; | |
} | |
if (Application.platform == RuntimePlatform.OSXPlayer){ | |
loadPath += "/Data/StreamingAssets"; | |
} | |
if (Application.platform == RuntimePlatform.WindowsPlayer){ | |
loadPath += "/StreamingAssets"; | |
} | |
} | |
void AcbSetUp() | |
{ | |
//--------------- CueInfoList ------------------ | |
CriAtomExAcb acb = CriAtom.GetAcb (cueSheetName); | |
cueInfoList = acb.GetCueInfoList (); | |
cueIdCueInfoDictionary.Clear(); | |
cueIndexCueInfoDictionary.Clear(); | |
{ | |
int i = 0; | |
foreach (CriAtomEx.CueInfo cueInfo in cueInfoList) { | |
cueIdCueInfoDictionary.Add(cueInfo.id,cueInfo); | |
cueIndexCueInfoDictionary.Add(i,cueInfo); | |
i++; | |
} | |
} | |
//-------------- AtomSource ----------------- | |
//selCueNo.Clear(); | |
//selBlockNo.Clear(); | |
foreach(OscPlayer oscPlayer in oscPlayerList) | |
{ | |
GameObject.Destroy(oscPlayer.atomSource); | |
} | |
oscPlayerList.Clear(); | |
//atomSourceSeList.Clear(); | |
for(int i =0;i<32;i++){ | |
OscPlayer oscPlayer = new OscPlayer(); | |
oscPlayer.atomSource = gameObject.AddComponent<CriAtomSource> (); | |
oscPlayer.atomSource.SetAisac(0,0); | |
oscPlayer.atomSource.SetAisac(1,0); | |
oscPlayer.atomSource.cueSheet = cueSheetName; | |
oscPlayer.atomSource.cueName = cueIndexCueInfoDictionary[0].name; | |
oscPlayer.selCueNo = cueIndexCueInfoDictionary[0].id; | |
oscPlayer.selBlockNo = 0; | |
oscPlayerList.Add(oscPlayer); | |
} | |
//--------------- DSPBus ------------- | |
CriAtomEx.AttachDspBusSetting("DspBusSetting_0"); | |
CriAtom.SetBusAnalyzer(true); // レベルメータを有効化 | |
UpdateCueName(0); | |
} | |
public bool soundDebug = true; | |
public GUISkin skin; | |
//CriAtomExPlayback playback; | |
bool fileLoadMode = false; | |
CriAtomExAsr.BusAnalyzerInfo lBusInfo; | |
void Update() | |
{ | |
lBusInfo = CriAtom.GetBusAnalyzerInfo(0); //バス0 | |
memoryUsage.text = String.Format("Memory Usage:{0,8:D}",CriWare.GetAtomMemoryUsage()); | |
fsMemoryUsage.text = String.Format("FileSystem Usage{0,8:D}",CriWare.GetFsMemoryUsage()); | |
cpuLoad.text = String.Format("CPU : {0,3:N}%",CriWare.GetAtomCpuUsage().last); | |
loadFileName.text = string.Format("{0}.acf {1}.acb",acfName,cueSheetName); | |
UpdateCueTime(0); | |
} | |
protected static float maxBarLength = 90.0f; | |
void GUI_LevelMeter() | |
{ | |
maxBarLength = Screen.width; | |
float barWidth = 4f; | |
//GUILayout.Label(string.Format("L:{0:F3}",lBusInfo.peakLevels[0])); | |
GUILayout.Space(barWidth); | |
Rect r = GUILayoutUtility.GetLastRect(); | |
r.y+=4; | |
r.width = Mathf.Clamp(100.0f*lBusInfo.peakLevels[0], -maxBarLength, maxBarLength); | |
Color lastColor = GUI.contentColor; | |
GUI.color = Color.green;GUI.color *= 0.7f; | |
GUI.DrawTexture(r, _debugLevelTex, ScaleMode.StretchToFill, false, 0.0f); | |
GUI.color = lastColor; | |
//GUILayout.Label(string.Format("R:{0:F3}",lBusInfo.peakLevels[1])); | |
GUILayout.Space(barWidth); | |
r = GUILayoutUtility.GetLastRect(); | |
r.y+=4; | |
r.width = Mathf.Clamp(100.0f*lBusInfo.peakLevels[1], -maxBarLength, maxBarLength); | |
GUI.color = Color.green; | |
GUI.color *= 0.7f; | |
GUI.DrawTexture(r, _debugLevelTex, ScaleMode.StretchToFill, false, 0.0f); | |
GUI.color = lastColor; | |
//GUILayout.Label(string.Format("C:{0:F3}",lBusInfo.peakLevels[2])); | |
GUILayout.Space(barWidth); | |
r = GUILayoutUtility.GetLastRect(); | |
r.y+=4; | |
r.width = Mathf.Clamp(100.0f*lBusInfo.peakLevels[2], -maxBarLength, maxBarLength); | |
GUI.color = Color.green;GUI.color *= 0.7f; | |
GUI.DrawTexture(r, _debugLevelTex, ScaleMode.StretchToFill, false, 0.0f); | |
GUI.color = lastColor; | |
//GUILayout.Label(string.Format("LFE:{0:F3}",lBusInfo.peakLevels[3])); | |
GUILayout.Space(barWidth); | |
r = GUILayoutUtility.GetLastRect(); | |
r.y+=4; | |
r.width = Mathf.Clamp(100.0f*lBusInfo.peakLevels[3], -maxBarLength, maxBarLength); | |
GUI.color = Color.green;GUI.color *= 0.7f; | |
GUI.DrawTexture(r, _debugLevelTex, ScaleMode.StretchToFill, false, 0.0f); | |
GUI.color = lastColor; | |
//GUILayout.Label(string.Format("SL:{0:F3}",lBusInfo.peakLevels[4])); | |
GUILayout.Space(barWidth); | |
r = GUILayoutUtility.GetLastRect(); | |
r.y+=4; | |
r.width = Mathf.Clamp(100.0f*lBusInfo.peakLevels[4], -maxBarLength, maxBarLength); | |
GUI.color = Color.green;GUI.color *= 0.7f; | |
GUI.DrawTexture(r, _debugLevelTex, ScaleMode.StretchToFill, false, 0.0f); | |
GUI.color = lastColor; | |
//GUILayout.Label(string.Format("SR:{0:F3}",lBusInfo.peakLevels[5])); | |
GUILayout.Space(barWidth); | |
r = GUILayoutUtility.GetLastRect(); | |
r.y+=4; | |
r.width = Mathf.Clamp(100.0f*lBusInfo.peakLevels[5], -maxBarLength, maxBarLength); | |
GUI.color = Color.green;GUI.color *= 0.7f; | |
GUI.DrawTexture(r, _debugLevelTex, ScaleMode.StretchToFill, false, 0.0f); | |
GUI.color = lastColor; | |
} | |
#if UNITY_IOS | |
int pathLisetHeaderPos = 42*2; | |
int pathLisetHeaderPos2 = (42+48)*2; | |
#else | |
int pathLisetHeaderPos = 42; | |
int pathLisetHeaderPos2 = 42+48; | |
#endif | |
public void Panic() | |
{ | |
this.AllStop(); | |
Application.LoadLevel(0); | |
} | |
public void OpenFilePanel() | |
{ | |
fileLoadMode = true; | |
filePanel.GetComponent<RectTransform>().localScale = new Vector3(1,1,1); | |
files = Directory.GetFiles(loadPath); | |
directories = Directory.GetDirectories(loadPath); | |
// filePanel.gameObject.SetActive(true); | |
UpdateFileList(); | |
} | |
public void FileButtonClick(GameObject go) | |
{ | |
var text = go.GetComponentInChildren<Text>(); | |
string fileName = text.text; | |
if(Path.GetExtension(fileName) == ".acb"){ | |
LoadACB(filePathInputField.text + "/" +fileName); | |
CloseFilePanel(); | |
} else | |
if(Path.GetExtension(fileName) == ".acf"){ | |
LoadACF(filePathInputField.text + "/" + fileName); | |
CloseFilePanel(); | |
} else | |
{ | |
loadPath += fileName; | |
files = Directory.GetFiles(loadPath); | |
directories = Directory.GetDirectories(loadPath); | |
} | |
UpdateFileList(); | |
} | |
public void CloseFilePanel() | |
{ | |
fileLoadMode = false; | |
// filePanel.SetActive(false); | |
filePanel.GetComponent<RectTransform>().localScale = new Vector3(0f,0f,0f); | |
} | |
public void GoUpperDirectory() | |
{ | |
if(loadPath != "/"){ | |
loadPath = Path.GetDirectoryName(loadPath); | |
} else { | |
loadPath = "/"; | |
} | |
UpdateFileList(); | |
} | |
public void FileNameEditEnd(string inputName) | |
{ | |
if(Directory.Exists(inputName)){ | |
loadPath = inputName; | |
} | |
UpdateFileList(); | |
} | |
List<GameObject> fileButtonList = new List<GameObject>(); | |
public void UpdateFileList() | |
{ | |
files = Directory.GetFiles(loadPath); | |
directories = Directory.GetDirectories(loadPath); | |
filePathInputField.text = loadPath; | |
// | |
foreach(GameObject go in fileButtonList){ | |
GameObject.Destroy(go); | |
} | |
fileButtonList = new List<GameObject>(); | |
// string dir = outputpath; | |
// string[] files = Directory.GetFiles(dir); | |
int colorRow = 0; | |
foreach (string s in files) { | |
if(Path.GetExtension(s) == ".acb" || | |
Path.GetExtension(s) == ".acf" | |
){ | |
var item = GameObject.Instantiate(fileButton) as GameObject; | |
item.SetActive(true); | |
fileButtonList.Add(item); | |
item.GetComponent<RectTransform>().SetParent(fileButton.transform.parent, false); | |
var text = item.GetComponentInChildren<Text>(); | |
text.text = System.IO.Path.GetFileName(s); | |
// var image = item.GetComponent<Image>(); | |
// image.color = ColorHSV.FromHsv(((colorRow*30) % 360),100,255,1); | |
colorRow++; | |
} | |
} | |
if(directories != null){ | |
foreach(string fileName in directories){ | |
string tmpfileName = "/"+Path.GetFileName(fileName); | |
var item = GameObject.Instantiate(fileButton) as GameObject; | |
item.SetActive(true); | |
fileButtonList.Add(item); | |
item.GetComponent<RectTransform>().SetParent(fileButton.transform.parent, false); | |
var text = item.GetComponentInChildren<Text>(); | |
text.text = tmpfileName.Normalize();//System.IO.Path.GetFileName(s); | |
colorRow++; | |
} | |
} | |
} | |
void OnGUI() | |
{ | |
GUI.skin = skin; | |
Color tmpColor = GUI.color; | |
if(soundDebug){ | |
GUI_LevelMeter(); | |
GUILayout.BeginArea(new Rect(0,0,Screen.width,50)); | |
GUILayout.BeginHorizontal(); | |
if(errorMessage != ""){ | |
GUI.color = Color.yellow; | |
GUILayout.Label(errorMessage,GUILayout.Width(Screen.width/2)); | |
} else { | |
GUILayout.Label("",GUILayout.Width(Screen.width/2)); | |
} | |
GUI.color = tmpColor; | |
GUILayout.EndHorizontal(); | |
GUILayout.EndArea(); | |
// ------------ CueSheet_0 [Load ACB] [Panic!] ------------ | |
GUILayout.BeginArea(new Rect(0,18,Screen.width,35)); | |
GUILayout.BeginHorizontal(); | |
GUILayout.BeginHorizontal(); | |
GUI.color = Color.green; | |
GUILayout.EndHorizontal(); | |
GUILayout.EndHorizontal(); | |
GUILayout.EndArea(); | |
if(fileLoadMode){ | |
} else { | |
// // --------- Player ----------- | |
// GUILayout.BeginArea(new Rect(0,pathLisetHeaderPos,Screen.width,Screen.height-25)); | |
// GUI.color = Color.white; | |
// scroll = GUILayout.BeginScrollView( scroll ); | |
// | |
// GUILayout.BeginHorizontal(); | |
// GUILayout.BeginVertical(); | |
// for(int i=0;i<16;i++){ | |
// GUIDrawPlayer(i); | |
// } | |
// for(int i=16;i<32;i++){ | |
// GUIDrawPlayer(i); | |
// } | |
// GUILayout.EndVertical(); | |
// GUILayout.EndHorizontal(); | |
// | |
// GUILayout.EndScrollView(); | |
// GUILayout.EndArea(); | |
} | |
} | |
} | |
void AllStop() | |
{ | |
for(int i=0;i<32;i++){ | |
oscPlayerList[i].atomSource.player.StopWithoutReleaseTime(); | |
} | |
} | |
#region LoadACB | |
string loadPath = ""; | |
string[] files = null; | |
string[] directories = null; | |
Vector2 scroll = new Vector2(0,0); | |
void GUIDrawLaodAcb() | |
{ | |
if(files == null && directories == null){ | |
GUILayout.Label(" - NoFiles - "); | |
} else | |
{ | |
int index = 0; | |
index = 0; | |
//GUI.skin.button.fontSize = 10; | |
GUI.skin.button.alignment = TextAnchor.MiddleLeft; | |
// ---------------- ACB Files ---------------- | |
GUILayout.BeginHorizontal(); | |
foreach(string fileName in files){ | |
index++; | |
if(index%3 == 0){ | |
GUILayout.EndHorizontal(); | |
GUILayout.BeginHorizontal(); | |
} | |
} | |
GUILayout.EndHorizontal(); | |
// ---------------- Directories ---------------- | |
GUILayout.BeginHorizontal(); | |
index = 0; | |
if(directories != null){ | |
foreach(string fileName in directories){ | |
if(Path.GetFileName(fileName).StartsWith("."))continue; | |
string tmpfileName = "/"+Path.GetFileName(fileName); | |
if(tmpfileName.StartsWith("/Assets") || tmpfileName.StartsWith("/StreamingAssets")){ | |
GUI.color =Color.green; | |
} else { | |
GUI.color = Color.white; | |
} | |
if(GUILayout.Button(tmpfileName,GUILayout.Width(Screen.width/3-10))){ | |
loadPath += tmpfileName; | |
files = Directory.GetFiles(loadPath); | |
directories = Directory.GetDirectories(loadPath); | |
} | |
index++; | |
if(index%3 == 0){ | |
GUILayout.EndHorizontal(); | |
GUILayout.BeginHorizontal(); | |
} | |
} | |
} | |
GUILayout.EndHorizontal(); | |
// ---------------- Other FIles ---------------- | |
GUILayout.BeginHorizontal(); | |
foreach(string fileName in files){ | |
if(Path.GetFileName(fileName).StartsWith("."))continue; | |
if(Path.GetExtension(fileName) == ".acb" || | |
Path.GetExtension(fileName) == ".acf" | |
){ | |
continue; | |
} else { | |
if(Path.GetExtension(fileName) == ""){ | |
GUI.color = Color.white; | |
if(GUILayout.Button(Path.GetFileName(fileName),GUILayout.Width(Screen.width/3-10))){ | |
loadPath += Path.GetFileName(fileName); | |
files = Directory.GetFiles(loadPath); | |
directories = Directory.GetDirectories(loadPath); | |
} | |
} else { | |
GUI.color = Color.gray; | |
GUILayout.Button(Path.GetFileName(fileName),GUILayout.Width(Screen.width/3-10)); | |
} | |
} | |
index++; | |
if(index%3 == 0){ | |
GUILayout.EndHorizontal(); | |
GUILayout.BeginHorizontal(); | |
} | |
} | |
GUILayout.EndHorizontal(); | |
} | |
} | |
private string LoadACB(string outString) | |
{ | |
//#if UNITY_IOS | |
// GUI.skin.button.fontSize = 44; | |
// GUI.skin.label.fontSize = 44; | |
// GUI.skin.horizontalSlider.fixedHeight =44; | |
// GUI.skin.horizontalSliderThumb.fixedHeight =44; | |
// GUI.skin.verticalSlider.fixedWidth = 22; | |
//#else | |
// GUI.skin.button.fontSize = 13; | |
// GUI.skin.label.fontSize = 13; | |
// GUI.skin.horizontalSlider.fixedHeight =13; | |
// GUI.skin.horizontalSliderThumb.fixedHeight =13; | |
//#endif | |
if(outString == ""){ | |
DefaultLoadPath(); | |
} | |
if(outString != String.Empty && (System.IO.Path.GetExtension(outString) == ".acb")){ | |
Debug.Log(String.Format("Loading \"{0}\" ",outString)); | |
} else { | |
Debug.LogError(String.Format("Can not Load \"{0}\".",outString)); | |
outString = String.Empty; | |
} | |
// Unload ACB | |
UnloadACB(); | |
// Reload ACB | |
ReloadACB(outString); | |
// fileLoadMode = false; | |
return cueSheetName; | |
} | |
private void UnloadACB() | |
{ | |
string oldCueSheetName = cueSheetName; | |
CriAtom.RemoveCueSheet(oldCueSheetName); | |
Debug.Log(String.Format("Remove CueSheet \"{0}\".",oldCueSheetName)); | |
} | |
private void ReloadACB(string outString) | |
{ | |
cueSheetName = Path.GetFileNameWithoutExtension(outString); | |
string awbPath = Path.GetDirectoryName(outString) + "/" + Path.GetFileNameWithoutExtension(outString) + ".awb"; | |
string acbPath = Path.GetDirectoryName(outString) + "/" + Path.GetFileNameWithoutExtension(outString) + ".acb"; | |
CriAtom.AddCueSheet(cueSheetName,acbPath,awbPath); | |
Debug.Log(String.Format("Add CueSheet \"{0}\" \"{1}\".",cueSheetName,acbPath)); | |
lastCueSheetPath = acbPath; | |
Debug.Log("Reload " + lastCueSheetPath); | |
AcbSetUp(); | |
} | |
private string LoadACF(string outString) | |
{ | |
if(outString == ""){ | |
DefaultLoadPath(); // loadPath += "/StreamingAssets"; | |
} | |
if(outString != String.Empty && (System.IO.Path.GetExtension(outString) == ".acf")){ | |
Debug.Log(String.Format("Loading \"{0}\" ",outString)); | |
} else { | |
Debug.LogError(String.Format("Can not Load \"{0}\".",outString)); | |
outString = String.Empty; | |
} | |
// Unload ACB | |
UnloadACB(); | |
// Unregister ACF | |
CriAtomEx.UnregisterAcf(); | |
Debug.Log(String.Format("UnregisterAcf.{0}",acfName)); | |
// Register ACF | |
CriAtomEx.RegisterAcf(null,outString); | |
acfName = Path.GetFileNameWithoutExtension(outString); | |
Debug.Log(String.Format("RegisterAcf \"{0}\" \"{1}\".",acfName,outString)); | |
string acbPath = Path.GetDirectoryName(outString) + "/CueSheet_0.acb"; | |
// Reload ACB | |
ReloadACB(acbPath); | |
return cueSheetName; | |
} | |
#endregion | |
void UpdateCueName(int i) | |
{ | |
textCueName.text = string.Format("{0}:{1}", | |
cueInfoList[oscPlayerList[i].selCueNo%cueInfoList.Length].id.ToString(), | |
cueInfoList[oscPlayerList[i].selCueNo%cueInfoList.Length].name); | |
} | |
void UpdateCueTime(int i) | |
{ | |
if(cueInfoList[oscPlayerList[i].selCueNo%cueInfoList.Length].length/1000f > 0){ | |
textCueTime.text = string.Format("{0:F3}/{1:F3}",oscPlayerList[i].atomSource.time/1000f, | |
cueInfoList[oscPlayerList[i].selCueNo%cueInfoList.Length].length/1000f | |
); | |
} else { | |
textCueTime.text = string.Format("{0:F3}",oscPlayerList[i].atomSource.time/1000f | |
); | |
} | |
} | |
public void OnCuePlus(int i) | |
{ | |
{ | |
oscPlayerList[i].selCueNo = ((oscPlayerList[i].selCueNo+1)+cueInfoList.Length)%cueInfoList.Length; | |
} | |
UpdateCueName(i); | |
} | |
public void OnCueMinus(int i) | |
{ | |
if(oscPlayerList[i].selCueNo == 0) | |
{ | |
oscPlayerList[i].selCueNo = cueInfoList.Length-1; | |
} else { | |
oscPlayerList[i].selCueNo = ((oscPlayerList[i].selCueNo-1)+cueInfoList.Length)%cueInfoList.Length; | |
} | |
UpdateCueName(i); | |
} | |
public void OnCuePlay(int i) | |
{ | |
oscPlayerList[i].playback = oscPlayerList[i].atomSource.Play(cueInfoList[oscPlayerList[i].selCueNo%cueInfoList.Length].name); | |
} | |
public void OnCueStop(int i) | |
{ | |
oscPlayerList[i].atomSource.Stop(); | |
} | |
public void OnCueAISAC0(float value) | |
{ | |
oscPlayerList[0].atomSource.SetAisac(0,value/1000f); | |
} | |
void GUIDrawPlayer(int i) | |
{ | |
#if UNITY_IOS | |
GUI.skin.button.fontSize = 44; | |
GUI.skin.label.fontSize = 44; | |
GUI.skin.horizontalSlider.fixedHeight =44; | |
GUI.skin.horizontalScrollbarThumb.fixedHeight =44; | |
#else | |
GUI.skin.button.fontSize = 13; | |
GUI.skin.label.fontSize = 13; | |
GUI.skin.horizontalSlider.fixedHeight =13; | |
GUI.skin.horizontalScrollbarThumb.fixedHeight =13; | |
#endif | |
Color tmpColor = GUI.color; | |
GUI.color = new Color(0.5f+((i+1)/2%6/6f),0.5f+((i+1)%4/4f),0.5f+((i+1)%5/5f)); | |
GUILayout.BeginHorizontal(); | |
GUILayout.BeginHorizontal(); | |
#if UNITY_IOS | |
GUILayout.Space(16); | |
#else | |
GUILayout.Space(8); | |
#endif | |
GUILayout.Label(string.Format("{0}:{1}", | |
cueInfoList[oscPlayerList[i].selCueNo%cueInfoList.Length].id.ToString(), | |
cueInfoList[oscPlayerList[i].selCueNo%cueInfoList.Length].name), | |
GUILayout.Width(Screen.width/4) | |
); | |
GUILayout.EndHorizontal(); | |
GUILayout.BeginHorizontal(); | |
if(GUILayout.Button("C-",GUILayout.Width( Screen.width/8))){ | |
oscPlayerList[i].selCueNo = ((oscPlayerList[i].selCueNo-1)+cueInfoList.Length)%cueInfoList.Length; | |
} | |
if(GUILayout.Button("C+",GUILayout.Width( Screen.width/8))){ | |
oscPlayerList[i].selCueNo = ((oscPlayerList[i].selCueNo+1)+cueInfoList.Length)%cueInfoList.Length; | |
} | |
if(GUILayout.Button("♪")){ | |
oscPlayerList[i].playback = oscPlayerList[i].atomSource.Play(cueInfoList[oscPlayerList[i].selCueNo%cueInfoList.Length].name); | |
} | |
if(oscPlayerList[i].atomSource.time>0f){GUI.color = Color.white; } else {GUI.color = Color.gray; } | |
if(GUILayout.Button("■")){ | |
oscPlayerList[i].atomSource.Stop(); | |
} | |
GUILayout.EndHorizontal(); | |
GUILayout.EndHorizontal(); | |
GUILayout.BeginHorizontal(); | |
if(oscPlayerList[i].aisaControlValue[0]>0f){GUI.color = Color.red; } else {GUI.color = Color.gray; } | |
oscPlayerList[i].atomSource.SetAisac(0,GUILayout.HorizontalSlider(oscPlayerList[i].aisaControlValue[0],0f,1f)); | |
GUI.color = tmpColor; | |
if(oscPlayerList[i].aisaControlValue[1]>0f){GUI.color = Color.green; } else {GUI.color = Color.gray; } | |
oscPlayerList[i].atomSource.SetAisac(1,GUILayout.HorizontalSlider(oscPlayerList[i].aisaControlValue[1],0f,1f)); | |
GUI.color = tmpColor; | |
if(oscPlayerList[i].atomSource.time>0f){GUI.color = Color.blue; } else {GUI.color = Color.gray; } | |
GUILayout.HorizontalSlider(oscPlayerList[i].atomSource.time,0f,100000f); | |
GUI.color = tmpColor; | |
// ------------- Block Control -------------- | |
if(cueInfoList[oscPlayerList[i].selCueNo%cueInfoList.Length].numBlocks > 0){ | |
if(oscPlayerList[i].currentBlockNo != oscPlayerList[i].selBlockNo){ | |
GUILayout.Label(string.Format("B{0} > {1}",oscPlayerList[i].currentBlockNo,oscPlayerList[i].selBlockNo),GUILayout.Width( Screen.width/8)); | |
oscPlayerList[i].currentBlockNo = oscPlayerList[i].playback.GetCurrentBlockIndex(); | |
} else { | |
GUILayout.Label(string.Format("B{0}",oscPlayerList[i].currentBlockNo,oscPlayerList[i].selBlockNo),GUILayout.Width( Screen.width/8)); | |
} | |
if(GUILayout.Button("B-",GUILayout.Width( Screen.width/8))){ | |
oscPlayerList[i].selBlockNo = ((oscPlayerList[i].selBlockNo-1) | |
+cueInfoList[oscPlayerList[i].selCueNo%cueInfoList.Length].numBlocks)%cueInfoList[oscPlayerList[i].selCueNo%cueInfoList.Length].numBlocks; | |
oscPlayerList[i].playback.SetNextBlockIndex(oscPlayerList[i].selBlockNo); | |
} | |
if(GUILayout.Button("B+",GUILayout.Width( Screen.width/8))){ | |
oscPlayerList[i].selBlockNo = ((oscPlayerList[i].selBlockNo+1) | |
+cueInfoList[oscPlayerList[i].selCueNo%cueInfoList.Length].numBlocks)%cueInfoList[oscPlayerList[i].selCueNo%cueInfoList.Length].numBlocks; | |
oscPlayerList[i].playback.SetNextBlockIndex(oscPlayerList[i].selBlockNo); | |
} | |
} | |
GUILayout.EndHorizontal(); | |
} | |
string errorMessage = ""; | |
public void ReciveOSC(OscMessage oscMessage){ | |
string tmpMsg = Osc.OscMessageToString(oscMessage); | |
Debug.Log("OSC " + tmpMsg); | |
string allMsg = Osc.OscMessageToString(oscMessage); | |
if(allMsg.Contains("/adx2/")){ | |
{ | |
if(allMsg.StartsWith("/adx2")){ | |
string[] messageArray = allMsg.Split(' '); | |
string tmpCommandOrPlayerId = messageArray[0].Replace("/adx2/",""); | |
string playerNoStr = ""; | |
if(tmpCommandOrPlayerId != ""){ | |
int startIndex = tmpCommandOrPlayerId.IndexOf('/'); | |
int endIndex = tmpCommandOrPlayerId.Length - startIndex; | |
if(startIndex > 0){ | |
playerNoStr = tmpCommandOrPlayerId.Remove(startIndex,endIndex); | |
} | |
} | |
int playerId = 0; | |
if(int.TryParse(playerNoStr,out playerId)){ | |
#region player command | |
playerId = playerId%32; | |
string functionName = System.IO.Path.GetFileName(messageArray[0]); | |
switch(functionName) | |
{ | |
case "playcueid": | |
{ | |
//selCueNo[playerId] = int.Parse(messageArray[1]); | |
if(cueIdCueInfoDictionary.ContainsKey(int.Parse(messageArray[1]))){ | |
oscPlayerList[playerId].selCueNo = cueIdCueInfoDictionary[int.Parse(messageArray[1])].id; | |
oscPlayerList[playerId].playback = SoundManager.oscPlayerList[playerId].atomSource.Play(int.Parse(messageArray[1])); | |
} else { | |
errorMessage = string.Format("Error Not found Cue ID \"{0}\" on Player\"{1}\"" | |
,int.Parse(messageArray[1]) | |
,playerId.ToString() | |
); | |
} | |
}break; | |
case "playcuename": | |
{ | |
SoundManager.oscPlayerList[playerId].atomSource.cueName = messageArray[1]; | |
SoundManager.oscPlayerList[playerId].atomSource.Play(messageArray[1]); | |
}break; | |
case "pause": | |
{ | |
bool pauseFlag = false; | |
if(int.Parse(messageArray[1]) == 1)pauseFlag = true; | |
SoundManager.oscPlayerList[playerId].atomSource.Pause(pauseFlag); | |
}break; | |
case "stop": | |
{ | |
SoundManager.oscPlayerList[playerId].atomSource.Stop(); | |
}break; | |
case "aisac": | |
{ | |
SoundManager.oscPlayerList[playerId].atomSource.SetAisac(uint.Parse(messageArray[1]),float.Parse(messageArray[2])); | |
}break; | |
case "reset": | |
{ | |
SoundManager.oscPlayerList[playerId].atomSource.player.ResetParameters(); | |
}break; | |
// ------------- Block ----------- | |
case "blockindex": | |
{ | |
int blockNo = int.Parse(messageArray[1]); | |
if(cueInfoList[oscPlayerList[playerId].selCueNo%cueInfoList.Length].numBlocks > blockNo){ | |
oscPlayerList[playerId].selBlockNo = blockNo; | |
oscPlayerList[playerId].playback.SetNextBlockIndex(oscPlayerList[playerId].selBlockNo); | |
} else { | |
errorMessage = string.Format("Error Not found Block {0} on Player\"{1}\"" | |
,int.Parse(messageArray[1]) | |
,playerId.ToString() | |
); | |
} | |
}break; | |
// ------------- Omake ----------- | |
case "pitch": | |
{ | |
SoundManager.oscPlayerList[playerId].atomSource.pitch = int.Parse(messageArray[1]); | |
}break; | |
case "note": | |
{ | |
SoundManager.oscPlayerList[playerId].atomSource.pitch = ((int.Parse(messageArray[1])-60) * 100) ; // BASE 60 | |
}break; | |
case "volume": | |
{ | |
SoundManager.oscPlayerList[playerId].atomSource.volume = float.Parse(messageArray[1]); | |
}break; | |
case "attack": | |
{ | |
SoundManager.oscPlayerList[playerId].atomSource.player.SetEnvelopeAttackTime(int.Parse(messageArray[1])); | |
SoundManager.oscPlayerList[playerId].atomSource.player.UpdateAll(); | |
}break; | |
case "release": | |
{ | |
SoundManager.oscPlayerList[playerId].atomSource.player.SetEnvelopeReleaseTime(int.Parse(messageArray[1])); | |
SoundManager.oscPlayerList[playerId].atomSource.player.UpdateAll(); | |
}break; | |
} | |
#endregion | |
} else { | |
// ----------- 特殊 | |
switch(allMsg) | |
{ | |
case "/adx2/restart": | |
{ | |
AllStop(); | |
//Application.LoadLevel(0); | |
}break; | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment