add level meters

This commit is contained in:
Chikashi Miyama 2019-09-28 21:21:58 +02:00
parent f29a1549c5
commit f86ea3078f
5 changed files with 65 additions and 2 deletions

View file

@ -59,6 +59,7 @@
<ItemGroup>
<Compile Include="Assets\Editor\AppBuilder.cs" />
<Compile Include="Assets\Editor\EditorToggle.cs" />
<Compile Include="Assets\Editor\LevelMeter.cs" />
<Compile Include="Assets\Editor\PdBindEditor.cs" />
<Compile Include="Assets\Editor\PdConsole.cs" />
<Compile Include="Assets\Editor\TogglePresenter.cs" />

View file

@ -0,0 +1,44 @@
using UnityEngine;
using UnityEditor;
namespace cylvester
{
public class LevelMeter
{
private string label_;
private float dB_;
private Texture2D meterImageTexture_;
public LevelMeter(int index)
{
label_ = (index + 1).ToString();
meterImageTexture_ = new Texture2D(1, 32);
}
public void Render()
{
UpdateTexture();
var rect = EditorGUILayout.BeginVertical();
var style = new GUIStyle(GUI.skin.label)
{
alignment = TextAnchor.UpperCenter,
fixedHeight = 120
};
GUILayout.Label(label_, style);
rect.y += 20;
rect.height -= 20;
EditorGUI.DrawPreviewTexture(rect, meterImageTexture_);
EditorGUILayout.EndVertical();
}
private void UpdateTexture()
{
for (var i = 0; i < 32; ++i)
{
meterImageTexture_.SetPixel(0, i, i < 10 ? Color.green : Color.black);
}
meterImageTexture_.Apply();
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f3be381e60d047f8a67bbbae4a0af44b
timeCreated: 1569696904

View file

@ -1,4 +1,5 @@
using UnityEditor;
using UnityEngine;
namespace cylvester
{
@ -7,12 +8,15 @@ namespace cylvester
private IEditorToggle dspToggle_;
private ITogglePresenter togglePresenter_;
private IPdBackend pdBackend_;
private LevelMeter[] levelMeters_;
[MenuItem("SoundVision/Pd console %#p")]
static void Init()
{
var window = (PdConsole)GetWindow(typeof(PdConsole));
window.Show();
}
private void OnEnable()
@ -25,6 +29,9 @@ namespace cylvester
dspToggle_ = new EditorToggle();
togglePresenter_ = new TogglePresenter(dspToggle_, pdBackend_);
levelMeters_ = new LevelMeter[16];
for (var i = 0; i < 16; ++i)
levelMeters_[i] = new LevelMeter(i);
}
private void OnGUI ()
@ -32,10 +39,20 @@ namespace cylvester
if(!ValidatePdBackend(pdBackend_))
return;
EditorGUILayout.Space();
dspToggle_.State = EditorGUILayout.Toggle("Pure Data Process", dspToggle_.State);
EditorGUILayout.Space();
EditorGUILayout.BeginHorizontal();
foreach (var levelMeter in levelMeters_)
levelMeter.Render();
EditorGUILayout.EndHorizontal();
}
private bool ValidatePdBackend(IPdBackend pdBackend)
{
var exist = pdBackend_ != null;

View file

@ -9,14 +9,12 @@ namespace cylvester
public class TogglePresenter : ITogglePresenter, IDisposable
{
private readonly IEditorToggle editorToggle_;
private IPdBackend pdBackend_;
private readonly Action onToggleChanged_;
public TogglePresenter(IEditorToggle toggle, IPdBackend pdBackend)
{
editorToggle_ = toggle;
pdBackend_ = pdBackend;
onToggleChanged_ = () =>
{