2014-08-17 16:00:46 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using BizHawk.Emulation.Common;
|
2014-08-17 15:22:02 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.Client.Common
|
2013-10-25 00:59:34 +00:00
|
|
|
|
{
|
2014-08-17 15:04:23 +00:00
|
|
|
|
public class MultitrackRecorder
|
2013-10-25 00:59:34 +00:00
|
|
|
|
{
|
2014-08-17 15:11:04 +00:00
|
|
|
|
public MultitrackRecorder()
|
|
|
|
|
{
|
|
|
|
|
Restart();
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-28 01:06:51 +00:00
|
|
|
|
public bool IsActive { get; set; }
|
2014-08-03 20:34:45 +00:00
|
|
|
|
public int CurrentPlayer{ get; set; }
|
2013-10-28 01:06:51 +00:00
|
|
|
|
public bool RecordAll { get; set; }
|
2014-06-29 23:13:44 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A user friendly multitrack status
|
|
|
|
|
/// </summary>
|
2014-08-17 15:04:23 +00:00
|
|
|
|
public string Status
|
2014-08-03 20:34:45 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!IsActive)
|
|
|
|
|
{
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (RecordAll)
|
|
|
|
|
{
|
|
|
|
|
return "Recording All";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CurrentPlayer == 0)
|
|
|
|
|
{
|
|
|
|
|
return "Recording None";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "Recording Player " + CurrentPlayer;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-29 23:13:44 +00:00
|
|
|
|
|
2014-08-17 15:04:23 +00:00
|
|
|
|
public void Restart()
|
|
|
|
|
{
|
|
|
|
|
IsActive = false;
|
|
|
|
|
CurrentPlayer = 0;
|
|
|
|
|
RecordAll = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 23:13:44 +00:00
|
|
|
|
public void SelectAll()
|
|
|
|
|
{
|
|
|
|
|
CurrentPlayer = 0;
|
|
|
|
|
RecordAll = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SelectNone()
|
|
|
|
|
{
|
|
|
|
|
RecordAll = false;
|
|
|
|
|
CurrentPlayer = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Increment()
|
|
|
|
|
{
|
|
|
|
|
RecordAll = false;
|
|
|
|
|
CurrentPlayer++;
|
|
|
|
|
if (CurrentPlayer > Global.Emulator.ControllerDefinition.PlayerCount)
|
|
|
|
|
{
|
|
|
|
|
CurrentPlayer = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Decrement()
|
|
|
|
|
{
|
|
|
|
|
RecordAll = false;
|
|
|
|
|
CurrentPlayer--;
|
|
|
|
|
if (CurrentPlayer < 1)
|
|
|
|
|
{
|
|
|
|
|
CurrentPlayer = Global.Emulator.ControllerDefinition.PlayerCount;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-25 00:59:34 +00:00
|
|
|
|
}
|
2014-08-17 15:22:02 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// rewires player1 controls to playerN
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class MultitrackRewiringControllerAdapter : IController
|
|
|
|
|
{
|
2014-08-17 15:45:04 +00:00
|
|
|
|
public MultitrackRewiringControllerAdapter()
|
|
|
|
|
{
|
|
|
|
|
PlayerSource = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 15:22:02 +00:00
|
|
|
|
public IController Source { get; set; }
|
2014-08-17 15:45:04 +00:00
|
|
|
|
public int PlayerSource { get; set; }
|
|
|
|
|
public int PlayerTargetMask { get; set; }
|
2014-08-17 15:22:02 +00:00
|
|
|
|
|
|
|
|
|
public ControllerDefinition Type { get { return Source.Type; } }
|
|
|
|
|
|
2014-08-17 15:45:04 +00:00
|
|
|
|
public bool this[string button]
|
|
|
|
|
{
|
|
|
|
|
get { return IsPressed(button); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsPressed(string button)
|
|
|
|
|
{
|
|
|
|
|
return Source.IsPressed(RemapButtonName(button));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float GetFloat(string button)
|
|
|
|
|
{
|
|
|
|
|
return Source.GetFloat(RemapButtonName(button));
|
|
|
|
|
}
|
2014-08-17 15:22:02 +00:00
|
|
|
|
|
|
|
|
|
private string RemapButtonName(string button)
|
|
|
|
|
{
|
|
|
|
|
// Do we even have a source?
|
|
|
|
|
if (PlayerSource == -1)
|
|
|
|
|
{
|
|
|
|
|
return button;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// See if we're being asked for a button that we know how to rewire
|
|
|
|
|
var bnp = ButtonNameParser.Parse(button);
|
|
|
|
|
|
|
|
|
|
if (bnp == null)
|
|
|
|
|
{
|
|
|
|
|
return button;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ok, this looks like a normal `P1 Button` type thing. we can handle it
|
|
|
|
|
// Were we supposed to replace this one?
|
|
|
|
|
int foundPlayerMask = (1 << bnp.PlayerNum);
|
|
|
|
|
if ((PlayerTargetMask & foundPlayerMask) == 0)
|
|
|
|
|
{
|
|
|
|
|
return button;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ok, we were. swap out the source player and then grab his button
|
|
|
|
|
bnp.PlayerNum = PlayerSource;
|
|
|
|
|
return bnp.ToString();
|
|
|
|
|
}
|
2014-08-17 15:45:04 +00:00
|
|
|
|
}
|
2014-08-17 15:22:02 +00:00
|
|
|
|
|
2014-08-17 15:45:04 +00:00
|
|
|
|
public class ButtonNameParser
|
|
|
|
|
{
|
|
|
|
|
public static ButtonNameParser Parse(string button)
|
2014-08-17 15:22:02 +00:00
|
|
|
|
{
|
2014-08-17 15:45:04 +00:00
|
|
|
|
// See if we're being asked for a button that we know how to rewire
|
|
|
|
|
var parts = button.Split(' ');
|
|
|
|
|
|
|
|
|
|
if (parts.Length < 2)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parts[0][0] != 'P')
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int player;
|
|
|
|
|
if (!int.TryParse(parts[0].Substring(1), out player))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new ButtonNameParser
|
|
|
|
|
{
|
|
|
|
|
PlayerNum = player,
|
|
|
|
|
ButtonPart = button.Substring(parts[0].Length + 1)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int PlayerNum { get; set; }
|
|
|
|
|
public string ButtonPart { get; private set; }
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return string.Format("P{0} {1}", PlayerNum, ButtonPart);
|
2014-08-17 15:22:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-25 00:59:34 +00:00
|
|
|
|
}
|