mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2026-05-14 23:15:27 +08:00
AWC improvements
This commit is contained in:
Generated
+4
-15
@@ -32,7 +32,6 @@
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AwcForm));
|
||||
this.MainTabControl = new System.Windows.Forms.TabControl();
|
||||
this.PlayerTabPage = new System.Windows.Forms.TabPage();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.LabelInfo = new System.Windows.Forms.Label();
|
||||
this.LabelTime = new System.Windows.Forms.Label();
|
||||
this.StopButton = new System.Windows.Forms.Button();
|
||||
@@ -75,7 +74,6 @@
|
||||
//
|
||||
// PlayerTabPage
|
||||
//
|
||||
this.PlayerTabPage.Controls.Add(this.label1);
|
||||
this.PlayerTabPage.Controls.Add(this.LabelInfo);
|
||||
this.PlayerTabPage.Controls.Add(this.LabelTime);
|
||||
this.PlayerTabPage.Controls.Add(this.StopButton);
|
||||
@@ -95,16 +93,6 @@
|
||||
this.PlayerTabPage.Text = "Player";
|
||||
this.PlayerTabPage.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(244, 247);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(316, 13);
|
||||
this.label1.TabIndex = 13;
|
||||
this.label1.Text = "WARNING: Work in progress! Some audio may not play correctly!";
|
||||
//
|
||||
// LabelInfo
|
||||
//
|
||||
this.LabelInfo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
@@ -133,6 +121,7 @@
|
||||
this.StopButton.TabIndex = 10;
|
||||
this.StopButton.Text = "◼";
|
||||
this.StopButton.UseVisualStyleBackColor = true;
|
||||
this.StopButton.Click += new System.EventHandler(this.StopButton_Click);
|
||||
//
|
||||
// VolumeLabel
|
||||
//
|
||||
@@ -208,6 +197,7 @@
|
||||
this.PlayListView.TabIndex = 0;
|
||||
this.PlayListView.UseCompatibleStateImageBehavior = false;
|
||||
this.PlayListView.View = System.Windows.Forms.View.Details;
|
||||
this.PlayListView.SelectedIndexChanged += new System.EventHandler(this.PlayListView_SelectedIndexChanged);
|
||||
this.PlayListView.DoubleClick += new System.EventHandler(this.PlayListView_DoubleClick);
|
||||
//
|
||||
// PlaylistNameHeader
|
||||
@@ -237,12 +227,12 @@
|
||||
this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.ExportAsWav});
|
||||
this.contextMenuStrip.Name = "contextMenuStrip1";
|
||||
this.contextMenuStrip.Size = new System.Drawing.Size(149, 26);
|
||||
this.contextMenuStrip.Size = new System.Drawing.Size(150, 26);
|
||||
//
|
||||
// ExportAsWav
|
||||
//
|
||||
this.ExportAsWav.Name = "ExportAsWav";
|
||||
this.ExportAsWav.Size = new System.Drawing.Size(148, 22);
|
||||
this.ExportAsWav.Size = new System.Drawing.Size(149, 22);
|
||||
this.ExportAsWav.Text = "Export as .wav";
|
||||
this.ExportAsWav.Click += new System.EventHandler(this.ExportAsWav_Click);
|
||||
//
|
||||
@@ -352,6 +342,5 @@
|
||||
private System.Windows.Forms.ToolStripMenuItem ExportAsWav;
|
||||
private System.Windows.Forms.SaveFileDialog saveFileDialog;
|
||||
private System.Windows.Forms.ColumnHeader PlaylistSizeHeader;
|
||||
private System.Windows.Forms.Label label1;
|
||||
}
|
||||
}
|
||||
+55
-16
@@ -16,7 +16,7 @@ namespace CodeWalker.Forms
|
||||
private XAudio2 xAudio2;
|
||||
private MasteringVoice masteringVoice;
|
||||
private AudioBuffer audioBuffer;
|
||||
private SourceVoice sourceVoice;
|
||||
private SourceVoice sourceVoice;
|
||||
|
||||
private string fileName;
|
||||
public string FileName
|
||||
@@ -60,7 +60,7 @@ namespace CodeWalker.Forms
|
||||
{
|
||||
fileName = awc?.FileEntry?.Name;
|
||||
}
|
||||
|
||||
|
||||
PlayListView.Items.Clear();
|
||||
|
||||
float totalLength = 0;
|
||||
@@ -68,16 +68,17 @@ namespace CodeWalker.Forms
|
||||
{
|
||||
foreach (var audio in awc.Audios)
|
||||
{
|
||||
if (audio.MultiChannelBlocks != null) continue;//don't display multichannel source audios
|
||||
var item = PlayListView.Items.Add(audio.Name);
|
||||
item.SubItems.Add(audio.Type);
|
||||
item.SubItems.Add(audio.LengthStr);
|
||||
item.SubItems.Add(TextUtil.GetBytesReadable(audio.Data?.Length ?? 0));
|
||||
item.SubItems.Add(TextUtil.GetBytesReadable(audio.ByteLength));
|
||||
item.Tag = audio;
|
||||
totalLength += audio.Length;
|
||||
}
|
||||
}
|
||||
|
||||
LabelInfo.Text = awc.Audios.Length.ToString() + " track(s), Length: " + TimeSpan.FromSeconds((float)totalLength).ToString("m\\:ss");
|
||||
LabelInfo.Text = awc.Audios.Length.ToString() + " track(s), Length: " + TimeSpan.FromSeconds((float)totalLength).ToString("h\\:mm\\:ss");
|
||||
UpdateFormTitle();
|
||||
}
|
||||
|
||||
@@ -119,7 +120,7 @@ namespace CodeWalker.Forms
|
||||
LabelTime.Visible = false;
|
||||
StopButton.Enabled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
playerState = newState;
|
||||
UpdateUI();
|
||||
@@ -129,7 +130,7 @@ namespace CodeWalker.Forms
|
||||
private void InitializeAudio(AwcAudio audio, float playBegin = 0)
|
||||
{
|
||||
currentAudio = audio;
|
||||
trackLength = audio.Length;
|
||||
trackLength = audio.Length;
|
||||
|
||||
if (xAudio2 == null)
|
||||
{
|
||||
@@ -160,7 +161,7 @@ namespace CodeWalker.Forms
|
||||
wavStream.Close();
|
||||
|
||||
trackFinished = false;
|
||||
sourceVoice = new SourceVoice(xAudio2, soundStream.Format, true);
|
||||
sourceVoice = new SourceVoice(xAudio2, soundStream.Format, true);
|
||||
sourceVoice.SubmitSourceBuffer(audioBuffer, soundStream.DecodedPacketsInfo);
|
||||
sourceVoice.BufferEnd += (context) => trackFinished = true;
|
||||
sourceVoice.SetVolume((float)VolumeTrackBar.Value / 100);
|
||||
@@ -175,12 +176,16 @@ namespace CodeWalker.Forms
|
||||
var item = PlayListView.SelectedItems[0];
|
||||
var audio = item.Tag as AwcAudio;
|
||||
|
||||
if (audio != null)
|
||||
if ((audio?.Format != null) || (audio?.MultiChannelFormat != null))
|
||||
{
|
||||
InitializeAudio(audio);
|
||||
sourceVoice.Start();
|
||||
SetPlayerState(PlayerState.Playing);
|
||||
}
|
||||
else if (audio.MIDIData != null)
|
||||
{
|
||||
//todo: play MIDI?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +222,7 @@ namespace CodeWalker.Forms
|
||||
private void Pause()
|
||||
{
|
||||
if (playerState == PlayerState.Playing)
|
||||
{
|
||||
{
|
||||
sourceVoice.Stop();
|
||||
SetPlayerState(PlayerState.Paused);
|
||||
}
|
||||
@@ -256,6 +261,11 @@ namespace CodeWalker.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void StopButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
|
||||
private void PrevButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
PlayPrevious();
|
||||
@@ -327,16 +337,45 @@ namespace CodeWalker.Forms
|
||||
var item = PlayListView.SelectedItems[0];
|
||||
var audio = item.Tag as AwcAudio;
|
||||
|
||||
saveFileDialog.FileName = audio.Name + ".wav";
|
||||
var ext = ".wav";
|
||||
if (audio?.MIDIData != null)
|
||||
{
|
||||
ext = ".midi";
|
||||
}
|
||||
|
||||
saveFileDialog.FileName = audio.Name + ext;
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
Stream wavStream = audio.GetWavStream();
|
||||
FileStream stream = File.Create(saveFileDialog.FileName);
|
||||
wavStream.CopyTo(stream);
|
||||
stream.Close();
|
||||
wavStream.Close();
|
||||
{
|
||||
if (audio?.MIDIData != null)
|
||||
{
|
||||
File.WriteAllBytes(saveFileDialog.FileName, audio.MIDIData.Data);
|
||||
}
|
||||
else if ((audio?.Format != null) || (audio?.MultiChannelFormat != null))
|
||||
{
|
||||
Stream wavStream = audio.GetWavStream();
|
||||
FileStream stream = File.Create(saveFileDialog.FileName);
|
||||
wavStream.CopyTo(stream);
|
||||
stream.Close();
|
||||
wavStream.Close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void PlayListView_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
ExportAsWav.Text = "Export as .wav";
|
||||
if (PlayListView.SelectedItems.Count == 1)
|
||||
{
|
||||
var item = PlayListView.SelectedItems[0];
|
||||
var audio = item.Tag as AwcAudio;
|
||||
if (audio?.MIDIData != null)
|
||||
{
|
||||
ExportAsWav.Text = "Export as .midi";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user