sl@4: using System; sl@4: using System.Collections.Generic; sl@4: using System.Linq; sl@4: using System.Text; sl@4: using System.Threading.Tasks; sl@4: using System.Runtime.InteropServices; sl@4: sl@4: namespace iMON sl@4: { sl@4: class Display sl@4: { sl@4: public string StatusMessage { get; set; } sl@4: public DSPType Type { get; set; } sl@4: public bool IsLcd() { return Type == DSPType.DSPN_DSP_LCD; } sl@4: public bool IsVfd() { return Type == DSPType.DSPN_DSP_VFD; } sl@4: public string Name() sl@4: { sl@4: if (Type == DSPType.DSPN_DSP_VFD) sl@4: { sl@4: return "SoundGraph iMON VFD"; sl@4: } sl@4: else if (Type == DSPType.DSPN_DSP_LCD) sl@4: { sl@4: return "SoundGraph iMON LCD"; sl@4: } sl@4: else //(DisplayType == DSPType.DSPN_DSP_NONE) sl@4: { sl@4: return "No display"; sl@4: } sl@4: } sl@4: sl@4: /// sl@4: /// Do display initialization. sl@4: /// Returns true on success sl@4: /// sl@4: public bool DoInit() sl@4: { sl@4: IDW_INITRESULT initResult = new IDW_INITRESULT(); sl@4: DSPResult ret = IDW_Init(initResult); sl@4: //Check the API call worked sl@4: if (ret != DSPResult.DSP_SUCCEEDED) sl@4: { sl@4: StatusMessage = DSPResult2String(ret); sl@4: return false; sl@4: } sl@4: //Check that the initialization was carried out properly sl@4: else if (initResult.iInitResult != DSPNInitResult.DSPN_SUCCEEDED) sl@4: { sl@4: StatusMessage = DSPNResult2String(initResult.iInitResult); sl@4: return false; sl@4: } sl@4: //Check we that we have a display sl@4: else if (initResult.iDspType == DSPType.DSPN_DSP_NONE) sl@4: { sl@4: StatusMessage = "Unsupported device"; sl@4: return false; sl@4: } sl@4: sl@4: Type = initResult.iDspType; sl@4: return true; sl@4: } sl@4: sl@4: /// sl@4: /// Do display de-initialization. sl@4: /// Returns true on success sl@4: /// sl@4: public void DoUninit() sl@4: { sl@4: Type = DSPType.DSPN_DSP_NONE; sl@4: IDW_Uninit(); sl@4: } sl@4: sl@4: sl@4: /// sl@4: /// Provide a string corresponding to the given DSPResult. sl@4: /// sl@4: protected string DSPResult2String(DSPResult result) sl@4: { sl@4: switch (result) sl@4: { sl@4: case DSPResult.DSP_SUCCEEDED: sl@4: return "Success"; sl@4: case DSPResult.DSP_E_FAIL: sl@4: return "An unknown error occurred"; sl@4: case DSPResult.DSP_E_OUTOFMEMORY: sl@4: return "Out of memory"; sl@4: case DSPResult.DSP_E_INVALIDARG: sl@4: return "One or more arguments are invalid"; sl@4: case DSPResult.DSP_E_NOT_INITED: sl@4: return "API is not initialized"; sl@4: case DSPResult.DSP_E_POINTER: sl@4: return "Pointer is invalid"; sl@4: default: sl@4: return "An unknown error occurred"; sl@4: } sl@4: } sl@4: sl@4: /// sl@4: /// Provide a string corresponding to the given DSPNInitResult. sl@4: /// sl@4: protected string DSPNResult2String(DSPNInitResult result) sl@4: { sl@4: switch (result) sl@4: { sl@4: case DSPNInitResult.DSPN_SUCCEEDED: sl@4: return "Success"; sl@4: case DSPNInitResult.DSPN_ERR_IN_USE: sl@4: return "Display plug-in is already used by another application"; sl@4: case DSPNInitResult.DSPN_ERR_HW_DISCONNECTED: sl@4: return "iMON hardware is not connected"; sl@4: case DSPNInitResult.DSPN_ERR_NOT_SUPPORTED_HW: sl@4: return "The connected hardware does not support the plug-in mode"; sl@4: case DSPNInitResult.DSPN_ERR_PLUGIN_DISABLED: sl@4: return "The plug-in mode option is disabled"; sl@4: case DSPNInitResult.DSPN_ERR_IMON_NO_REPLY: sl@4: return "The latest iMON is not installed or iMON is not running"; sl@4: default: sl@4: return "An unknown error occurred"; sl@4: } sl@4: } sl@4: sl@4: //Possible return values from iMON Display APIs sl@4: public enum DSPResult : int sl@4: { sl@4: DSP_SUCCEEDED = 0, sl@4: DSP_E_FAIL = 1, sl@4: DSP_E_OUTOFMEMORY = 2, sl@4: DSP_E_INVALIDARG = 3, sl@4: DSP_E_NOT_INITED = 4, sl@4: DSP_E_POINTER = 5, sl@4: DSP_S_INITED = 0x1000, sl@4: DSP_S_NOT_INITED = 0x1001, sl@4: DSP_S_IN_PLUGIN_MODE = 0x1002, sl@4: DSP_S_NOT_IN_PLUGIN_MODE = 0x1003 sl@4: } sl@4: sl@4: //Possible results from display initialization sl@4: public enum DSPNInitResult : int sl@4: { sl@4: DSPN_SUCCEEDED = 0, sl@4: DSPN_ERR_IN_USE = 0x0100, sl@4: DSPN_ERR_HW_DISCONNECTED = 0x0101, sl@4: DSPN_ERR_NOT_SUPPORTED_HW = 0x0102, sl@4: DSPN_ERR_PLUGIN_DISABLED = 0x0103, sl@4: DSPN_ERR_IMON_NO_REPLY = 0x0104, sl@4: DSPN_ERR_UNKNOWN = 0x0200 sl@4: } sl@4: sl@4: //Type of display sl@4: public enum DSPType : int sl@4: { sl@4: DSPN_DSP_NONE = 0, sl@4: DSPN_DSP_VFD = 0x01, sl@4: DSPN_DSP_LCD = 0x02 sl@4: }; sl@4: sl@4: //Notification code sl@4: public enum DSPNotifyCode : int sl@4: { sl@4: DSPNM_PLUGIN_SUCCEED = 0, sl@4: DSPNM_PLUGIN_FAILED, sl@4: DSPNM_IMON_RESTARTED, sl@4: DSPNM_IMON_CLOSED, sl@4: DSPNM_HW_CONNECTED, sl@4: DSPNM_HW_DISCONNECTED, sl@4: DSPNM_LCD_TEXT_SCROLL_DONE = 0x1000 sl@4: }; sl@4: sl@4: [Flags] sl@4: public enum OrangeDiskPieces : byte sl@4: { sl@4: Piece1 = 0x80, // top piece sl@4: Piece2 = 0x40, // next piece counter-clockwise sl@4: Piece3 = 0x20, // and so on... sl@4: Piece4 = 0x10, sl@4: Piece5 = 0x8, sl@4: Piece6 = 0x4, sl@4: Piece7 = 0x2, sl@4: Piece8 = 0x1, sl@4: None = 0x0 sl@4: } sl@4: sl@4: public enum OrangeDiskIcon : byte sl@4: { sl@4: On = 0x80, sl@4: Off = 0x0 sl@4: } sl@4: sl@4: [Flags] sl@4: public enum MediaTypes : byte sl@4: { sl@4: Music = 0x80, sl@4: Movie = 0x40, sl@4: Photo = 0x20, sl@4: Cd_Dvd = 0x10, sl@4: Tv = 0x8, sl@4: WebCasting = 0x4, sl@4: News_Weather = 0x2, sl@4: None = 0x0 sl@4: } sl@4: sl@4: [Flags] sl@4: public enum Speakers : byte sl@4: { sl@4: L = 0x80, sl@4: C = 0x40, sl@4: R = 0x20, sl@4: SL = 0x10, sl@4: LFE = 0x8, sl@4: SR = 0x4, sl@4: RL = 0x2, sl@4: SPDIF = 0x1, sl@4: None = 0x0 sl@4: } sl@4: sl@4: public enum SpeakersRR : byte sl@4: { sl@4: RR = 0x80, sl@4: Off = 0x0 sl@4: } sl@4: sl@4: [Flags] sl@4: public enum VideoCodecs : byte sl@4: { sl@4: MPG = 0x80, sl@4: DIVX = 0x40, sl@4: XVID = 0x20, sl@4: WMV = 0x10, sl@4: MPG2 = 0x8, sl@4: AC3 = 0x4, sl@4: DTS = 0x2, sl@4: WMA = 0x1, sl@4: None = 0x0 sl@4: } sl@4: sl@4: [Flags] sl@4: public enum AudioCodecs : byte sl@4: { sl@4: MP3 = 0x80, sl@4: OGG = 0x40, sl@4: WMA = 0x20, sl@4: WAV = 0x10, sl@4: None = 0x0 sl@4: } sl@4: sl@4: [Flags] sl@4: public enum AspectRatios : byte sl@4: { sl@4: SRC = 0x80, sl@4: FIT = 0x40, sl@4: TV = 0x20, sl@4: HDTV = 0x10, sl@4: SCR1 = 0x8, sl@4: SCR2 = 0x4, sl@4: None = 0x0 sl@4: } sl@4: sl@4: [Flags] sl@4: public enum EtcIcons : byte sl@4: { sl@4: Repeat = 0x80, sl@4: Shuffle = 0x40, sl@4: Alarm = 0x20, sl@4: Recording = 0x10, sl@4: Volume = 0x8, sl@4: Time = 0x4, sl@4: None = 0x0 sl@4: } sl@4: sl@4: //Provide results from our iMON Display initialization sl@4: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 8)] sl@4: protected class IDW_INITRESULT sl@4: { sl@4: [MarshalAs(UnmanagedType.U4)] sl@4: public DSPNotifyCode iNotification; sl@4: [MarshalAs(UnmanagedType.U4)] sl@4: public DSPNInitResult iInitResult; sl@4: [MarshalAs(UnmanagedType.U4)] sl@4: public DSPType iDspType; sl@4: } sl@4: sl@4: //Provide result for our status query sl@4: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 8)] sl@4: protected class IDW_STATUS sl@4: { sl@4: [MarshalAs(UnmanagedType.U4)] sl@4: public DSPNotifyCode iNotification; sl@4: } sl@4: sl@4: //Declare a struct to pass our EqData sl@4: [StructLayout(LayoutKind.Sequential)] sl@4: public class DSPEQDATA sl@4: { sl@4: public DSPEQDATA() sl@4: { sl@4: BandData = new int[16]; sl@4: } sl@4: sl@4: [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] sl@4: public readonly int[] BandData; sl@4: } sl@4: sl@4: [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: protected static extern DSPResult IDW_Init(IDW_INITRESULT initResult); sl@4: sl@4: [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: protected static extern DSPResult IDW_Uninit(); sl@4: sl@4: [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: protected static extern DSPResult IDW_IsInitialized(); sl@4: sl@4: [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: protected static extern DSPResult IDW_GetStatus(IDW_STATUS status); sl@4: sl@4: [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: public static extern DSPResult IDW_SetVfdText([MarshalAs(UnmanagedType.LPWStr)] string line1, [MarshalAs(UnmanagedType.LPWStr)] string line2); sl@4: sl@4: //Import function to set VFD EQDATA sl@4: [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: public static extern int IDW_SetVfdEqData(DSPEQDATA EqData); sl@4: sl@4: //Import function to set LCD EQDATA sl@4: [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: public static extern int IDW_SetLcdEqData(DSPEQDATA EqDataLeft, DSPEQDATA EqDataRight); sl@4: sl@4: [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: public static extern DSPResult IDW_SetLcdText([MarshalAs(UnmanagedType.LPWStr)] string line); sl@4: sl@4: [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: public static extern DSPResult IDW_SetLcdAllIcons([MarshalAs(UnmanagedType.Bool)] bool on); sl@4: sl@4: [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: public static extern DSPResult IDW_SetLcdOrangeIcon(byte iconData1, byte iconData2); sl@4: sl@4: [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: public static extern DSPResult IDW_SetLcdMediaTypeIcon(byte iconData); sl@4: sl@4: [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: public static extern DSPResult IDW_SetLcdSpeakerIcon(byte iconData1, byte iconData2); sl@4: sl@4: [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: public static extern DSPResult IDW_SetLcdVideoCodecIcon(byte iconData); sl@4: sl@4: [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: public static extern DSPResult IDW_SetLcdAudioCodecIcon(byte iconData); sl@4: sl@4: [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: public static extern DSPResult IDW_SetLcdAspectRatioIcon(byte iconData); sl@4: sl@4: [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: public static extern DSPResult IDW_SetLcdEtcIcon(byte iconData); sl@4: sl@4: [DllImport("iMONDisplayWrapper.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: public static extern DSPResult IDW_SetLcdProgress(int currentPosition, int total); sl@4: sl@4: sl@4: } sl@4: }