mirror of
https://github.com/jwetzell/qController.git
synced 2026-08-19 14:14:22 +00:00
Initial check-in of module qController
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="qController.ControlPage">
|
||||
<ContentPage.Content>
|
||||
<StackLayout x:Name="sLayout">
|
||||
<Grid x:Name="topBar" HorizontalOptions="FillAndExpand">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image x:Name = "backButton" HorizontalOptions = "Start" Margin="20,10,20,10" Grid.Row="0" Grid.Column="0" />
|
||||
</Grid>
|
||||
</StackLayout>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
||||
@@ -0,0 +1,161 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xamarin.Forms;
|
||||
using Rug.Osc;
|
||||
using System.Collections;
|
||||
|
||||
namespace qController
|
||||
{
|
||||
public partial class ControlPage : ContentPage
|
||||
{
|
||||
QController qController;
|
||||
Label instanceName = new Label();
|
||||
QSelectedCueCell qCell;
|
||||
QSelectedCueOptionsCell qSelectedCueOptions;
|
||||
Grid mainG;
|
||||
public ControlPage(string name, string address)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
qController = new QController(address, 53000);
|
||||
qController.qParser.SelectedCueUpdated += SelectedCueUpdated;
|
||||
NavigationPage.SetHasNavigationBar(this, false);
|
||||
instanceName.Text = name;
|
||||
|
||||
|
||||
InitGUI();
|
||||
|
||||
}
|
||||
|
||||
private void InitGUI()
|
||||
{
|
||||
|
||||
|
||||
instanceName.HorizontalTextAlignment = TextAlignment.Center;
|
||||
instanceName.HorizontalOptions = LayoutOptions.CenterAndExpand;
|
||||
instanceName.VerticalOptions = LayoutOptions.CenterAndExpand;
|
||||
topBar.Children.Add(instanceName, 1, 0);
|
||||
topBar.BackgroundColor = Color.FromHex("71AEFF");
|
||||
|
||||
BackgroundColor = Color.FromHex("4A4A4A");
|
||||
backButton.Source = ImageSource.FromFile("back");
|
||||
switch (Device.RuntimePlatform)
|
||||
{
|
||||
case Device.iOS:
|
||||
backButton.Margin = new Thickness(20, 45, 20, 10);
|
||||
instanceName.Margin = new Thickness(20, 45, 20, 10);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
Hashtable cmds = new Hashtable();
|
||||
|
||||
var backButtonGesture = new TapGestureRecognizer();
|
||||
|
||||
backButtonGesture.Tapped += Back;
|
||||
backButton.GestureRecognizers.Add(backButtonGesture);
|
||||
|
||||
|
||||
cmds.Add("Pause", "/pause");
|
||||
cmds.Add("Resume", "/resume");
|
||||
cmds.Add("Panic", "/panic");
|
||||
cmds.Add("Next", "/select/next");
|
||||
cmds.Add("Previous", "/select/previous");
|
||||
cmds.Add("Preview", "/preview");
|
||||
|
||||
qCell = new QSelectedCueCell();
|
||||
qSelectedCueOptions = new QSelectedCueOptionsCell(qController);
|
||||
|
||||
sLayout.Children.Add(qCell);
|
||||
|
||||
|
||||
mainG = new Grid
|
||||
{
|
||||
Padding = new Thickness(0),
|
||||
RowDefinitions = {
|
||||
new RowDefinition{Height = GridLength.Auto},
|
||||
new RowDefinition{Height = GridLength.Auto},
|
||||
new RowDefinition{Height = GridLength.Auto}
|
||||
},
|
||||
ColumnDefinitions = {
|
||||
new ColumnDefinition{Width = new GridLength(1,GridUnitType.Star)},
|
||||
new ColumnDefinition{Width = new GridLength(1,GridUnitType.Star)},
|
||||
new ColumnDefinition{Width = new GridLength(1,GridUnitType.Star)}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int row = 0;
|
||||
int column = 0;
|
||||
foreach (string cmd in cmds.Keys)
|
||||
{
|
||||
QButton b = new QButton(cmd,(string)cmds[cmd]);
|
||||
b.Clicked += sendOSC;
|
||||
if(cmd=="Panic")
|
||||
{
|
||||
b.BackgroundColor = Color.IndianRed;
|
||||
}
|
||||
else
|
||||
{
|
||||
b.BackgroundColor = Color.FromHex("D8D8D8");
|
||||
}
|
||||
b.TextColor = Color.Black;
|
||||
mainG.Children.Add(b,column,row);
|
||||
row++;
|
||||
if(row == 3){
|
||||
row = 0;
|
||||
column = 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QButton goButton = new QButton("GO","/go");
|
||||
goButton.Clicked += sendOSC;
|
||||
goButton.BackgroundColor = Color.SeaGreen;
|
||||
goButton.TextColor = Color.Black;
|
||||
mainG.Children.Add(goButton,1,0);
|
||||
Grid.SetRowSpan(goButton,3);
|
||||
|
||||
sLayout.Children.Add(mainG);
|
||||
|
||||
}
|
||||
|
||||
void sendOSC(object sender, EventArgs e)
|
||||
{
|
||||
qController.sendCommand(((QButton)sender).OSCCommand);
|
||||
}
|
||||
|
||||
void Back(object sender, EventArgs e)
|
||||
{
|
||||
App.iNav.PopModalAsync();
|
||||
}
|
||||
|
||||
public void SelectedCueUpdated(object sender, CueEventArgs e){
|
||||
Device.BeginInvokeOnMainThread(()=>{
|
||||
if (e.SelectedCue.type.Equals("Audio"))
|
||||
{
|
||||
//Console.WriteLine("CUE IS AN AUDIO CUE");
|
||||
sLayout.Children.Add(qSelectedCueOptions);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Console.WriteLine("CUE IS NOT AN AUDIO CUE");
|
||||
sLayout.Children.Remove(qSelectedCueOptions);
|
||||
}
|
||||
qCell.UpdateSelectedCue(e.SelectedCue);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnDisappearing()
|
||||
{
|
||||
base.OnDisappearing();
|
||||
Console.WriteLine("Disappeared");
|
||||
qController.Kill();
|
||||
}
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
Console.WriteLine("Appeared");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:qController" x:Class="qController.qControllerPage">
|
||||
<StackLayout x:Name="sLayout">
|
||||
<Grid x:Name="topBar" HorizontalOptions="FillAndExpand">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image x:Name = "scanButton" HorizontalOptions = "Start" Margin="20,10,20,10" Grid.Row="0" Grid.Column="0" />
|
||||
<Image x:Name = "addButton" HorizontalOptions = "End" Margin="20,10,20,10" Grid.Row="0" Grid.Column="1" />
|
||||
</Grid>
|
||||
<ListView x:Name="lstView" HasUnevenRows = "true" >
|
||||
</ListView>
|
||||
</StackLayout>
|
||||
</ContentPage>
|
||||
@@ -0,0 +1,134 @@
|
||||
using Xamarin.Forms;
|
||||
using System.Net;
|
||||
using System;
|
||||
using Rug.Osc;
|
||||
using Acr.UserDialogs;
|
||||
using Acr.Settings;
|
||||
using Zeroconf;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace qController
|
||||
{
|
||||
|
||||
public partial class qControllerPage : ContentPage
|
||||
{
|
||||
public qControllerPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
InitGUI();
|
||||
|
||||
}
|
||||
|
||||
private void InitGUI()
|
||||
{
|
||||
NavigationPage.SetHasNavigationBar(this, false);
|
||||
lstView.ItemsSource = QStorage.qInstances;
|
||||
|
||||
|
||||
lstView.ItemTemplate = new DataTemplate(typeof(QInstanceCell));
|
||||
lstView.SeparatorVisibility = SeparatorVisibility.None;
|
||||
lstView.ItemTapped += (object sender, ItemTappedEventArgs e) =>
|
||||
{
|
||||
// don't do anything if we just de-selected the row
|
||||
if (e.Item == null) return;
|
||||
// do something with e.SelectedItem
|
||||
((ListView)sender).SelectedItem = null; // de-select the row
|
||||
};
|
||||
topBar.BackgroundColor = Color.FromHex("71AEFF");
|
||||
|
||||
switch (Device.RuntimePlatform)
|
||||
{
|
||||
case Device.iOS:
|
||||
scanButton.Margin = new Thickness(20, 45, 20, 10);
|
||||
addButton.Margin = new Thickness(20, 45, 20, 10);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
addButton.Source = ImageSource.FromFile("add");
|
||||
scanButton.Source = ImageSource.FromFile("scan");
|
||||
|
||||
lstView.BackgroundColor = Color.FromHex("4A4A4A");
|
||||
BackgroundColor = Color.FromHex("4A4A4A");
|
||||
var scanButtonGesture = new TapGestureRecognizer();
|
||||
|
||||
scanButtonGesture.Tapped += Scan;
|
||||
scanButton.GestureRecognizers.Add(scanButtonGesture);
|
||||
|
||||
|
||||
|
||||
var addButtonGesture = new TapGestureRecognizer();
|
||||
|
||||
addButtonGesture.Tapped += AddWorkspace;
|
||||
addButton.GestureRecognizers.Add(addButtonGesture);
|
||||
}
|
||||
|
||||
void AddWorkspace(object sender, EventArgs e){
|
||||
|
||||
UserDialogs.Instance.Prompt(new PromptConfig
|
||||
{
|
||||
Title = "Enter IP of QLab Computer",
|
||||
Message = "Enter an IP Address to save",
|
||||
OkText = "Next",
|
||||
OnTextChanged = args =>
|
||||
{
|
||||
//IPAddress ugh
|
||||
args.IsValid = IPHelper.IsValidAddress(args.Value);
|
||||
},
|
||||
OnAction = (qAddress) =>
|
||||
{
|
||||
if (!qAddress.Ok)
|
||||
return;
|
||||
|
||||
UserDialogs.Instance.Prompt(new PromptConfig
|
||||
{
|
||||
Title="Enter Name",
|
||||
Message = "Enter a Name for " + qAddress.Text,
|
||||
OkText="Save",
|
||||
OnAction = (qName) => {
|
||||
if (!qName.Ok)
|
||||
return;
|
||||
QStorage.AddInstance(qName.Text,qAddress.Text);
|
||||
showToast("Manual Workspace Added!");
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void showToast(string message){
|
||||
var toastConfig = new ToastConfig(message);
|
||||
toastConfig.SetDuration(3000);
|
||||
toastConfig.SetPosition(ToastPosition.Bottom);
|
||||
UserDialogs.Instance.Toast(toastConfig);
|
||||
}
|
||||
|
||||
async void Scan(object sender, EventArgs e){
|
||||
bool workspacesFound = false;
|
||||
showToast("Scanning for Workspaces...");
|
||||
|
||||
|
||||
Console.WriteLine("Begin Scanning");
|
||||
IReadOnlyList<IZeroconfHost> results = await ZeroconfResolver.ResolveAsync("_qlab._udp.local.",TimeSpan.FromSeconds(3));
|
||||
if(results != null){
|
||||
foreach (var result in results)
|
||||
{
|
||||
if (result != null)
|
||||
{
|
||||
QStorage.AddInstance(result.DisplayName, result.IPAddress);
|
||||
Console.WriteLine(result.DisplayName + " @ " + result.IPAddress + " added");
|
||||
workspacesFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(workspacesFound){
|
||||
showToast("Workspace Found and Added!");
|
||||
}else{
|
||||
showToast("No Workspaces Found!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user