Ejemplo n.º 1
0
        public override void Run()
        {
            // We will come here once per millisecond to see if we have some USB incoming.
            // USB reads are initiated here, and if one is pending, we must not initiate a new one.
            // We buffer and analyze incoming data and asseble the MIDI messages.
            // Each complete message is used in a call to MidiInport_MessageReceived.
            //if (buffer[1] == 0xf0 && buffer[9] == 0x11) // Note: Offsets from MIDI SysEx standard due to embedded USB codes.
            USB usb = (USB)MainPage_Portable.platform_specific[0];

            if (usb != null && usb.InputEndpoint != null && usb.DeviceConnection != null)
            {
                // See if there is some data:
                byte[] inputBuffer = new byte[64];
                Int32  count;
                count = usb.DeviceConnection.BulkTransfer(usb.InputEndpoint, inputBuffer, 64, 5000);

                // Handle data if it was expected:
                if (count > 0 && MainPage_Portable.uIHandler.queryType != UIHandler.QueryType.NONE)
                {
                    collectionBuffer = AddBuffer(inputBuffer, count);

                    // Did we get the full message?
                    // Last 4 bytes starts with a USB code with value = 5, 6 or 7 rather than 4:
                    if (collectionBuffer[collectionBuffer.Length - 4] != 0x04)
                    {
                        rawData          = RemoveUsbCodes(collectionBuffer);
                        collectionBuffer = null;
                        MidiInPort_MessageReceived(rawData);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void UsbTransmit(byte[] buffer)
        {
            USB usb = (USB)MainPage_Portable.platform_specific[0];

            if (usb != null && usb.HasPermission)
            {
                {
                    usb.DeviceConnection.BulkTransfer(usb.OutputEndpoint, buffer, buffer.Length, 5000);
                }
            }
        }
        private void Init()
        {
            Xamarin.Forms.DependencyService.Register <IMidi>();

            // Get Integra7Random_Xamarin.MainPage:
            MainPage_Portable = Integra7Random_Xamarin.MainPage.GetMainPage();
            UIHandler.appType = UIHandler._appType.ANDROID;

            // Make Portable project draw UI and get the Pickers for Midi output device:
            MainPage_Portable.uIHandler.ShowLibrarianPage();
            OutputSelector = MainPage_Portable.uIHandler.Librarian_midiOutputDevice;
            InputSelector  = MainPage_Portable.uIHandler.Librarian_midiInputDevice;

            // Let the portable project know this MainActivity:
            mainActivity = this;
            MainPage_Portable.SetDeviceSpecificMainPage(this);

            // Get and initiate USB:
            UsbManager usbManager = (UsbManager)GetSystemService(Context.UsbService);

            usb = new USB(usbManager, this);

            // Hook up USB :
            pendingIntent = PendingIntent.GetBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
            IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);

            filter.AddAction(USB_DEVICE_ATTACHED);
            filter.AddAction(USB_DEVICE_DETACHED);
            RegisterReceiver(usb, filter);

            // Ask user for permission to use USB if creation and initiation was successful:
            if (usb.Device != null && usb.Interface != null && usb.OutputEndpoint != null && usb.InputEndpoint != null)
            {
                usb.Manager.RequestPermission(usb.Device, pendingIntent);
                usb.HasPermission = usb.Manager.HasPermission(usb.Device);
            }

            // Initiate MIDI:
            MainPage_Portable.uIHandler.commonState.midi.Init(MainPage_Portable, "INTEGRA-7", OutputSelector, InputSelector, this, 0, 0);

            // Let the portable project access our USB:
            MainPage_Portable.platform_specific = new object[] { usb };

            //MainPage_Portable.uIHandler.ScanForStudioSetNames();
            //Android.Views.View view = this.SetContentView()
            //mainActivity.Touch
            //OnTouchListener +=
            //Android.Views.View view = FindViewById(Resource.Id.sliding_tabs);
            //view.SetOnTouchListener(this);

            //SetOnListener(this);
            //mainActivity. SetOnTouchListener()

            // Show the librarian at startup:
            MainPage_Portable.uIHandler.ShowLibrarianPage();

            //TapGestureRecognizer tapGestureRecognizer = new TapGestureRecognizer();
            //tapGestureRecognizer.Tapped += (sender, e) => OnTouch((Android.Views.View)sender, (TappedEventArgs)e);
            //MainPage_Portable.uIHandler.Librarian_Keyboard.GestureRecognizers.Add(tapGestureRecognizer);

            //PanGestureRecognizer panGestureRecognizer = new PanGestureRecognizer();
            ////panGestureRecognizer.PanUpdated += panGestureRecognizer_PanUpdated;
            //MainPage_Portable.uIHandler.Librarian_Keyboard.GestureRecognizers.Add(panGestureRecognizer);


            //Image image = (Xamarin.Forms.Image)MainPage_Portable.uIHandler.Librarian_Keyboard. On<Xamarin.Forms.Image>();
        }
Ejemplo n.º 4
0
        public Boolean MidiIsReady()
        {
            USB usb = (USB)MainPage_Portable.platform_specific[0];

            return(mainActivity != null && MainPage_Portable != null && usb != null && usb.HasPermission && usb.DeviceConnection != null);
        }