33using System ;
44using System . Collections . Generic ;
55using System . IO ;
6+ using System . Linq ;
67using UI24RController ;
78using UI24RController . MIDIController ;
89
@@ -26,7 +27,7 @@ static void Main(string[] args)
2627 var controllersSetting = new List < UI24RController . ControllerSettings > ( ) ;
2728 configuration . GetSection ( "MidiControllers" ) . Bind ( controllersSetting ) ;
2829
29-
30+
3031 var address = configuration [ "UI24R-Url" ] ;
3132 var midiInputDevice = configuration [ "MIDI-Input-Name" ] ;
3233 var midiOutputDevice = configuration [ "MIDI-Output-Name" ] ;
@@ -55,7 +56,7 @@ static void Main(string[] args)
5556 {
5657 controllerSecond = MIDIControllerFactory . GetMidiController ( protocol ) ;
5758 }
58-
59+
5960 if ( args . Length > 0 )
6061 WriteMIDIDeviceNames ( controller ) ;
6162 else
@@ -156,7 +157,7 @@ static void Main(string[] args)
156157 Console . WriteLine ( "Start bridge..." ) ;
157158
158159 BridgeSettings settings = new BridgeSettings ( address , messageWriter ) ;
159-
160+
160161 if ( syncID != null )
161162 {
162163 settings . SyncID = syncID ;
@@ -251,27 +252,42 @@ static void Main(string[] args)
251252 }
252253 }
253254 }
254-
255+
255256 }
256257 }
257258 }
259+ private static string PromptDeviceChoice ( string promptText , IEnumerable < string > deviceNames )
260+ {
261+ var nameList = deviceNames . ToList ( ) ;
262+
263+ AnsiConsole . WriteLine ( promptText ) ;
264+ for ( int i = 0 ; i < nameList . Count ; i ++ )
265+ AnsiConsole . MarkupLine ( $ " [blue][[{ i + 1 } ]][/]: { nameList [ i ] } ") ;
266+
267+ int chosen = AnsiConsole . Prompt (
268+ new TextPrompt < int > ( "Enter number:" )
269+ . DefaultValue ( 1 )
270+ . Validate ( n => n >= 1 && n <= nameList . Count
271+ ? ValidationResult . Success ( )
272+ : ValidationResult . Error ( $ "Please enter a number between 1 and { nameList . Count } ") ) ) ;
273+
274+ return nameList [ chosen - 1 ] ;
275+ }
258276
259277 private static void CreateAppsettings ( string fileName )
260278 {
261279 var controller = MIDIControllerFactory . GetMidiController ( "MC" ) ;
262280 var inputDevicenames = controller . GetInputDeviceNames ( ) ;
263281 var outputDevicenames = controller . GetOutputDeviceNames ( ) ;
264-
282+
265283 AnsiConsole . WriteLine ( "appsettings.json is not found." ) ;
266284 AnsiConsole . WriteLine ( "Creating of the configuration file is starting." ) ;
267285 var address = AnsiConsole . Ask < string > ( @"Please write the mixer address (eg: ws:\\192.168.3.12): " ) ; //"UI24R-Url"
268- var midiInputDevice = AnsiConsole . Prompt (
269- new TextPrompt < string > ( "Choose primary input device. (It is case sensitive.)" )
270- . AddChoices ( inputDevicenames ) ) ; //configuration["MIDI-Input-Name"];
286+ var midiInputDevice = PromptDeviceChoice (
287+ "Choose primary input device:" , inputDevicenames ) ; //configuration["MIDI-Input-Name"];
271288
272- var midiOutputDevice = AnsiConsole . Prompt (
273- new TextPrompt < string > ( "Choose primary output device. (It is case sensitive.)" )
274- . AddChoices ( outputDevicenames ) ) ; //configuration["MIDI-Output-Name"];
289+ var midiOutputDevice = PromptDeviceChoice (
290+ "Choose primary output device:" , outputDevicenames ) ; //configuration["MIDI-Output-Name"];
275291
276292 //var primaryIsExtender = configuration["PrimaryIsExtender"] == "true";
277293 string primaryIsExtender = "false" ;
@@ -290,7 +306,7 @@ private static void CreateAppsettings(string fileName)
290306 new TextPrompt < string > ( "Primary controller offset (show 1-8ch: 0 9-16ch: 1" )
291307 . AddChoices ( [ "0" , "1" ] )
292308 . DefaultValue ( "0" ) ) ;
293-
309+
294310 var isAddSecondaryDevice = AnsiConsole . Prompt (
295311 new TextPrompt < bool > ( "Do you want to add secondary device?" )
296312 . AddChoice ( true )
@@ -304,17 +320,15 @@ private static void CreateAppsettings(string fileName)
304320 string secondaryIsExtender = "false" ;
305321 string secondaryChannelStart = "1" ;
306322 //var secondaryMidiInputDevice = configuration["MIDI-Input-Name-Second"];
307- //var secondaryMidiOutputDevice = configuration["MIDI-Output-Name-Second"];
323+ //var secondaryMidiOutputDevice = configuration["MIDI-Output-Name-Second"];
308324 //var secondaryIsExtender = configuration["SecondaryIsExtender"] == "true";
309325 if ( isAddSecondaryDevice )
310326 {
311- secondaryMidiInputDevice = AnsiConsole . Prompt (
312- new TextPrompt < string > ( "Choose secondary input device. (It is case sensitive.)" )
313- . AddChoices ( inputDevicenames ) ) ; //configuration["MIDI-Input-Name"];
327+ secondaryMidiInputDevice = PromptDeviceChoice (
328+ "Choose secondary input device:" , inputDevicenames ) ; //configuration["MIDI-Input-Name"];
314329
315- secondaryMidiOutputDevice = AnsiConsole . Prompt (
316- new TextPrompt < string > ( "Choose secondary output device. (It is case sensitive.)" )
317- . AddChoices ( outputDevicenames ) ) ; //configuration["MIDI-Output-Name"];
330+ secondaryMidiOutputDevice = PromptDeviceChoice (
331+ "Choose secondary output device:" , outputDevicenames ) ; //configuration["MIDI-Output-Name"];
318332
319333 if ( AnsiConsole . Prompt (
320334 new TextPrompt < bool > ( "Is secondary device an extender?" )
@@ -370,7 +384,7 @@ private static void CreateAppsettings(string fileName)
370384" ;
371385
372386 File . WriteAllText ( fileName , settingsContent ) ;
373-
387+
374388
375389 }
376390
0 commit comments