Files
cuetools.net/CUEPlayer/frmCUEPlayer.cs

188 lines
4.6 KiB
C#
Raw Normal View History

2010-04-06 14:22:27 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using System.Diagnostics;
using CUEControls;
using CUETools.Codecs;
using CUETools.DSP.Mixer;
using CUETools.Processor;
namespace CUEPlayer
{
public partial class frmCUEPlayer : Form
{
private ShellIconMgr _icon_mgr;
private CUEConfig _config;
DataSet1TableAdapters.PlaylistTableAdapter adapterPlayList = new DataSet1TableAdapters.PlaylistTableAdapter();
private DataSet1 dataSet = new DataSet1();
private Thread mixThread;
private MixingSource _mixer;
internal Playlist wndPlaylist
{
get
{
return playlist;
}
}
internal DataSet1 DataSet
{
get
{
return dataSet;
}
}
internal CUEConfig Config
{
get
{
return _config;
}
}
internal ShellIconMgr IconMgr
{
get
{
return _icon_mgr;
}
}
public MixingSource Mixer
{
get
{
return _mixer;
}
}
public frmCUEPlayer()
{
InitializeComponent();
_icon_mgr = new ShellIconMgr();
_config = new CUEConfig();
_config.separateDecodingThread = false;
}
internal Deck deckA = new Deck(0, "A");
internal Deck deckB = new Deck(1, "B");
internal Output outputA = new Output();
internal Browser browser = new Browser();
internal Playlist playlist = new Playlist();
private void frmCUEPlayer_Load(object sender, EventArgs e)
{
2010-04-16 04:30:51 +00:00
if (Properties.Settings.Default.AppSettings == null)
{
Properties.Settings.Default.AppSettings = new CUEPlayerSettings();
Properties.Settings.Default.AppSettings.IcecastServers.Add(new CUETools.Codecs.Icecast.IcecastSettingsData());
}
2010-04-06 14:22:27 +00:00
//System.Data.SqlServerCe.SqlCeDataAdapter ad = new System.Data.SqlServerCe.SqlCeDataAdapter();
//ad.SelectCommand = new System.Data.SqlServerCe.SqlCeCommand("SELECT * FROM Playlist WHERE track=1", adapterPlayList.Connection);
//ad.Fill(dataSet.Playlist);
adapterPlayList.Fill(dataSet.Playlist);
2010-04-16 04:30:51 +00:00
_mixer = new MixingSource(new AudioPCMConfig(32, 2, 44100), 100, 2);
2010-04-06 14:22:27 +00:00
outputA.Init(this);
browser.Init(this);
playlist.Init(this);
deckB.Init(this, null);
deckA.Init(this, deckB);
2010-04-16 04:30:51 +00:00
Icecast icecast = new Icecast();
icecast.Init(this);
2010-04-06 14:22:27 +00:00
//LayoutMdi(MdiLayout.TileHorizontal);
2010-04-16 04:30:51 +00:00
2010-04-06 14:22:27 +00:00
browser.Location = new Point(0, 0);
2010-04-16 04:30:51 +00:00
browser.Height = ClientRectangle.Height - 5 - menuStrip1.Height;
2010-04-06 14:22:27 +00:00
playlist.Location = new Point(browser.Location.X + browser.Width, 0);
2010-04-16 04:30:51 +00:00
playlist.Height = ClientRectangle.Height - 5 - menuStrip1.Height;
2010-04-06 14:22:27 +00:00
deckA.Location = new Point(playlist.Location.X + playlist.Width, 0);
deckB.Location = new Point(playlist.Location.X + playlist.Width, deckA.Height);
outputA.Location = new Point(deckA.Location.X + deckA.Width, 0);
2010-04-16 04:30:51 +00:00
icecast.Location = new Point(deckA.Location.X + deckA.Width, outputA.Height);
2010-04-06 14:22:27 +00:00
2010-04-16 04:30:51 +00:00
mixThread = new Thread(MixThread);
mixThread.Priority = ThreadPriority.AboveNormal;
mixThread.IsBackground = true;
mixThread.Name = "Mixer";
mixThread.Start();
2010-04-06 14:22:27 +00:00
}
2010-04-16 04:30:51 +00:00
private void frmCUEPlayer_FormClosing(object sender, FormClosingEventArgs e)
2010-04-06 14:22:27 +00:00
{
try
{
2010-04-16 04:30:51 +00:00
int rowsAffected = adapterPlayList.Update(dataSet.Playlist);
2010-04-06 14:22:27 +00:00
}
catch (Exception ex)
{
2010-04-16 04:30:51 +00:00
System.Diagnostics.Trace.WriteLine(ex.Message);
2010-04-06 14:22:27 +00:00
}
}
2010-04-16 04:30:51 +00:00
private void MixThread()
2010-04-06 14:22:27 +00:00
{
2010-04-16 04:30:51 +00:00
AudioBuffer result = new AudioBuffer(_mixer.PCM, _mixer.BufferSize);
while (true)
2010-04-06 14:22:27 +00:00
{
2010-04-16 04:30:51 +00:00
_mixer.Read(result, -1);
2010-04-06 14:22:27 +00:00
}
}
2010-04-16 04:30:51 +00:00
public event EventHandler<UpdateMetadataEvent> updateMetadata;
public void UpdateMetadata(string artist, string title)
2010-04-06 14:22:27 +00:00
{
2010-04-16 04:30:51 +00:00
UpdateMetadataEvent e = new UpdateMetadataEvent();
e.artist = artist;
e.title = title;
if (updateMetadata != null)
updateMetadata(this, e);
2010-04-06 14:22:27 +00:00
}
2010-04-16 04:30:51 +00:00
private void icecastToolStripMenuItem_Click(object sender, EventArgs e)
2010-04-06 14:22:27 +00:00
{
2010-04-16 04:30:51 +00:00
Icecast icecast = new Icecast();
icecast.Init(this);
2010-04-06 14:22:27 +00:00
}
2010-04-16 04:30:51 +00:00
}
2010-04-06 14:22:27 +00:00
2010-04-16 04:30:51 +00:00
public class UpdateMetadataEvent: EventArgs
{
public string artist;
public string title;
}
public class CUEPlayerSettings
{
private BindingList<CUETools.Codecs.Icecast.IcecastSettingsData> icecastServers;
public CUEPlayerSettings()
2010-04-06 14:22:27 +00:00
{
2010-04-16 04:30:51 +00:00
icecastServers = new BindingList<CUETools.Codecs.Icecast.IcecastSettingsData>();
2010-04-06 14:22:27 +00:00
}
2010-04-16 04:30:51 +00:00
public BindingList<CUETools.Codecs.Icecast.IcecastSettingsData> IcecastServers
2010-04-06 14:22:27 +00:00
{
2010-04-16 04:30:51 +00:00
get
2010-04-06 14:22:27 +00:00
{
2010-04-16 04:30:51 +00:00
return icecastServers;
}
set
{
icecastServers = value;
2010-04-06 14:22:27 +00:00
}
}
}
}