81 lines
2.2 KiB
C#
81 lines
2.2 KiB
C#
using System.IO;
|
|
using Godot;
|
|
|
|
namespace AudioEditor;
|
|
|
|
[GlobalClass]
|
|
public partial class ProjectController : Node
|
|
{
|
|
[Signal] public delegate void AudioClipDroppedEventHandler(Vector2 atPosition, string path, string clipName, double startTime, double endTime);
|
|
[Signal] public delegate void OnTrackAddedEventHandler(int idx);
|
|
[Signal] public delegate void OnTrackRenamedEventHandler(int idx, string name);
|
|
[Signal] public delegate void OnTrackDuplicatedEventHandler(int idx);
|
|
[Signal] public delegate void OnTrackDeletedEventHandler(int trackIdx);
|
|
|
|
public override void _Ready()
|
|
{
|
|
GetWindow().FilesDropped += FilesDropped;
|
|
}
|
|
|
|
public void AddTrack(int idx = 0)
|
|
{
|
|
_project.AddTrack();
|
|
EmitSignal(SignalName.OnTrackAdded, _project.TrackCount - 1);
|
|
}
|
|
|
|
public void DuplicateTrack(int idx)
|
|
{
|
|
_project.DuplicateTrack(idx);
|
|
EmitSignal(SignalName.OnTrackDuplicated, idx);
|
|
}
|
|
|
|
public void RenameTrack(int idx, string name)
|
|
{
|
|
_project.RenameTrack(idx, name);
|
|
EmitSignal(SignalName.OnTrackRenamed, idx, name);
|
|
}
|
|
|
|
public void DeleteTrack(int idx)
|
|
{
|
|
_project.DeleteTrack(idx);
|
|
EmitSignal(SignalName.OnTrackDeleted, idx);
|
|
}
|
|
|
|
public void CreateAudioClipPreview(Control audioClip)
|
|
{
|
|
// GD.Print(audioClip.Clas());
|
|
var path = audioClip.Get("clip_path").AsString();
|
|
|
|
if (string.IsNullOrEmpty(path))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!AudioFileAnalyzer.Instance.TryGetFromCache(path, out WaveformInfo waveformInfo))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (audioClip.HasNode("%Waveform"))
|
|
{
|
|
var waveform = audioClip.GetNode<Waveform>("%Waveform");
|
|
waveform.SetWaveformInfo(waveformInfo);
|
|
}
|
|
}
|
|
|
|
private void FilesDropped(string[] files)
|
|
{
|
|
var mousePosition = GetViewport().GetMousePosition();
|
|
|
|
var path = files[0];
|
|
var fileName = Path.GetFileName(path);
|
|
|
|
AudioFileAnalyzer.Instance.AnalyzeFile(path, out WaveformInfo waveformInfo);
|
|
|
|
GD.Print(path);
|
|
|
|
EmitSignal(SignalName.AudioClipDropped, mousePosition, path, fileName, 0, waveformInfo.Length.TotalMilliseconds);
|
|
}
|
|
|
|
private Project _project = new();
|
|
} |