Skip to content

Commit

Permalink
Make OscMaster class public
Browse files Browse the repository at this point in the history
  • Loading branch information
keijiro committed Jul 22, 2018
1 parent 706aecc commit 4e9d34f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,11 @@

namespace OscJack
{
internal static class OscMaster
public static class OscMaster
{
#region Mapping objects

// OSC server map (key = port number)
static Dictionary<int, OscServer> _servers = new Dictionary<int, OscServer>();

// OSC client map (key = IP address + port number)
static Dictionary<string, OscClient> _clients = new Dictionary<string, OscClient>();

#endregion

#region Client key generator

static StringBuilder _stringBuilder = new StringBuilder();

static string GetClientKey(string ipAddress, int port)
{
_stringBuilder.Length = 0;
_stringBuilder.Append(ipAddress).Append(port);
return _stringBuilder.ToString();
}

#endregion

#region Public methods

public static OscServer GetServer(int port)
public static OscServer GetSharedServer(int port)
{
OscServer server;
if (!_servers.TryGetValue(port, out server))
Expand All @@ -44,7 +21,7 @@ public static OscServer GetServer(int port)
return server;
}

public static OscClient GetClient(string ipAddress, int port)
public static OscClient GetSharedClient(string ipAddress, int port)
{
var key = GetClientKey(ipAddress, port);
OscClient client;
Expand All @@ -57,5 +34,28 @@ public static OscClient GetClient(string ipAddress, int port)
}

#endregion

#region Mapping objects

// OSC server map (key = port number)
static Dictionary<int, OscServer> _servers = new Dictionary<int, OscServer>();

// OSC client map (key = IP address + port number)
static Dictionary<string, OscClient> _clients = new Dictionary<string, OscClient>();

#endregion

#region Client key generator

static StringBuilder _stringBuilder = new StringBuilder();

static string GetClientKey(string ipAddress, int port)
{
_stringBuilder.Length = 0;
_stringBuilder.Append(ipAddress).Append(':').Append(port);
return _stringBuilder.ToString();
}

#endregion
}
}
4 changes: 2 additions & 2 deletions Assets/OscJack/Runtime/Unity/OscEventReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void OnEnable()
return;
}

var server = OscMaster.GetServer(_udpPort);
var server = OscMaster.GetSharedServer(_udpPort);
server.MessageDispatcher.AddCallback(_oscAddress, OnDataReceive);

_currentPort = _udpPort;
Expand Down Expand Up @@ -166,7 +166,7 @@ void OnDisable()
{
if (string.IsNullOrEmpty(_currentAddress)) return;

var server = OscMaster.GetServer(_currentPort);
var server = OscMaster.GetSharedServer(_currentPort);
server.MessageDispatcher.RemoveCallback(_currentAddress, OnDataReceive);

_currentAddress = null;
Expand Down
2 changes: 1 addition & 1 deletion Assets/OscJack/Runtime/Unity/OscPropertySender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed class OscPropertySender : MonoBehaviour

void UpdateSettings()
{
_client = OscMaster.GetClient(_ipAddress, _udpPort);
_client = OscMaster.GetSharedClient(_ipAddress, _udpPort);

if (_dataSource != null && !string.IsNullOrEmpty(_propertyName))
_propertyInfo = _dataSource.GetType().GetProperty(_propertyName);
Expand Down

0 comments on commit 4e9d34f

Please sign in to comment.