Added solution files
This commit is contained in:
parent
136af4a8b1
commit
0c9a31d652
6
RadioBroadcaster.Server/App.config
Normal file
6
RadioBroadcaster.Server/App.config
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||
</startup>
|
||||
</configuration>
|
9
RadioBroadcaster.Server/App.xaml
Normal file
9
RadioBroadcaster.Server/App.xaml
Normal file
@ -0,0 +1,9 @@
|
||||
<Application x:Class="RadioBroadcaster.Server.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:RadioBroadcaster.Server"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
17
RadioBroadcaster.Server/App.xaml.cs
Normal file
17
RadioBroadcaster.Server/App.xaml.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace RadioBroadcaster.Server
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
}
|
52
RadioBroadcaster.Server/FileEngine.cs
Normal file
52
RadioBroadcaster.Server/FileEngine.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
namespace RadioBroadcaster.Server
|
||||
{
|
||||
static class FileEngine
|
||||
{
|
||||
static string[] WriteBuffer = new string[1024];
|
||||
static int LastWrite = -1;
|
||||
static int LastAddition = -1;
|
||||
static bool IsCurrentlyActive = false;
|
||||
public static string logLocation = "";
|
||||
public static void Write(string TextToWrite)
|
||||
{
|
||||
LastAddition = LastAddition + 1;
|
||||
if(LastAddition > 1023)
|
||||
{
|
||||
LastAddition = 0;
|
||||
}
|
||||
WriteBuffer[LastAddition] = TextToWrite;
|
||||
if (!IsCurrentlyActive)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
static void WriteManager()
|
||||
{
|
||||
FileStream fs = File.OpenWrite(logLocation);
|
||||
fs.Position = fs.Length; // Set position to the end of the stream.
|
||||
while(LastWrite != LastAddition)
|
||||
{
|
||||
DoWrite(fs);
|
||||
}
|
||||
fs.Close();
|
||||
IsCurrentlyActive = false;
|
||||
}
|
||||
static void DoWrite(FileStream fileStream)
|
||||
{
|
||||
LastWrite = LastWrite + 1;
|
||||
if(LastWrite > 1023)
|
||||
{
|
||||
LastWrite = 0;
|
||||
}
|
||||
byte[] utf8Bytes = Encoding.UTF8.GetBytes(WriteBuffer[LastWrite]);
|
||||
fileStream.Write(utf8Bytes, 0, utf8Bytes.Length);
|
||||
}
|
||||
}
|
||||
}
|
149
RadioBroadcaster.Server/LogManager.cs
Normal file
149
RadioBroadcaster.Server/LogManager.cs
Normal file
@ -0,0 +1,149 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
namespace RadioBroadcaster.Server
|
||||
{
|
||||
static class LogManager
|
||||
{
|
||||
static string[] LogItems = new string[1024];
|
||||
static string[] SerialItems = new string[128];
|
||||
static int currentLogPosition = 0;
|
||||
static int lastLogAddition = 0;
|
||||
|
||||
static int currentSerialPosition = 0;
|
||||
static int lastSerialPosition = 0;
|
||||
|
||||
static string logLocation = System.Reflection.Assembly.GetExecutingAssembly().Location.Remove(System.Reflection.Assembly.GetExecutingAssembly().Location.LastIndexOf("\\")) + "\\outputLog";
|
||||
static string serialLocation = System.Reflection.Assembly.GetExecutingAssembly().Location.Remove(System.Reflection.Assembly.GetExecutingAssembly().Location.LastIndexOf("\\")) + "\\SerialLog";
|
||||
|
||||
static bool LogItemsIsRunning = false;
|
||||
static bool SerialItemsIsRunning = false;
|
||||
|
||||
static bool isDebug = false;
|
||||
|
||||
static bool IsCurrentlyActive = false;
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
WriteLogTimer = new System.Timers.Timer(1000);
|
||||
WriteLogTimer.Elapsed += WriteLogTimer_Elapsed;
|
||||
WriteLogTimer.Start();
|
||||
try
|
||||
{
|
||||
if (DateTime.Now.Subtract(File.GetLastWriteTime(serialLocation)).TotalDays > 14) // As the serial log could contain a massive amount of data, we wipe it after some time
|
||||
{
|
||||
File.WriteAllBytes(serialLocation, new byte[] { 0x00 });
|
||||
}
|
||||
else
|
||||
{
|
||||
FileStream fs = File.OpenRead(serialLocation);
|
||||
if (fs.Length > 10737418240) // > 10GB
|
||||
{
|
||||
fs.Dispose();
|
||||
File.WriteAllBytes(serialLocation, new byte[] { 0x00 });
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// We don't absolutely need to do anything here
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void WriteLogTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
if (!LogItemsIsRunning)
|
||||
{
|
||||
LogItemsIsRunning = true;
|
||||
WriteManager();
|
||||
LogItemsIsRunning = false;
|
||||
}
|
||||
if (!SerialItemsIsRunning)
|
||||
{
|
||||
SerialItemsIsRunning = true;
|
||||
SerialWriteManager();
|
||||
SerialItemsIsRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Write(string TextToWrite)
|
||||
{
|
||||
lastLogAddition = lastLogAddition + 1;
|
||||
if (lastLogAddition > 1023)
|
||||
{
|
||||
lastLogAddition = 0;
|
||||
}
|
||||
LogItems[lastLogAddition] = TextToWrite;
|
||||
if (!IsCurrentlyActive)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
static void WriteManager()
|
||||
{
|
||||
FileStream fs = File.OpenWrite(logLocation);
|
||||
fs.Position = fs.Length; // Set position to the end of the stream.
|
||||
while (currentLogPosition != lastLogAddition)
|
||||
{
|
||||
DoWrite(fs);
|
||||
}
|
||||
fs.Close();
|
||||
IsCurrentlyActive = false;
|
||||
}
|
||||
static void DoWrite(FileStream fileStream)
|
||||
{
|
||||
currentLogPosition = currentLogPosition + 1;
|
||||
if (currentLogPosition > 1023)
|
||||
{
|
||||
currentLogPosition = 0;
|
||||
}
|
||||
byte[] utf8Bytes = Encoding.UTF8.GetBytes(LogItems[currentLogPosition] + Environment.NewLine);
|
||||
fileStream.Write(utf8Bytes, 0, utf8Bytes.Length);
|
||||
LogItems[currentLogPosition] = ""; // Clear some mem
|
||||
}
|
||||
/// <summary>
|
||||
/// Logs serial data
|
||||
/// </summary>
|
||||
/// <param name="TextToWrite"></param>
|
||||
public static void WriteSerial(string TextToWrite)
|
||||
{
|
||||
if (isDebug)
|
||||
{
|
||||
lastSerialPosition = lastSerialPosition + 1;
|
||||
if (lastSerialPosition > 127)
|
||||
{
|
||||
lastSerialPosition = 0;
|
||||
}
|
||||
SerialItems[lastSerialPosition] = TextToWrite;
|
||||
}
|
||||
}
|
||||
public static void SerialWriteManager()
|
||||
{
|
||||
FileStream fs = File.OpenWrite(serialLocation);
|
||||
fs.Position = fs.Length; // Set position to the end of the stream.
|
||||
while (currentSerialPosition != lastSerialPosition)
|
||||
{
|
||||
SerialDoWrite(fs);
|
||||
}
|
||||
fs.Close();
|
||||
IsCurrentlyActive = false;
|
||||
}
|
||||
static void SerialDoWrite(FileStream fileStream)
|
||||
{
|
||||
currentSerialPosition = currentSerialPosition + 1;
|
||||
if (currentSerialPosition > 127)
|
||||
{
|
||||
currentSerialPosition = 0;
|
||||
}
|
||||
byte[] utf8Bytes = Encoding.UTF8.GetBytes(SerialItems[currentSerialPosition] + "\t"+ DateTime.Now.ToShortTimeString() + Environment.NewLine);
|
||||
fileStream.Write(utf8Bytes, 0, utf8Bytes.Length);
|
||||
SerialItems[currentSerialPosition] = ""; // Clear some mem
|
||||
}
|
||||
private static System.Timers.Timer WriteLogTimer;
|
||||
}
|
||||
}
|
48
RadioBroadcaster.Server/MainWindow.xaml
Normal file
48
RadioBroadcaster.Server/MainWindow.xaml
Normal file
@ -0,0 +1,48 @@
|
||||
<Window x:Class="RadioBroadcaster.Server.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:RadioBroadcaster.Server"
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="450" Width="800">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="226*"/>
|
||||
<RowDefinition Height="193*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="185*"/>
|
||||
<ColumnDefinition Width="607*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ListBox x:Name="StationsList" Margin="10" Grid.RowSpan="2"/>
|
||||
<Button x:Name="PlayButton" Content="PlayMedia" HorizontalAlignment="Left" Margin="234,142,0,0" VerticalAlignment="Top" Width="75" Click="PlayButton_Click" Grid.Column="1" Height="20"/>
|
||||
<Slider x:Name="TX" HorizontalAlignment="Left" Margin="258,64,0,0" VerticalAlignment="Top" Height="16" Width="139" Minimum="88" Maximum="115" SmallChange="1" IsSnapToTickEnabled="True" TickPlacement="BottomRight" ValueChanged="TX_ValueChanged" Grid.Column="1"/>
|
||||
<Button x:Name="TX_Send" Content="Set TX Strength" HorizontalAlignment="Left" Margin="402,64,0,0" VerticalAlignment="Top" Width="75" Click="TX_Send_Click" Grid.Column="1" Height="20"/>
|
||||
<Label Content="TransmitPower:" HorizontalAlignment="Right" Margin="0,58,354,0" VerticalAlignment="Top" Grid.Column="1" Height="26" Width="90"/>
|
||||
<Canvas HorizontalAlignment="Left" Height="100" Margin="48,84,0,0" VerticalAlignment="Top" Width="100" Grid.Column="1"/>
|
||||
<Grid Grid.Row="1" Grid.Column="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="163*"/>
|
||||
<ColumnDefinition Width="62*"/>
|
||||
<ColumnDefinition Width="163*"/>
|
||||
<ColumnDefinition Width="281*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Margin="0">
|
||||
<Label x:Name="Media_1" Content="Media 1"/>
|
||||
<Label x:Name="p1Loaded" Content="Not Loaded"/>
|
||||
<Label x:Name="p1Playing" Content="Not Playing"/>
|
||||
<Button x:Name="LoadStation1" Content="Load Selected Station" Click="LoadStation1_Click"/>
|
||||
<Button x:Name="Play_1" Content="Play"/>
|
||||
</StackPanel>
|
||||
<StackPanel Margin="0" Grid.Column="2">
|
||||
<Label x:Name="Player2" Content="Player Two"/>
|
||||
<Label x:Name="p2Loaded" Content="Not Loaded"/>
|
||||
<Label x:Name="p2playing" Content="Not Playing"/>
|
||||
<Button x:Name="LoadStation2" Content="Load Selected Station" Click="LoadStation2_Click"/>
|
||||
<Button x:Name="Play_2" Content="Play" Click="Play_2_Click"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
255
RadioBroadcaster.Server/MainWindow.xaml.cs
Normal file
255
RadioBroadcaster.Server/MainWindow.xaml.cs
Normal file
@ -0,0 +1,255 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.IO;
|
||||
|
||||
namespace RadioBroadcaster.Server
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
MediaEngine CurrentMediaEngine;
|
||||
AudioTools audioTools = new AudioTools();
|
||||
// File data
|
||||
const string settingsFile = "settings.dat";
|
||||
string currentRoot = System.Reflection.Assembly.GetExecutingAssembly().Location.Remove(System.Reflection.Assembly.GetExecutingAssembly().Location.LastIndexOf("\\")) + "\\";
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
LogManager.Init();
|
||||
LogManager.Write("Starting software at " + DateTime.Now.ToShortDateString() +" "+ DateTime.Now.ToShortTimeString());
|
||||
CurrentMediaEngine = new MediaEngine();
|
||||
SerialManager.Init();
|
||||
LogManager.Write("Loading Stations list");
|
||||
Stations.LoadStations();
|
||||
// Build UI objects
|
||||
foreach (var item in Stations.sourceStations)
|
||||
{
|
||||
ListBoxItem listItem = new ListBoxItem() { Content = item.InternalName };
|
||||
listItem.Selected += ListItem_Selected;
|
||||
StationsList.Items.Add(listItem);
|
||||
}
|
||||
// Do loading of default settings
|
||||
LogManager.Write("Loading settings");
|
||||
BuildSettings();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates or loads the settings file
|
||||
/// </summary>
|
||||
private void BuildSettings()
|
||||
{
|
||||
if (File.Exists(currentRoot + settingsFile))
|
||||
{
|
||||
string[] settings = File.ReadAllLines(currentRoot + settingsFile);
|
||||
bool stationTag = false;
|
||||
string[] stationsList = new string[0];
|
||||
int stationsInc = 0;
|
||||
foreach (var item in settings)
|
||||
{
|
||||
if (stationTag)
|
||||
{
|
||||
Array.Resize(ref stationsList, stationsList.Length + 1);
|
||||
stationsList[stationsInc] = item;
|
||||
stationsInc++;
|
||||
}
|
||||
else if (item.StartsWith("vol="))
|
||||
{
|
||||
CurrentMediaEngine.SetDefaultVolume = Convert.ToDouble(item.Replace("vol=", ""));
|
||||
LogManager.Write("Volume: " + Convert.ToDouble(item.Replace("vol=", "")));
|
||||
}
|
||||
else if (item.StartsWith("txpow="))
|
||||
{
|
||||
// Not implemented
|
||||
}
|
||||
else if (item.StartsWith("freq="))
|
||||
{
|
||||
// Not implemented
|
||||
}
|
||||
else if (item.StartsWith("Default Station: (comment with // to skip)"))
|
||||
{
|
||||
stationTag = true;
|
||||
}
|
||||
}
|
||||
bool[] validStations = new bool[stationsList.Length];
|
||||
for (int i = 0; i < stationsList.Length; i++)
|
||||
{
|
||||
if (stationsList[i].StartsWith("//"))
|
||||
{
|
||||
validStations[i] = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
validStations[i] = true;
|
||||
}
|
||||
}
|
||||
string SelectedStationName = stationsList[Array.IndexOf(validStations, true)].Trim();
|
||||
LogManager.Write("Station: " + SelectedStationName);
|
||||
foreach (var item in Stations.sourceStations)
|
||||
{
|
||||
if (item.InternalName == SelectedStationName)
|
||||
{
|
||||
|
||||
CurrentMediaEngine.SetPrimaryLocation = new Uri(item.URISource);
|
||||
SerialManager.SetRDSStationName(item.RDS_StationName, true);
|
||||
LogManager.Write("Setting RDS Station Name: " + item.RDS_StationName);
|
||||
SerialManager.SetRDSStationData(item.RDS_Buffers[0]);
|
||||
LogManager.Write("Setting RDS Station Data: " + item.RDS_Buffers[0]);
|
||||
p1Loaded.Content = "Loaded";
|
||||
LogManager.Write("Playing...");
|
||||
CurrentMediaEngine.PlayPrimary();
|
||||
p1Playing.Content = "Playing " + CurrentMediaEngine.SetPrimaryLocation;
|
||||
}
|
||||
}
|
||||
}
|
||||
else // Create a default settings file
|
||||
{
|
||||
LogManager.Write("Settings file did not exist, creating...");
|
||||
string temp = "vol=0.7" + Environment.NewLine
|
||||
+ "txpow=115" + Environment.NewLine
|
||||
+ "freq=88.10 MHz" + Environment.NewLine
|
||||
+ "Default Station: (comment with // to skip)" + Environment.NewLine;
|
||||
foreach (var item in Stations.sourceStations)
|
||||
{
|
||||
temp = temp + item.InternalName + Environment.NewLine;
|
||||
}
|
||||
File.WriteAllText(currentRoot + settingsFile, temp);
|
||||
}
|
||||
}
|
||||
|
||||
private void ListItem_Selected(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ListBoxItem listBoxItem = (ListBoxItem)sender;
|
||||
PlayButton.Content = "Play " + listBoxItem.Content;
|
||||
}
|
||||
|
||||
private void PlayButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!CurrentMediaEngine.IsPlayingAudio)
|
||||
{
|
||||
CurrentMediaEngine.SetPrimaryLocation = new Uri(Stations.sourceStations[StationsList.SelectedIndex].URISource);
|
||||
SerialManager.SetRDSStationName(Stations.sourceStations[StationsList.SelectedIndex].RDS_StationName, true);
|
||||
SerialManager.SetRDSStationData(Stations.sourceStations[StationsList.SelectedIndex].RDS_Buffers[0]);
|
||||
p1Loaded.Content = "Loaded";
|
||||
CurrentMediaEngine.PlayPrimary();
|
||||
p1Playing.Content = "Playing " + CurrentMediaEngine.SetPrimaryLocation;
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentMediaEngine.SetSecondaryLocation = new Uri(Stations.sourceStations[StationsList.SelectedIndex].URISource);
|
||||
SerialManager.SetRDSStationName(Stations.sourceStations[StationsList.SelectedIndex].RDS_StationName, true);
|
||||
SerialManager.SetRDSStationData(Stations.sourceStations[StationsList.SelectedIndex].RDS_Buffers[0]);
|
||||
if (CurrentMediaEngine.CurrentPrimaryPlayer == 1)
|
||||
{
|
||||
p2Loaded.Content = "Loaded";
|
||||
}
|
||||
else
|
||||
{
|
||||
p1Loaded.Content = "Loaded";
|
||||
}
|
||||
CurrentMediaEngine.PlaySecondary();
|
||||
if (CurrentMediaEngine.CurrentPrimaryPlayer == 1)
|
||||
{
|
||||
p2playing.Content = "Playing " + CurrentMediaEngine.SetSecondaryLocation;
|
||||
}
|
||||
else
|
||||
{
|
||||
p1Playing.Content = "Playing " + CurrentMediaEngine.SetSecondaryLocation;
|
||||
}
|
||||
audioTools.Crossfade(CurrentMediaEngine);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void TX_Send_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SerialManager.SetTXPower(TX.Value.ToString());
|
||||
}
|
||||
|
||||
private void TX_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void LoadStation1_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CurrentMediaEngine.SetPlayer1 = Stations.sourceStations[StationsList.SelectedIndex].URISource;
|
||||
p1Loaded.Content = Stations.sourceStations[StationsList.SelectedIndex].RDS_StationName;
|
||||
}
|
||||
|
||||
private void LoadStation2_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CurrentMediaEngine.SetPlayer2 = Stations.sourceStations[StationsList.SelectedIndex].URISource;
|
||||
p2Loaded.Content = Stations.sourceStations[StationsList.SelectedIndex].RDS_StationName;
|
||||
}
|
||||
|
||||
private void Play_2_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if(CurrentMediaEngine.SetPlayer1 != null)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Various tools for handling audio streams and to add effects
|
||||
/// </summary>
|
||||
class AudioTools
|
||||
{
|
||||
/// <summary>
|
||||
/// Crossfades the audio between the two tracks
|
||||
/// </summary>
|
||||
/// <param name="playbackEngine">The playback engine in use</param>
|
||||
/// <param name="steptime">the time (in ms) to wait between each step</param>
|
||||
/// <param name="steps">The number of steps to take</param>
|
||||
/// <param name="FullVolume">The maximum volume</param>
|
||||
public void Crossfade(MediaEngine playbackEngine, int steptime = 40, int steps = 16, double FullVolume=0.7)
|
||||
{
|
||||
playbackEngine.SecondaryVolume = 0;
|
||||
playbackEngine.SecondaryMuted = false;
|
||||
double volumePerStep = FullVolume / steps;
|
||||
while (steps > 0)
|
||||
{
|
||||
playbackEngine.PrimaryVolume = playbackEngine.PrimaryVolume - volumePerStep;
|
||||
if (playbackEngine.SecondaryVolume > FullVolume - volumePerStep)
|
||||
{
|
||||
playbackEngine.SecondaryVolume = FullVolume;
|
||||
}
|
||||
else
|
||||
{
|
||||
playbackEngine.SecondaryVolume = playbackEngine.SecondaryVolume + volumePerStep;
|
||||
}
|
||||
Thread.Sleep(steptime);
|
||||
steps--;
|
||||
}
|
||||
// Mute and reset volume
|
||||
playbackEngine.PrimaryMuted = true;
|
||||
playbackEngine.PrimaryVolume = FullVolume;
|
||||
playbackEngine.StopPrimary();
|
||||
playbackEngine.SwapPrimary();
|
||||
}
|
||||
/// <summary>
|
||||
/// Exposes the underlying audio stream within an m3u encapsulation
|
||||
/// </summary>
|
||||
public void m3uDecapsulator()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
379
RadioBroadcaster.Server/MediaEngine.cs
Normal file
379
RadioBroadcaster.Server/MediaEngine.cs
Normal file
@ -0,0 +1,379 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace RadioBroadcaster.Server
|
||||
{
|
||||
class MediaEngine
|
||||
{
|
||||
MediaPlayer PlayerOne = new MediaPlayer();
|
||||
MediaPlayer PlayerTwo = new MediaPlayer();
|
||||
Uri PlayerOneUri;
|
||||
Uri PlayerTwoUri;
|
||||
private double DefaultVolume = 0.5;
|
||||
/// <summary>
|
||||
/// Handlers for if the media either ends or completely stops playing.
|
||||
/// Default interval is 5s between attempts to restart.
|
||||
/// </summary>
|
||||
public void AddHandlers()
|
||||
{
|
||||
PlayerOne.MediaEnded += PlayerOne_MediaEnded;
|
||||
PlayerOne.MediaFailed += PlayerOne_MediaFailed;
|
||||
|
||||
PlayerTwo.MediaEnded += PlayerTwo_MediaEnded;
|
||||
PlayerTwo.MediaFailed += PlayerTwo_MediaFailed;
|
||||
}
|
||||
|
||||
private void PlayerTwo_MediaFailed(object sender, ExceptionEventArgs e)
|
||||
{
|
||||
LogManager.Write("Media stream 2 failed at time: " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString());
|
||||
PlayerTwo.Close();
|
||||
Thread.Sleep(5000);
|
||||
PlayerTwo.Open(PlayerTwoUri);
|
||||
PlayerTwo.Play();
|
||||
}
|
||||
|
||||
private void PlayerTwo_MediaEnded(object sender, EventArgs e)
|
||||
{
|
||||
LogManager.Write("Media stream 2 ended at time: " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString());
|
||||
PlayerTwo.Close();
|
||||
Thread.Sleep(5000);
|
||||
PlayerTwo.Open(PlayerTwoUri);
|
||||
PlayerTwo.Play();
|
||||
}
|
||||
|
||||
private void PlayerOne_MediaFailed(object sender, ExceptionEventArgs e)
|
||||
{
|
||||
LogManager.Write("Media stream 1 failed at time: " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString());
|
||||
PlayerOne.Close();
|
||||
Thread.Sleep(5000);
|
||||
PlayerOne.Open(PlayerOneUri);
|
||||
PlayerOne.Play();
|
||||
}
|
||||
|
||||
private void PlayerOne_MediaEnded(object sender, EventArgs e)
|
||||
{
|
||||
LogManager.Write("Media stream 1 ended at time: " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString());
|
||||
PlayerOne.Close();
|
||||
Thread.Sleep(5000);
|
||||
PlayerOne.Open(PlayerOneUri);
|
||||
PlayerOne.Play();
|
||||
}
|
||||
#region States
|
||||
private bool One_Playing = false;
|
||||
private bool One_Loaded = false;
|
||||
|
||||
private bool Two_Playing = false;
|
||||
private bool Two_Loaded = false;
|
||||
|
||||
private int CurrentPrimary = 1;
|
||||
#endregion
|
||||
public Uri SetPrimaryLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (CurrentPrimary == 1)
|
||||
{
|
||||
return PlayerOne.Source;
|
||||
}
|
||||
else
|
||||
{
|
||||
return PlayerTwo.Source;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if(CurrentPrimary == 1)
|
||||
{
|
||||
PlayerOneUri = value;
|
||||
PlayerOne.Open(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayerTwoUri = value;
|
||||
PlayerTwo.Open(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public Uri SetSecondaryLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (CurrentPrimary == 1)
|
||||
{
|
||||
return PlayerTwo.Source;
|
||||
}
|
||||
else
|
||||
{
|
||||
return PlayerOne.Source;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (CurrentPrimary == 1)
|
||||
{
|
||||
PlayerTwoUri = value;
|
||||
PlayerTwo.Open(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayerOneUri = value;
|
||||
PlayerOne.Open(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void PlayPrimary()
|
||||
{
|
||||
if(CurrentPrimary == 1)
|
||||
{
|
||||
PlayerOne.Play();
|
||||
One_Playing = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayerTwo.Play();
|
||||
Two_Playing = true;
|
||||
}
|
||||
}
|
||||
public void PlaySecondary()
|
||||
{
|
||||
if (CurrentPrimary == 1)
|
||||
{
|
||||
//PlayerTwo.IsMuted = true;
|
||||
PlayerTwo.Play();
|
||||
Two_Playing = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//PlayerOne.IsMuted = true;
|
||||
PlayerOne.Play();
|
||||
One_Playing = true;
|
||||
}
|
||||
}
|
||||
public string SetPlayer1
|
||||
{
|
||||
get
|
||||
{
|
||||
return PlayerOneUri.AbsoluteUri;
|
||||
}
|
||||
set
|
||||
{
|
||||
PlayerOneUri = new Uri(value);
|
||||
if (One_Playing)
|
||||
{
|
||||
PlayerOne.Open(PlayerOneUri);
|
||||
}
|
||||
}
|
||||
}
|
||||
public string SetPlayer2
|
||||
{
|
||||
get
|
||||
{
|
||||
return PlayerTwoUri.AbsoluteUri;
|
||||
}
|
||||
set
|
||||
{
|
||||
PlayerTwoUri = new Uri(value);
|
||||
if (Two_Playing)
|
||||
{
|
||||
PlayerTwo.Open(PlayerTwoUri);
|
||||
}
|
||||
}
|
||||
}
|
||||
public bool IsPlayingAudio
|
||||
{
|
||||
get
|
||||
{
|
||||
if(One_Playing == false && Two_Playing == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
public bool IsOnePlayingAudio
|
||||
{
|
||||
get
|
||||
{
|
||||
return One_Playing;
|
||||
}
|
||||
}
|
||||
public bool IsTwoPlayingAudio
|
||||
{
|
||||
get
|
||||
{
|
||||
return Two_Playing;
|
||||
}
|
||||
}
|
||||
public bool IsPrimaryLoaded
|
||||
{
|
||||
get
|
||||
{
|
||||
if(CurrentPrimary == 1)
|
||||
{
|
||||
return One_Loaded;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Two_Loaded;
|
||||
}
|
||||
}
|
||||
}
|
||||
public bool IsSecondaryLoaded
|
||||
{
|
||||
get
|
||||
{
|
||||
if (CurrentPrimary == 1)
|
||||
{
|
||||
return Two_Loaded;
|
||||
}
|
||||
else
|
||||
{
|
||||
return One_Loaded;
|
||||
}
|
||||
}
|
||||
}
|
||||
public int CurrentPrimaryPlayer
|
||||
{
|
||||
get{ return CurrentPrimary; }
|
||||
}
|
||||
public double PrimaryVolume
|
||||
{
|
||||
get
|
||||
{
|
||||
if(CurrentPrimary == 1)
|
||||
{
|
||||
return PlayerOne.Volume;
|
||||
}
|
||||
else
|
||||
{
|
||||
return PlayerTwo.Volume;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if(CurrentPrimary == 1)
|
||||
{
|
||||
PlayerOne.Volume = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayerTwo.Volume = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
public double SecondaryVolume
|
||||
{
|
||||
get
|
||||
{
|
||||
if (CurrentPrimary == 1)
|
||||
{
|
||||
return PlayerTwo.Volume;
|
||||
}
|
||||
else
|
||||
{
|
||||
return PlayerOne.Volume;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (CurrentPrimary == 1)
|
||||
{
|
||||
PlayerTwo.Volume = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayerOne.Volume = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
public double SetDefaultVolume
|
||||
{
|
||||
set
|
||||
{
|
||||
DefaultVolume = value;
|
||||
PrimaryVolume = value;
|
||||
SecondaryVolume = value;
|
||||
}
|
||||
}
|
||||
public bool SecondaryMuted
|
||||
{
|
||||
get
|
||||
{
|
||||
if (CurrentPrimary == 1)
|
||||
{
|
||||
return PlayerTwo.IsMuted;
|
||||
}
|
||||
else
|
||||
{
|
||||
return PlayerOne.IsMuted;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if(CurrentPrimary == 1)
|
||||
{
|
||||
PlayerTwo.IsMuted = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayerOne.IsMuted = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
public bool PrimaryMuted
|
||||
{
|
||||
get
|
||||
{
|
||||
if (CurrentPrimary == 1)
|
||||
{
|
||||
return PlayerOne.IsMuted;
|
||||
}
|
||||
else
|
||||
{
|
||||
return PlayerTwo.IsMuted;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (CurrentPrimary == 1)
|
||||
{
|
||||
PlayerOne.IsMuted = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayerTwo.IsMuted = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void SwapPrimary()
|
||||
{
|
||||
if(CurrentPrimary == 1)
|
||||
{
|
||||
CurrentPrimary = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentPrimary = 1;
|
||||
}
|
||||
}
|
||||
public void StopPrimary()
|
||||
{
|
||||
if(CurrentPrimary == 1)
|
||||
{
|
||||
PlayerOne.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayerTwo.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
55
RadioBroadcaster.Server/Properties/AssemblyInfo.cs
Normal file
55
RadioBroadcaster.Server/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("RadioBroadcaster.Server")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("RadioBroadcaster.Server")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
//In order to begin building localizable applications, set
|
||||
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
|
||||
//inside a <PropertyGroup>. For example, if you are using US english
|
||||
//in your source files, set the <UICulture> to en-US. Then uncomment
|
||||
//the NeutralResourceLanguage attribute below. Update the "en-US" in
|
||||
//the line below to match the UICulture setting in the project file.
|
||||
|
||||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
|
||||
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
71
RadioBroadcaster.Server/Properties/Resources.Designer.cs
generated
Normal file
71
RadioBroadcaster.Server/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,71 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace RadioBroadcaster.Server.Properties
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources
|
||||
{
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((resourceMan == null))
|
||||
{
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("RadioBroadcaster.Server.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture
|
||||
{
|
||||
get
|
||||
{
|
||||
return resourceCulture;
|
||||
}
|
||||
set
|
||||
{
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
117
RadioBroadcaster.Server/Properties/Resources.resx
Normal file
117
RadioBroadcaster.Server/Properties/Resources.resx
Normal file
@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
30
RadioBroadcaster.Server/Properties/Settings.Designer.cs
generated
Normal file
30
RadioBroadcaster.Server/Properties/Settings.Designer.cs
generated
Normal file
@ -0,0 +1,30 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace RadioBroadcaster.Server.Properties
|
||||
{
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||
{
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
7
RadioBroadcaster.Server/Properties/Settings.settings
Normal file
7
RadioBroadcaster.Server/Properties/Settings.settings
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
102
RadioBroadcaster.Server/RadioBroadcaster.Server.csproj
Normal file
102
RadioBroadcaster.Server/RadioBroadcaster.Server.csproj
Normal file
@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{FE7C4844-0504-4FF0-97A5-AFE1064D058D}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>RadioBroadcaster.Server</RootNamespace>
|
||||
<AssemblyName>RadioBroadcaster.Server</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xaml">
|
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="FileEngine.cs" />
|
||||
<Compile Include="LogManager.cs" />
|
||||
<Compile Include="MediaEngine.cs" />
|
||||
<Compile Include="SerialManager.cs" />
|
||||
<Compile Include="Stations.cs" />
|
||||
<Page Include="MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="MainWindow.xaml.cs">
|
||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
260
RadioBroadcaster.Server/SerialManager.cs
Normal file
260
RadioBroadcaster.Server/SerialManager.cs
Normal file
@ -0,0 +1,260 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO.Ports;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace RadioBroadcaster.Server
|
||||
{
|
||||
static class SerialManager
|
||||
{
|
||||
static bool _continue;
|
||||
static SerialPort _serialPort;
|
||||
/// <summary>
|
||||
/// Data is sent at a predetermined rate. As the arduino can only process one piece of data at a time,
|
||||
/// we add each command to the buffer; which will be sent as soon as possible
|
||||
/// </summary>
|
||||
static string[] SendBuffer = new string[0];
|
||||
static int SendBufferSize = 64;
|
||||
static int currentBufferPos = 0; // The current line to send
|
||||
static int lastBufferAddition = -1; // The last position added to within the buffer
|
||||
private static System.Timers.Timer CarouselTimer;
|
||||
private static System.Timers.Timer SendBufferTimer;
|
||||
|
||||
const string FileName = "PortSelection.txt";
|
||||
public static void Init()
|
||||
{
|
||||
Thread readThread = new Thread(Read);
|
||||
SendBuffer = new string[SendBufferSize];
|
||||
_serialPort = new SerialPort();
|
||||
_serialPort.BaudRate = 9600;
|
||||
SendBufferTimer = new System.Timers.Timer(610); // We tick at the same rate as the arduino. There may be clashing
|
||||
// Due to timing differences, but so long as we always take longer than it takes to process data, we
|
||||
// we will ensure data arrives correctly. Make sure this is delayed while serial gets set-up.
|
||||
// Currently, as the carousel works on a 2 second timer, we can send at least 3 packets of data before
|
||||
// a new one is routinely added.
|
||||
SendBufferTimer.Elapsed += SendBufferTimer_Elapsed;
|
||||
CarouselTimer = new System.Timers.Timer(2000);
|
||||
CarouselTimer.Elapsed += CarouselTimer_Elapsed;
|
||||
string[] AvailablePorts;
|
||||
string s = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
||||
try
|
||||
{
|
||||
AvailablePorts = File.ReadAllText(s.Remove(s.LastIndexOf("\\")) + "\\" + FileName).Replace(Environment.NewLine, "\n").Split('\n');
|
||||
}
|
||||
catch
|
||||
{
|
||||
AvailablePorts = SerialPort.GetPortNames();
|
||||
File.WriteAllLines(s.Remove(s.LastIndexOf("\\")) + "\\" + FileName, AvailablePorts);
|
||||
}
|
||||
bool[] removedPorts = new bool[AvailablePorts.Length];
|
||||
for (int i = 0; i < AvailablePorts.Length; i++)
|
||||
{
|
||||
if (AvailablePorts[i].StartsWith("//"))
|
||||
{
|
||||
removedPorts[i] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
removedPorts[i] = false;
|
||||
}
|
||||
}
|
||||
_serialPort.PortName = AvailablePorts[Array.IndexOf(removedPorts,false)];
|
||||
try
|
||||
{
|
||||
_serialPort.Open();
|
||||
LogManager.Write("Serial port opened successfully");
|
||||
}
|
||||
catch
|
||||
{
|
||||
LogManager.Write("Couldn't access " + _serialPort.PortName + ", loading first port as a default");
|
||||
_serialPort.PortName = SerialPort.GetPortNames()[0];
|
||||
_serialPort.Open();
|
||||
}
|
||||
_continue = true;
|
||||
readThread.Start();
|
||||
SendBufferTimer.Start();
|
||||
Console.Write("Ready to write data to the port");
|
||||
}
|
||||
static bool SendBufferLock = false;
|
||||
static int waitTicks = 0;
|
||||
/// <summary>
|
||||
/// Sends data, if there is any, at every timer tick. Allows a queue of commands
|
||||
/// to be executed without clashing.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private static void SendBufferTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
if(waitTicks > 5)
|
||||
{
|
||||
if (!SendBufferLock)
|
||||
{
|
||||
SendBufferLock = true;
|
||||
if (SendBuffer[currentBufferPos] != null)
|
||||
{
|
||||
string s = SendBuffer[currentBufferPos].Trim();
|
||||
if (s == "" || s == null)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.WriteSerial("\tOut: " + s);
|
||||
_serialPort.WriteLine(s);
|
||||
SendBuffer[currentBufferPos] = "";
|
||||
if (currentBufferPos >= SendBufferSize - 1)
|
||||
{
|
||||
currentBufferPos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentBufferPos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
SendBufferLock = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
waitTicks++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static string currentIteration = "";
|
||||
public static void SetRDSStationName(string setStationName, bool useCarousel = false, bool stopCarousel = false)
|
||||
{
|
||||
if (useCarousel)
|
||||
{
|
||||
LogManager.Write("Starting carousel...");
|
||||
CarouselTimer.Stop();
|
||||
if(setStationName.Last() != ' ') // Make sure there is a space between the first and last char
|
||||
{
|
||||
setStationName = setStationName + " ";
|
||||
}
|
||||
currentIteration = setStationName;
|
||||
|
||||
CarouselTimer.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (setStationName.Length < 9)
|
||||
{
|
||||
Write("RDSName" + setStationName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Write("RDSName" + setStationName.Remove(8));
|
||||
}
|
||||
}
|
||||
if (stopCarousel)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public static void SetRDSStationData(string data)
|
||||
{
|
||||
Write("RDSData" + data);
|
||||
}
|
||||
public static void SetFrequency(string Frequency)
|
||||
{
|
||||
string temp = Frequency.ToLower();
|
||||
if (temp.Contains("mhz"))
|
||||
{
|
||||
temp = temp.Remove(temp.IndexOf("mhz"));
|
||||
}
|
||||
temp = temp.Replace(".", "");
|
||||
temp = temp.Trim();
|
||||
Write("StatFreq" + temp);
|
||||
}
|
||||
public static void SetTXPower(string power)
|
||||
{
|
||||
string s = power.Trim();
|
||||
Write("TXpower" + s);
|
||||
}
|
||||
|
||||
private static void CarouselTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
char one = currentIteration[0];
|
||||
currentIteration = currentIteration.Remove(0, 1) + one;
|
||||
SetRDSStationName(currentIteration);
|
||||
}
|
||||
/// <summary>
|
||||
/// Adds the data to the write queue
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
static void Write(string message)
|
||||
{
|
||||
if(message.Trim() != "")
|
||||
{
|
||||
lastBufferAddition = lastBufferAddition + 1;
|
||||
if (lastBufferAddition > SendBufferSize -1)
|
||||
{
|
||||
lastBufferAddition = 0;
|
||||
}
|
||||
SendBuffer[lastBufferAddition] = message;
|
||||
}
|
||||
}
|
||||
static void Read()
|
||||
{
|
||||
while (_continue)
|
||||
{
|
||||
try
|
||||
{
|
||||
string message = _serialPort.ReadLine();
|
||||
LogManager.WriteSerial(message);
|
||||
if (message == "beat")
|
||||
{
|
||||
// We recieved a heartbeat
|
||||
|
||||
}
|
||||
else if (message.Trim() != "")
|
||||
{
|
||||
Console.WriteLine(message);
|
||||
switch (message.Remove(message.IndexOf(":")))
|
||||
{
|
||||
case "Freq":
|
||||
break;
|
||||
case "TXPower":
|
||||
break;
|
||||
case "InLevel":
|
||||
break;
|
||||
case "ASQ":
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (TimeoutException) { }
|
||||
}
|
||||
}
|
||||
public static bool carouselContinue = false;
|
||||
public static void RDSStationNameCarousel(string StationName, SerialPort serialPort)
|
||||
{
|
||||
string originalName = StationName;
|
||||
string currentIteration = originalName;
|
||||
carouselContinue = true;
|
||||
while (carouselContinue)
|
||||
{
|
||||
char one = currentIteration[0];
|
||||
currentIteration = currentIteration.Remove(0, 1) + one;
|
||||
if (currentIteration.Length < 9)
|
||||
{
|
||||
serialPort.WriteLine("RDSName" + currentIteration);
|
||||
}
|
||||
else
|
||||
{
|
||||
serialPort.WriteLine("RDSName" + currentIteration.Remove(8));
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
84
RadioBroadcaster.Server/Stations.cs
Normal file
84
RadioBroadcaster.Server/Stations.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RadioBroadcaster.Server
|
||||
{
|
||||
public static class Stations
|
||||
{
|
||||
public static List<SourceStation> sourceStations = new List<SourceStation>();
|
||||
public static void LoadStations()
|
||||
{
|
||||
sourceStations.Add(new SourceStation()
|
||||
{
|
||||
InternalName = "Sound",
|
||||
InternalID = 0,
|
||||
URISource = "http://tunein-icecast.mediaworks.nz/sound_128kbps",
|
||||
RDS_StationName = "The Sound - Rebroadcast",
|
||||
RDS_Buffers = new string[] { "The Sound FM - ", "Rebroadcast" }
|
||||
});
|
||||
sourceStations.Add(new SourceStation()
|
||||
{
|
||||
InternalName = "MoreFM",
|
||||
InternalID = 0,
|
||||
URISource = "http://tunein-icecast.mediaworks.nz/more_128kbps",
|
||||
RDS_StationName = "MoreFM - Rebroadcast",
|
||||
RDS_Buffers = new string[] { "MoreFM - ", "Rebroadcast" }
|
||||
});
|
||||
sourceStations.Add(new SourceStation()
|
||||
{
|
||||
InternalName = "P4",
|
||||
InternalID = 0,
|
||||
URISource = "http://http-live.sr.se/p4stockholm-aac-96",
|
||||
RDS_StationName = "P4 Stockholm",
|
||||
RDS_Buffers = new string[] { "P4 Stockholm ", "Rebroadcast" }
|
||||
});
|
||||
sourceStations.Add(new SourceStation()
|
||||
{
|
||||
InternalName = "Radio Hauraki",
|
||||
InternalID = 0,
|
||||
URISource = "https://ais-nzme.streamguys1.com/nz_009/playlist.m3u8",
|
||||
RDS_StationName = "Radio Hauraki",
|
||||
RDS_Buffers = new string[] { "Radio Hauraki", "Rebroadcast" }
|
||||
});
|
||||
sourceStations.Add(new SourceStation()
|
||||
{
|
||||
InternalName = "Rock",
|
||||
InternalID = 0,
|
||||
URISource = "http://tunein-icecast.mediaworks.nz/rock_128kbps",
|
||||
RDS_StationName = "The Rock - Rebroadcast",
|
||||
RDS_Buffers = new string[] { "The Rock FM - ", "Rebroadcast" }
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
public class SourceStation : IEquatable<SourceStation>
|
||||
{
|
||||
public string InternalName { get; set; }
|
||||
public int InternalID { get; set; }
|
||||
|
||||
public string URISource { get; set; }
|
||||
|
||||
public string RequestedFrequency { get; set; }
|
||||
public int BroadcastPower { get; set; }
|
||||
public string RDS_StationName { get; set; }
|
||||
/// <summary>
|
||||
/// RDS Buffer. Cannot exceed 32 chars per segment
|
||||
/// </summary>
|
||||
public string[] RDS_Buffers { get; set; }
|
||||
|
||||
public bool Equals(SourceStation otherStation)
|
||||
{
|
||||
if (this.InternalName != otherStation.InternalName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
25
RadioBroadcaster.sln
Normal file
25
RadioBroadcaster.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27428.2043
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RadioBroadcaster.Server", "RadioBroadcaster.Server\RadioBroadcaster.Server.csproj", "{FE7C4844-0504-4FF0-97A5-AFE1064D058D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{FE7C4844-0504-4FF0-97A5-AFE1064D058D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FE7C4844-0504-4FF0-97A5-AFE1064D058D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FE7C4844-0504-4FF0-97A5-AFE1064D058D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FE7C4844-0504-4FF0-97A5-AFE1064D058D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {A1F4495C-B9DD-4AE5-B631-029D8F167948}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Reference in New Issue
Block a user