-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #511 from SainsburyWellcomeCentre/social-dev
Add video stream selector to main control panel
- Loading branch information
Showing
8 changed files
with
420 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using Bonsai; | ||
using System; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Reactive.Linq; | ||
using System.Collections.ObjectModel; | ||
using Bonsai.Expressions; | ||
|
||
[Combinator] | ||
[Description("Selects a specific stream by name from a set of input streams.")] | ||
[WorkflowElementCategory(ElementCategory.Combinator)] | ||
[DefaultProperty("StreamNames")] | ||
public class StreamSelector | ||
{ | ||
readonly Collection<string> streamNames = new Collection<string>(); | ||
|
||
[TypeConverter(typeof(SelectedStreamConverter))] | ||
public string SelectedStream { get; set; } | ||
|
||
public Collection<string> StreamNames | ||
{ | ||
get { return streamNames; } | ||
} | ||
|
||
public IObservable<TSource> Process<TSource>(params IObservable<TSource>[] source) | ||
{ | ||
var filteredStreams = new IObservable<TSource>[source.Length]; | ||
for (int i = 0; i < source.Length; i++) | ||
{ | ||
var name = i < streamNames.Count ? streamNames[i] : string.Empty; | ||
filteredStreams[i] = source[i].Where(_ => name == SelectedStream); | ||
} | ||
|
||
return Observable.Merge(filteredStreams); | ||
} | ||
|
||
class SelectedStreamConverter : StringConverter | ||
{ | ||
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) | ||
{ | ||
return true; | ||
} | ||
|
||
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) | ||
{ | ||
StreamSelector selector = null; | ||
var workflowBuilder = (WorkflowBuilder)context.GetService(typeof(WorkflowBuilder)); | ||
var descendants = workflowBuilder.Workflow.Descendants(); | ||
foreach (var node in descendants) | ||
{ | ||
selector = ExpressionBuilder.GetWorkflowElement(node) as StreamSelector; | ||
if (selector != null) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
return new StandardValuesCollection(selector.StreamNames); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.