コード例 #1
0
ファイル: Sound.cs プロジェクト: konni-arcadia/MonoGame
		public Sound(string url, float volume, bool looping)
		{			
			var data = NSData.FromUrl(NSUrl.FromFilename(url));
			_audioPlayer = new NSSound(data);
			_audioPlayer.Volume = volume;
			_audioPlayer.Loops = looping;
		}
コード例 #2
0
        public Sound(byte[] audiodata, float volume, bool looping)
        {
            var data = NSData.FromArray(audiodata);

            _audioPlayer        = new NSSound(data);
            _audioPlayer.Volume = volume;
            _audioPlayer.Loops  = looping;
        }
コード例 #3
0
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            switch (index)
            {
            case 0:
                TextManager.SetTitle("Animation Events");
                TextManager.AddBulletAtLevel("SCNAnimationEvent", 0);
                TextManager.AddBulletAtLevel("Smooth transitions", 0);

                TextManager.AddCode("#var anEvent = #SCNAnimationEvent.Create# (0.2,  aBlock); \n"
                                    + "anAnimation.#AnimationEvents# = @[anEvent, anotherEvent];#");

                var path      = NSBundle.MainBundle.PathForResource("Sounds/bossaggro", "wav");
                var soundUrl  = NSUrl.FromFilename(path);
                var bossaggro = new NSSound(soundUrl, false);
                bossaggro.Play();
                break;

            case 1:
                // Trigger the attack animation
                HeroSkeletonNode.AddAnimation(Animations [(int)CharacterAnimation.Attack], new NSString("attack"));
                break;

            case 2:
                TextManager.FadeOutText(SlideTextManager.TextType.Code);
                TextManager.AddCode("#\n"
                                    + "\n"
                                    + "\n\n"
                                    + "anAnimation.FadeInDuration = #0.0#;\n"
                                    + "anAnimation.FadeOutDuration = #0.0#;#");
                break;

            case 3:
            case 4:
                Animations[(int)CharacterAnimation.Attack].FadeInDuration  = 0;
                Animations[(int)CharacterAnimation.Attack].FadeOutDuration = 0;
                // Trigger the attack animation
                HeroSkeletonNode.AddAnimation(Animations [(int)CharacterAnimation.Attack], new NSString("attack"));
                break;

            case 5:
                TextManager.FadeOutText(SlideTextManager.TextType.Code);
                TextManager.AddCode("#\n"
                                    + "\n"
                                    + "\n\n"
                                    + "anAnimation.FadeInDuration = #0.3#;\n"
                                    + "anAnimation.FadeOutDuration = #0.3#;#");
                break;

            case 6:
            case 7:
                Animations[(int)CharacterAnimation.Attack].FadeInDuration  = 0.3f;
                Animations[(int)CharacterAnimation.Attack].FadeOutDuration = 0.3f;
                // Trigger the attack animation
                HeroSkeletonNode.AddAnimation(Animations [(int)CharacterAnimation.Attack], new NSString("attack"));
                break;
            }
        }
コード例 #4
0
        public override void DidFinishPlaying(NSSound sound, bool finished)
        {
            EventHandler handler = DidComplete;

            if (null != handler)
            {
                handler(this, EventArgs.Empty);
            }
        }
コード例 #5
0
ファイル: GuiUtil.cs プロジェクト: xerohour/scsharp
        public static void PlaySound(Mpq mpq, string resourcePath)
        {
            Stream stream = (Stream)mpq.GetResource(resourcePath);

            if (stream == null)
            {
                return;
            }
            NSSound s = GuiUtil.SoundFromStream(stream);

            s.Play();
        }
コード例 #6
0
		public override void PresentStep (int index, PresentationViewController presentationViewController)
		{
			switch (index) {
			case 0:
				TextManager.SetTitle ("Animation Events");
				TextManager.AddBulletAtLevel ("SCNAnimationEvent", 0);
				TextManager.AddBulletAtLevel ("Smooth transitions", 0);

				TextManager.AddCode ("#var anEvent = #SCNAnimationEvent.Create# (0.2,  aBlock); \n"
				+ "anAnimation.#AnimationEvents# = @[anEvent, anotherEvent];#");

				var path = NSBundle.MainBundle.PathForResource ("Sounds/bossaggro", "wav");
				var soundUrl = NSUrl.FromFilename (path);
				var bossaggro = new NSSound (soundUrl, false);
				bossaggro.Play ();
				break;
			case 1:
				// Trigger the attack animation
				HeroSkeletonNode.AddAnimation (Animations [(int)CharacterAnimation.Attack], new NSString ("attack"));
				break;
			case 2:
				TextManager.FadeOutText (SlideTextManager.TextType.Code);
				TextManager.AddCode ("#\n"
				+ "\n"
				+ "\n\n"
				+ "anAnimation.FadeInDuration = #0.0#;\n"
				+ "anAnimation.FadeOutDuration = #0.0#;#");
				break;
			case 3:
			case 4:
				Animations[(int)CharacterAnimation.Attack].FadeInDuration = 0;
				Animations[(int)CharacterAnimation.Attack].FadeOutDuration = 0;
				// Trigger the attack animation
				HeroSkeletonNode.AddAnimation (Animations [(int)CharacterAnimation.Attack], new NSString ("attack"));
				break;
			case 5:
				TextManager.FadeOutText (SlideTextManager.TextType.Code);
				TextManager.AddCode ("#\n"
					+ "\n"
					+ "\n\n"
					+ "anAnimation.FadeInDuration = #0.3#;\n"
					+ "anAnimation.FadeOutDuration = #0.3#;#");
					break;
			case 6:
			case 7:
				Animations[(int)CharacterAnimation.Attack].FadeInDuration = 0.3f;
				Animations[(int)CharacterAnimation.Attack].FadeOutDuration = 0.3f;
				// Trigger the attack animation
				HeroSkeletonNode.AddAnimation (Animations [(int)CharacterAnimation.Attack], new NSString ("attack"));
				break;
			}
		}
コード例 #7
0
ファイル: GuiUtil.cs プロジェクト: xerohour/scsharp
        public static void PlayMusic(Mpq mpq, string resourcePath, int numLoops)
        {
            Stream stream = (Stream)mpq.GetResource(resourcePath);

            if (stream == null)
            {
                return;
            }
            NSSound s = GuiUtil.SoundFromStream(stream);

            s.Loops = true;;
            s.Play();
        }
コード例 #8
0
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            switch (index)
            {
            case 0:
                TextManager.SetTitle("Animation Events");
                TextManager.AddBulletAtLevel("SCNAnimationEvent", 0);

                TextManager.AddCode("#var anEvent = #SCNAnimationEvent.Create# (0.2,  aBlock); \n"
                                    + "anAnimation.#AnimationEvents# = @[anEvent, anotherEvent];#");

                // Warm up NSSound by playing an empty sound.
                // Otherwise the first sound may take some time to start playing and will be desynchronised.
                var path       = NSBundle.MainBundle.PathForResource("Sounds/emptySound", "m4a");
                var soundUrl   = NSUrl.FromFilename(path);
                var emptySound = new NSSound(soundUrl, false);
                emptySound.Play();
                break;

            case 1:
            case 2:
                // Trigger the attack animation
                HeroSkeletonNode.AddAnimation(Animations [(int)CharacterAnimation.Attack], new NSString("attack"));
                break;

            case 3:
                // Trigger the walk animation
                HeroSkeletonNode.AddAnimation(Animations [(int)CharacterAnimation.Walk], new NSString("walk"));
                break;

            case 4:
                // Trigger the death animation
                // Make sure to remove the "idle" animation and prevent the model from intersecting with the floor.

                HeroSkeletonNode.RemoveAllAnimations();
                HeroSkeletonNode.AddAnimation(Animations [(int)CharacterAnimation.Die], new NSString("death"));

                SCNTransaction.Begin();
                //TODO heroSkeletonNode.ParentNode.Transform = SCNMatrix4.CreateTranslation (new SCNVector3 (0, 0, 40)); //CATransform3DTranslate(_heroSkeletonNode.parentNode.transform, 0, 0, 40);
                SCNTransaction.Commit();
                break;
            }
        }
コード例 #9
0
		public override void PresentStep (int index, PresentationViewController presentationViewController)
		{
			switch (index) {
			case 0:
				TextManager.SetTitle ("Animation Events");
				TextManager.AddBulletAtLevel ("SCNAnimationEvent", 0);

				TextManager.AddCode ("#var anEvent = #SCNAnimationEvent.Create# (0.2,  aBlock); \n"
				+ "anAnimation.#AnimationEvents# = @[anEvent, anotherEvent];#");

				// Warm up NSSound by playing an empty sound.
				// Otherwise the first sound may take some time to start playing and will be desynchronised.
				var path = NSBundle.MainBundle.PathForResource ("Sounds/emptySound", "m4a");
				var soundUrl = NSUrl.FromFilename (path);
				var emptySound = new NSSound (soundUrl, false);
				emptySound.Play ();
				break;
			case 1:
			case 2:
				// Trigger the attack animation
				HeroSkeletonNode.AddAnimation (Animations [(int)CharacterAnimation.Attack], new NSString ("attack"));
				break;
			case 3:
				// Trigger the walk animation
				HeroSkeletonNode.AddAnimation (Animations [(int)CharacterAnimation.Walk], new NSString ("walk"));
				break;
			case 4:
				// Trigger the death animation
				// Make sure to remove the "idle" animation and prevent the model from intersecting with the floor.

				HeroSkeletonNode.RemoveAllAnimations ();
				HeroSkeletonNode.AddAnimation (Animations [(int)CharacterAnimation.Die], new NSString ("death"));

				SCNTransaction.Begin ();
				//TODO heroSkeletonNode.ParentNode.Transform = SCNMatrix4.CreateTranslation (new SCNVector3 (0, 0, 40)); //CATransform3DTranslate(_heroSkeletonNode.parentNode.transform, 0, 0, 40);
				SCNTransaction.Commit ();
				break;
			}
		}
コード例 #10
0
        partial void OpenWavFile(NSObject sender)
        {
            var dlg = NSOpenPanel.OpenPanel;

            dlg.CanChooseFiles       = true;
            dlg.CanChooseDirectories = false;
            dlg.AllowedFileTypes     = new string[] { "mp3" };


            if (dlg.RunModal() == 1)
            {
                var url = dlg.Urls[0];
            }

            sound = new NSSound(dlg.Filename, byRef: false);
            var fil = new FileInfo(dlg.Filename);

            sound.Play();
            isPaused = false;
            string imagePath = "/Users/sansirajalingam/Desktop/bla.jpg";

            image = new NSImage(imagePath);
        }
コード例 #11
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            #region first two buttons

            // add the image menu item back to the first menu item
            NSMenuItem menuItem = new NSMenuItem("", new Selector(""), "");

            menuItem.Image = NSImage.ImageNamed("moof.png");
            buttonMenu.InsertItem(menuItem, 0);

            nibBasedPopUpDown.Menu  = buttonMenu;
            nibBasedPopUpRight.Menu = buttonMenu;

            // create the pull down button pointing DOWN
            CGRect buttonFrame = placeHolder1.Frame;
            codeBasedPopUpDown = new NSPopUpButton(buttonFrame, true);

            ((NSPopUpButtonCell)codeBasedPopUpDown.Cell).ArrowPosition = NSPopUpArrowPosition.Bottom;
            ((NSPopUpButtonCell)codeBasedPopUpDown.Cell).BezelStyle    = NSBezelStyle.ThickSquare;
            codeBasedPopUpDown.Menu = buttonMenu;
            popupBox.AddSubview(codeBasedPopUpDown);
            placeHolder1.RemoveFromSuperview();

            // create the pull down button pointing RIGHT
            buttonFrame         = placeHolder2.Frame;
            codeBasedPopUpRight = new NSPopUpButton(buttonFrame, true);

            ((NSPopUpButtonCell)codeBasedPopUpRight.Cell).ArrowPosition = NSPopUpArrowPosition.Bottom;
            ((NSPopUpButtonCell)codeBasedPopUpRight.Cell).PreferredEdge = NSRectEdge.MaxXEdge;
            ((NSPopUpButtonCell)codeBasedPopUpRight.Cell).BezelStyle    = NSBezelStyle.Circular;
            codeBasedPopUpRight.Menu = buttonMenu;
            ((NSPopUpButtonCell)codeBasedPopUpRight.Cell).HighlightsBy = (nint)(int)NSCellStyleMask.ChangeGrayCell;
            popupBox.AddSubview(codeBasedPopUpRight);
            placeHolder2.RemoveFromSuperview();

            #endregion

            #region second two buttons

            // create the rounded button
            buttonFrame = placeHolder3.Frame;
            // note: this button we want alternate title and image, so we need to call this:
            codeBasedButtonRound = new NSButton(buttonFrame)
            {
                Title          = "NSButton",
                AlternateTitle = "(pressed)",
                Image          = NSImage.ImageNamed("moof.png"),
                AlternateImage = NSImage.ImageNamed("moof2.png"),
                BezelStyle     = NSBezelStyle.RegularSquare,
                ImagePosition  = NSCellImagePosition.ImageLeft,
                Font           = NSFont.SystemFontOfSize(NSFont.SmallSystemFontSize),
                Sound          = NSSound.FromName("Pop"),
            };
            // Two choices, either use the .NET event system:
            //    foo.Activated += delegate {..} or += SomeMethod
            //
            // Or you can use the Target = this Action = new Selector ("buttonAction:")
            // pattern
            codeBasedButtonRound.Activated += delegate {
                buttonAction(null);
            };
            codeBasedButtonRound.SetButtonType(NSButtonType.MomentaryChange);
            codeBasedButtonRound.Cell.Alignment = NSTextAlignment.Left;
            buttonBox.AddSubview(codeBasedButtonRound);
            placeHolder3.RemoveFromSuperview();                                 // we are done with the place holder, remove it from the window

            // create the square button
            buttonFrame           = placeHolder4.Frame;
            codeBasedButtonSquare = new NSButton(buttonFrame)
            {
                Title         = "NSButton",
                BezelStyle    = NSBezelStyle.ShadowlessSquare,
                ImagePosition = NSCellImagePosition.ImageLeft,
                Image         = NSImage.ImageNamed("moof.png"),
                Font          = NSFont.SystemFontOfSize(NSFont.SmallSystemFontSize),
                Sound         = NSSound.FromName("Pop"),
            };
            codeBasedButtonSquare.Activated     += delegate { buttonAction(null); };
            codeBasedButtonSquare.Cell.Alignment = NSTextAlignment.Left;
            buttonBox.AddSubview(codeBasedButtonSquare);
            placeHolder4.RemoveFromSuperview();                                 // we are done with the place holder, remove it from the window

            #endregion

            #region segmented control

            buttonFrame             = placeHolder5.Frame;
            codeBasedSegmentControl = new NSSegmentedControl(buttonFrame)
            {
                SegmentCount = 3,
                Target       = this,
                Action       = new Selector("segmentAction:")
            };

            codeBasedSegmentControl.SetWidth(nibBasedSegControl.GetWidth(0), 0);
            codeBasedSegmentControl.SetWidth(nibBasedSegControl.GetWidth(1), 1);
            codeBasedSegmentControl.SetWidth(nibBasedSegControl.GetWidth(2), 2);
            codeBasedSegmentControl.SetLabel("One", 0);
            codeBasedSegmentControl.SetLabel("Two", 1);
            codeBasedSegmentControl.SetLabel("Three", 2);
            segmentBox.AddSubview(codeBasedSegmentControl);
            placeHolder5.RemoveFromSuperview();

            // use a menu to the first segment (applied to both nib-based and code-based)
            codeBasedSegmentControl.SetMenu(buttonMenu, 0);
            nibBasedSegControl.SetMenu(buttonMenu, 0);

            // add icons to each segment (applied to both nib-based and code-based)
            NSImage segmentIcon1 = NSWorkspace.SharedWorkspace.IconForFileType(HFSTypeCode.ComputerIcon);
            segmentIcon1.Size = new CGSize(16, 16);
            nibBasedSegControl.SetImage(segmentIcon1, 0);
            codeBasedSegmentControl.SetImage(segmentIcon1, 0);

            NSImage segmentIcon2 = NSWorkspace.SharedWorkspace.IconForFileType(HFSTypeCode.DesktopIcon);
            segmentIcon2.Size = new CGSize(16, 16);
            nibBasedSegControl.SetImage(segmentIcon2, 1);
            codeBasedSegmentControl.SetImage(segmentIcon2, 1);

            NSImage segmentIcon3 = NSWorkspace.SharedWorkspace.IconForFileType(HFSTypeCode.FinderIcon);
            segmentIcon3.Size = new CGSize(16, 16);
            nibBasedSegControl.SetImage(segmentIcon3, 2);
            codeBasedSegmentControl.SetImage(segmentIcon3, 2);

            #endregion

            #region level indicator

            buttonFrame        = placeHolder8.Frame;
            codeBasedIndicator = new NSLevelIndicator(buttonFrame)
            {
                MaxValue           = 10,
                MajorTickMarkCount = 4,
                TickMarkCount      = 7,
                WarningValue       = 5,
                CriticalValue      = 8,
                Action             = new Selector("levelAction:")
            };
            codeBasedIndicator.Cell.LevelIndicatorStyle = NSLevelIndicatorStyle.DiscreteCapacity;
            indicatorBox.AddSubview(codeBasedIndicator);
            placeHolder8.RemoveFromSuperview();


            #endregion
        }
コード例 #12
0
        private void SetAnimation(CharacterAnimation index, string animationName, string sceneName)
        {
            // Load the DAE using SCNSceneSource in order to be able to retrieve the animation by its identifier
            var path        = NSBundle.MainBundle.PathForResource("Scenes/hero/" + sceneName, "dae");
            var sceneURL    = NSUrl.FromFilename(path);
            var sceneSource = SCNSceneSource.FromUrl(sceneURL, (NSDictionary)null);

            var animation = (CAAnimation)sceneSource.GetEntryWithIdentifier(animationName, new Class("CAAnimation"));

            Animations [(int)index] = animation;

            // Blend animations for smoother transitions
            animation.FadeInDuration  = 0.3f;
            animation.FadeOutDuration = 0.3f;

            if (index == CharacterAnimation.Die)
            {
                // We want the "death" animation to remain at its final state at the end of the animation
                animation.RemovedOnCompletion = false;
                animation.FillMode            = CAFillMode.Both;

                // Create animation events and set them to the animation
                var swipeSoundEventHandler = new SCNAnimationEventHandler((CAAnimation handlerAnimation, NSObject animatedObject, bool playingBackward) => {
                    InvokeOnMainThread(delegate {
                        var soundUrl = NSUrl.FromFilename(NSBundle.MainBundle.PathForResource("Sounds/swipe", "wav"));
                        new NSSound(soundUrl, false).Play();
                    });
                });

                var deathSoundEventBlock = new SCNAnimationEventHandler((CAAnimation handlerAnimation, NSObject animatedObject, bool playingBackward) => {
                    InvokeOnMainThread(delegate {
                        var soundUrl = NSUrl.FromFilename(NSBundle.MainBundle.PathForResource("Sounds/death", "wav"));
                        new NSSound(soundUrl, false).Play();
                    });
                });

                animation.AnimationEvents = new SCNAnimationEvent[] {
                    SCNAnimationEvent.Create(0.0f, swipeSoundEventHandler),
                    SCNAnimationEvent.Create(0.3f, deathSoundEventBlock)
                };
            }

            if (index == CharacterAnimation.Attack)
            {
                // Create an animation event and set it to the animation
                var swordSoundEventHandler = new SCNAnimationEventHandler((CAAnimation handlerAnimation, NSObject animatedObject, bool playingBackward) => {
                    InvokeOnMainThread(delegate {
                        var soundUrl    = NSUrl.FromFilename(NSBundle.MainBundle.PathForResource("Sounds/sword", "wav"));
                        var attackSound = new NSSound(soundUrl, false);
                        attackSound.Play();
                    });
                });

                animation.AnimationEvents = new SCNAnimationEvent[] { SCNAnimationEvent.Create(0.4f, swordSoundEventHandler) };
            }

            if (index == CharacterAnimation.Walk)
            {
                // Repeat the walk animation 3 times
                animation.RepeatCount = 3;

                // Create an animation event and set it to the animation
                var stepSoundEventHandler = new SCNAnimationEventHandler((CAAnimation handlerAnimation, NSObject animatedObject, bool playingBackward) => {
                    InvokeOnMainThread(delegate {
                        var soundUrl = NSUrl.FromFilename(NSBundle.MainBundle.PathForResource("Sounds/walk", "wav"));
                        new NSSound(soundUrl, false).Play();
                    });
                });

                animation.AnimationEvents = new SCNAnimationEvent[] {
                    SCNAnimationEvent.Create(0.2f, stepSoundEventHandler),
                    SCNAnimationEvent.Create(0.7f, stepSoundEventHandler)
                };
            }
        }
コード例 #13
0
 void Ping()
 {
     NSSound.FromName("Submarine").Play();
 }
コード例 #14
0
 void PingItem_Activated(object sender, System.EventArgs e)
 {
     NSSound.FromName("Ping").Play();
 }
コード例 #15
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            this.labeltime.Alignment       = NSTextAlignment.Center;
            this.txtRemain.StringValue     = "";
            this.txtRemain.BackgroundColor = NSColor.FromRgb(135 / 255f, 206 / 255f, 250 / 255f);
            this.txtRemain.Alignment       = NSTextAlignment.Center;
            this.txtminutes.Alignment      = NSTextAlignment.Right;

            SecondTimer          = new Timer(1000);
            SecondTimer.Elapsed += (sender, e) =>
            {
                TimeLeft--;
                TimeSpan time = TimeSpan.FromSeconds(TimeLeft);

                InvokeOnMainThread(() =>
                {
                    this.txtRemain.StringValue = $"剩:{TimeLeft / 60} 分鐘 ";
                });

                if (TimeLeft == 0)
                {
                    // Stop the timer and reset
                    //SecondTimer.Stop();
                    TimeLeft = this.orignTimeLeft;

                    InvokeOnMainThread(() =>
                    {
                        String path = NSBundle.MainBundle.PathForResource("fb", "mp3");

                        NSSound sound = new NSSound(path, true);

                        sound.Play();

                        NSAlert alert = new NSAlert();
                        // Set the style and message text
                        alert.AlertStyle  = NSAlertStyle.Informational;
                        alert.MessageText = "起來休息啦!!";
                        //NSImage image = NSImage.ImageNamed("clock.ico");
                        // Display the NSAlert from the current view
                        alert.BeginSheet(View.Window);
                        NSTimer.CreateScheduledTimer(TimeSpan.FromSeconds(5), (a) => {
                            this.View.Window.EndSheet(alert.Window);
                        });
                    });
                }
            };


            MainTimer          = new Timer(1000);
            MainTimer.Elapsed += (sender, e) =>
            {
                DateTime time       = DateTime.Now;
                string   timeString = time.ToString(@"HH\:mm\:ss");
                InvokeOnMainThread(() =>
                {
                    this.labeltime.StringValue = timeString;
                });
            };

            MainTimer.Start();

            thirdTimer          = new Timer(3000);
            thirdTimer.Elapsed += (sender, e) =>
            {
                imagenumber++;

                InvokeOnMainThread(() =>
                {
                    ChangeBackground((imagenumber));

                    NextSnowStartPosition();
                    //this.HideLayer();
                });


                if (imagenumber == 6)
                {
                    imagenumber = 1;
                }
            };

            thirdTimer.Start();
        }
コード例 #16
0
		void SetAnimation (CharacterAnimation index, string animationName, string sceneName)
		{
			// Load the DAE using SCNSceneSource in order to be able to retrieve the animation by its identifier
			var path = NSBundle.MainBundle.PathForResource ("Scenes/hero/" + sceneName, "dae");
			var sceneURL = NSUrl.FromFilename (path);
			var sceneSource = SCNSceneSource.FromUrl (sceneURL, (NSDictionary)null);

			var animation = (CAAnimation)sceneSource.GetEntryWithIdentifier (animationName, new Class ("CAAnimation"));
			Animations [(int)index] = animation;

			// Blend animations for smoother transitions
			animation.FadeInDuration = 0.3f;
			animation.FadeOutDuration = 0.3f;

			if (index == CharacterAnimation.Die) {
				// We want the "death" animation to remain at its final state at the end of the animation
				animation.RemovedOnCompletion = false;
				animation.FillMode = CAFillMode.Both;

				// Create animation events and set them to the animation
				var swipeSoundEventHandler = new SCNAnimationEventHandler ((CAAnimation handlerAnimation, NSObject animatedObject, bool playingBackward) => {
					InvokeOnMainThread (delegate {
						var soundUrl = NSUrl.FromFilename (NSBundle.MainBundle.PathForResource ("Sounds/swipe", "wav"));
						new NSSound (soundUrl, false).Play ();
					});
				});

				var deathSoundEventBlock = new SCNAnimationEventHandler ((CAAnimation handlerAnimation, NSObject animatedObject, bool playingBackward) => {
					InvokeOnMainThread (delegate {
						var soundUrl = NSUrl.FromFilename (NSBundle.MainBundle.PathForResource ("Sounds/death", "wav"));
						new NSSound (soundUrl, false).Play ();
					});
				});

				animation.AnimationEvents = new SCNAnimationEvent[] {
					SCNAnimationEvent.Create (0.0f, swipeSoundEventHandler),
					SCNAnimationEvent.Create (0.3f, deathSoundEventBlock)
				};
			}

			if (index == CharacterAnimation.Attack) {
				// Create an animation event and set it to the animation
				var swordSoundEventHandler = new SCNAnimationEventHandler ((CAAnimation handlerAnimation, NSObject animatedObject, bool playingBackward) => {
					InvokeOnMainThread (delegate {
						var soundUrl = NSUrl.FromFilename (NSBundle.MainBundle.PathForResource ("Sounds/sword", "wav"));
						var attackSound = new NSSound (soundUrl, false);
						attackSound.Play ();
					});
				});

				animation.AnimationEvents = new SCNAnimationEvent[] { SCNAnimationEvent.Create (0.4f, swordSoundEventHandler) };
			}

			if (index == CharacterAnimation.Walk) {
				// Repeat the walk animation 3 times
				animation.RepeatCount = 3;

				// Create an animation event and set it to the animation
				var stepSoundEventHandler = new SCNAnimationEventHandler ((CAAnimation handlerAnimation, NSObject animatedObject, bool playingBackward) => {
					InvokeOnMainThread (delegate {
						var soundUrl = NSUrl.FromFilename (NSBundle.MainBundle.PathForResource ("Sounds/walk", "wav"));
						new NSSound (soundUrl, false).Play ();
					});
				});

				animation.AnimationEvents = new SCNAnimationEvent[] {
					SCNAnimationEvent.Create (0.2f, stepSoundEventHandler),
					SCNAnimationEvent.Create (0.7f, stepSoundEventHandler)
				};
			}
		}
コード例 #17
0
        void ItemDropped(string item)
        {
            Console.WriteLine("Item dropped: {0}", item);

            //var provider = ProviderFactory.GetInstance();
            //if (provider.IsAuthenticated) {

            //}

            var provider = new FtpProvider();

            if (provider.Authenticated)
            {
                Console.WriteLine("Uploading...");
                provider.Upload(item, "asdf", (url) => {
                    Console.WriteLine("very nice => " + url);
                });
            }
            else
            {
                Console.WriteLine("authenticating...");
                var username = ConfigurationSettings.AppSettings["FtpUsername"];
                var password = ConfigurationSettings.AppSettings["FtpPassword"];
                provider.Authenticate(username, password, account => {
                    Console.WriteLine("cool. got: " + account);
                    var fileInfo = new System.IO.FileInfo(item);
                    provider.Upload(item, fileInfo.Name, (url) => {
                        Console.WriteLine("very nice => " + url);
                        BeginInvokeOnMainThread(() => {
                            // placing link into clipboard
                            NSPasteboard pb = NSPasteboard.GeneralPasteboard;
                            pb.DeclareTypes(new string[] { NSPasteboard.NSStringType }, null);
                            pb.SetStringForType(url, NSPasteboard.NSStringType);
                            Console.WriteLine("File will be available for download from {0}", url);

                            var sound = NSSound.FromName("Pop");
                            sound.Play();
                        });
                    });
                }, err => {
                    Console.WriteLine("not cool -- failed with: " + err);
                });
            }


            //if (Account.IsAuthenticated) {
            //	CreateShare(Account, item.Replace("file://localhost", "").Replace("%20", " "));
            //}
            //else {
            //	GettProvider.Instance.Authenticate(Account.Email, Account.Password, (account) => {
            //		// user is logged in

            //		// store retrieved access token for future requests
            //		Account.AccessToken = account.AccessToken;

            //		CreateShare(account, item.Replace("file://localhost", "").Replace("%20", " "));
            //	}, (error) => {
            //		// TODO: handle error message when uploading
            //		Console.WriteLine("Got an error: {0}", error);
            //	});
            //}
        }
コード例 #18
0
        public SparkleSetup() : base()
        {
            Controller.ChangePageEvent += delegate(PageType type, string [] warnings) {
                InvokeOnMainThread(delegate {
                    Reset();

                    switch (type)
                    {
                    case PageType.Setup: {
                        Header      = "Welcome to SparkleShare!";
                        Description = "We'll need some info to mark your changes in the event log. " +
                                      "Don't worry, this stays between you and your peers.";


                        FullNameLabel = new NSTextField()
                        {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF(165, Frame.Height - 234, 160, 17),
                            StringValue     = "Full Name:",
                            Font            = SparkleUI.Font
                        };

                        FullNameTextField = new NSTextField()
                        {
                            Frame       = new RectangleF(330, Frame.Height - 238, 196, 22),
                            StringValue = Controller.GuessedUserName,
                            Delegate    = new SparkleTextFieldDelegate()
                        };

                        EmailLabel = new NSTextField()
                        {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF(165, Frame.Height - 264, 160, 17),
                            StringValue     = "Email:",
                            Font            = SparkleUI.Font
                        };

                        EmailTextField = new NSTextField()
                        {
                            Frame       = new RectangleF(330, Frame.Height - 268, 196, 22),
                            StringValue = Controller.GuessedUserEmail,
                            Delegate    = new SparkleTextFieldDelegate()
                        };


                        (FullNameTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                            Controller.CheckSetupPage(
                                FullNameTextField.StringValue,
                                EmailTextField.StringValue
                                );
                        };

                        (EmailTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                            Controller.CheckSetupPage(
                                FullNameTextField.StringValue,
                                EmailTextField.StringValue
                                );
                        };


                        ContinueButton = new NSButton()
                        {
                            Title   = "Continue",
                            Enabled = false
                        };

                        ContinueButton.Activated += delegate {
                            string full_name = FullNameTextField.StringValue.Trim();
                            string email     = EmailTextField.StringValue.Trim();

                            Controller.SetupPageCompleted(full_name, email);
                        };

                        Controller.UpdateSetupContinueButtonEvent += delegate(bool button_enabled) {
                            InvokeOnMainThread(delegate {
                                    ContinueButton.Enabled = button_enabled;
                                });
                        };


                        ContentView.AddSubview(FullNameLabel);
                        ContentView.AddSubview(FullNameTextField);
                        ContentView.AddSubview(EmailLabel);
                        ContentView.AddSubview(EmailTextField);

                        Buttons.Add(ContinueButton);

                        Controller.CheckSetupPage(
                            FullNameTextField.StringValue,
                            EmailTextField.StringValue
                            );

                        break;
                    }

                    case PageType.Add: {
                        Header      = "Where's your project hosted?";
                        Description = "";

                        AddressLabel = new NSTextField()
                        {
                            Alignment       = NSTextAlignment.Left,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF(190, Frame.Height - 308, 160, 17),
                            StringValue     = "Address:",
                            Font            = SparkleUI.Font
                        };

                        AddressTextField = new NSTextField()
                        {
                            Frame       = new RectangleF(190, Frame.Height - 336, 196, 22),
                            Font        = SparkleUI.Font,
                            StringValue = Controller.PreviousAddress,
                            Enabled     = (Controller.SelectedPlugin.Address == null),
                            Delegate    = new SparkleTextFieldDelegate()
                        };


                        PathLabel = new NSTextField()
                        {
                            Alignment       = NSTextAlignment.Left,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF(190 + 196 + 16, Frame.Height - 308, 160, 17),
                            StringValue     = "Remote Path:",
                            Font            = SparkleUI.Font
                        };

                        PathTextField = new NSTextField()
                        {
                            Frame       = new RectangleF(190 + 196 + 16, Frame.Height - 336, 196, 22),
                            StringValue = Controller.PreviousPath,
                            Enabled     = (Controller.SelectedPlugin.Path == null),
                            Delegate    = new SparkleTextFieldDelegate()
                        };


                        AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
                        PathTextField.Cell.LineBreakMode    = NSLineBreakMode.TruncatingTail;


                        PathHelpLabel = new NSTextField()
                        {
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            TextColor       = NSColor.DisabledControlText,
                            Editable        = false,
                            Frame           = new RectangleF(190 + 196 + 16, Frame.Height - 355, 204, 17),
                            StringValue     = "e.g. ‘rupert/website-design’",
                            Font            = NSFontManager.SharedFontManager.FontWithFamily
                                                  ("Lucida Grande", NSFontTraitMask.Condensed, 0, 11)
                        };


                        TableView = new NSTableView()
                        {
                            Frame            = new RectangleF(0, 0, 0, 0),
                            RowHeight        = 30,
                            IntercellSpacing = new SizeF(0, 12),
                            HeaderView       = null,
                            Delegate         = new SparkleTableViewDelegate()
                        };

                        ScrollView = new NSScrollView()
                        {
                            Frame               = new RectangleF(190, Frame.Height - 280, 408, 175),
                            DocumentView        = TableView,
                            HasVerticalScroller = true,
                            BorderType          = NSBorderType.BezelBorder
                        };

                        IconColumn = new NSTableColumn(new NSImage())
                        {
                            Width         = 42,
                            HeaderToolTip = "Icon",
                            DataCell      = new NSImageCell()
                        };

                        DescriptionColumn = new NSTableColumn()
                        {
                            Width         = 350,
                            HeaderToolTip = "Description",
                            Editable      = false
                        };

                        DescriptionColumn.DataCell.Font =
                            NSFontManager.SharedFontManager.FontWithFamily(
                                "Lucida Grande", NSFontTraitMask.Condensed, 0, 11);

                        TableView.AddColumn(IconColumn);
                        TableView.AddColumn(DescriptionColumn);

                        DataSource = new SparkleDataSource();

                        foreach (SparklePlugin plugin in Controller.Plugins)
                        {
                            DataSource.Items.Add(plugin);
                        }

                        TableView.DataSource = DataSource;
                        TableView.ReloadData();


                        Controller.ChangeAddressFieldEvent += delegate(string text,
                                                                       string example_text, FieldState state) {
                            InvokeOnMainThread(delegate {
                                    AddressTextField.StringValue = text;
                                    AddressTextField.Enabled     = (state == FieldState.Enabled);
                                });
                        };


                        Controller.ChangePathFieldEvent += delegate(string text,
                                                                    string example_text, FieldState state) {
                            InvokeOnMainThread(delegate {
                                    PathTextField.StringValue = text;
                                    PathTextField.Enabled     = (state == FieldState.Enabled);

                                    if (!string.IsNullOrEmpty(example_text))
                                    {
                                        PathHelpLabel.StringValue = "e.g. " + example_text;
                                    }
                                });
                        };


                        TableView.SelectRow(Controller.SelectedPluginIndex, false);


                        (AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                            Controller.CheckAddPage(
                                AddressTextField.StringValue,
                                PathTextField.StringValue,
                                TableView.SelectedRow
                                );
                        };

                        (PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                            Controller.CheckAddPage(
                                AddressTextField.StringValue,
                                PathTextField.StringValue,
                                TableView.SelectedRow
                                );
                        };

                        (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate {
                            Controller.SelectedPluginChanged(TableView.SelectedRow);

                            Controller.CheckAddPage(
                                AddressTextField.StringValue,
                                PathTextField.StringValue,
                                TableView.SelectedRow
                                );
                        };


                        Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled) {
                            InvokeOnMainThread(delegate {
                                    SyncButton.Enabled = button_enabled;
                                });
                        };


                        ContentView.AddSubview(ScrollView);
                        ContentView.AddSubview(AddressLabel);
                        ContentView.AddSubview(AddressTextField);
                        ContentView.AddSubview(PathLabel);
                        ContentView.AddSubview(PathTextField);
                        ContentView.AddSubview(PathHelpLabel);

                        SyncButton = new NSButton()
                        {
                            Title   = "Add",
                            Enabled = false
                        };

                        SyncButton.Activated += delegate {
                            Controller.AddPageCompleted(
                                AddressTextField.StringValue,
                                PathTextField.StringValue
                                );
                        };

                        Buttons.Add(SyncButton);

                        CancelButton = new NSButton()
                        {
                            Title = "Cancel"
                        };

                        CancelButton.Activated += delegate {
                            InvokeOnMainThread(delegate {
                                    PerformClose(this);
                                });
                        };

                        Buttons.Add(CancelButton);

                        Controller.CheckAddPage(
                            AddressTextField.StringValue,
                            PathTextField.StringValue,
                            TableView.SelectedRow
                            );


                        break;
                    }

                    case PageType.Syncing: {
                        Header      = "Adding project ‘" + Controller.SyncingFolder + "’…";
                        Description = "This may take a while.\n" +
                                      "Are you sure it’s not coffee o'clock?";

                        ProgressIndicator = new NSProgressIndicator()
                        {
                            Frame         = new RectangleF(190, Frame.Height - 200, 640 - 150 - 80, 20),
                            Style         = NSProgressIndicatorStyle.Bar,
                            MinValue      = 0.0,
                            MaxValue      = 100.0,
                            Indeterminate = false,
                            DoubleValue   = 1.0
                        };

                        ProgressIndicator.StartAnimation(this);

                        Controller.UpdateProgressBarEvent += delegate(double percentage) {
                            InvokeOnMainThread(delegate {
                                    ProgressIndicator.DoubleValue = percentage;
                                });
                        };

                        ContentView.AddSubview(ProgressIndicator);

                        FinishButton = new NSButton()
                        {
                            Title   = "Finish",
                            Enabled = false
                        };

                        CancelButton = new NSButton()
                        {
                            Title = "Cancel"
                        };

                        CancelButton.Activated += delegate {
                            Controller.SyncingCancelled();
                        };

                        Buttons.Add(FinishButton);
                        Buttons.Add(CancelButton);

                        break;
                    }

                    case PageType.Error: {
                        Header      = "Something went wrong…";
                        Description = "Please check the following:";

                        // Displaying marked up text with Cocoa is
                        // a pain, so we just use a webview instead
                        WebView web_view = new WebView();
                        web_view.Frame   = new RectangleF(190, Frame.Height - 525, 375, 400);

                        string html = "<style>" +
                                      "* {" +
                                      "  font-family: 'Lucida Grande';" +
                                      "  font-size: 12px; cursor: default;" +
                                      "}" +
                                      "body {" +
                                      "  -webkit-user-select: none;" +
                                      "  margin: 0;" +
                                      "  padding: 3px;" +
                                      "}" +
                                      "li {" +
                                      "  margin-bottom: 16px;" +
                                      "  margin-left: 0;" +
                                      "  padding-left: 0;" +
                                      "  line-height: 20px;" +
                                      "}" +
                                      "ul {" +
                                      "  padding-left: 24px;" +
                                      "}" +
                                      "</style>" +
                                      "<ul>" +
                                      "  <li>First, have you tried turning it off and on again?</li>" +
                                      "  <li><b>" + Controller.PreviousUrl + "</b> is the address we've compiled. Does this look alright?</li>" +
                                      "  <li>The host needs to know who you are. Did you upload the key that's in your SparkleShare folder?</li>" +
                                      "</ul>";

                        web_view.MainFrame.LoadHtmlString(html, new NSUrl(""));
                        web_view.DrawsBackground = false;

                        ContentView.AddSubview(web_view);

                        TryAgainButton = new NSButton()
                        {
                            Title = "Try again…"
                        };

                        TryAgainButton.Activated += delegate {
                            Controller.ErrorPageCompleted();
                        };

                        Buttons.Add(TryAgainButton);

                        break;
                    }

                    case PageType.Finished: {
                        Header      = "Project succesfully added!";
                        Description = "Now you can access the files from " +
                                      "‘" + Controller.SyncingFolder + "’ in " +
                                      "your SparkleShare folder.";

                        if (warnings != null)
                        {
                            WarningImage      = NSImage.ImageNamed("NSCaution");
                            WarningImage.Size = new SizeF(24, 24);

                            WarningImageView = new NSImageView()
                            {
                                Image = WarningImage,
                                Frame = new RectangleF(190, Frame.Height - 175, 24, 24)
                            };

                            WarningTextField = new NSTextField()
                            {
                                Frame           = new RectangleF(230, Frame.Height - 245, 325, 100),
                                StringValue     = warnings [0],
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                Editable        = false,
                                Font            = SparkleUI.Font
                            };

                            ContentView.AddSubview(WarningImageView);
                            ContentView.AddSubview(WarningTextField);
                        }

                        FinishButton = new NSButton()
                        {
                            Title = "Finish"
                        };

                        FinishButton.Activated += delegate {
                            InvokeOnMainThread(delegate {
                                    Controller.FinishedPageCompleted();
                                    PerformClose(this);
                                });
                        };

                        OpenFolderButton = new NSButton()
                        {
                            Title = "Open Folder"
                        };

                        OpenFolderButton.Activated += delegate {
                            Program.Controller.OpenSparkleShareFolder(Controller.SyncingFolder);
                        };

                        Buttons.Add(FinishButton);
                        Buttons.Add(OpenFolderButton);

                        NSApplication.SharedApplication.RequestUserAttention
                            (NSRequestUserAttentionType.CriticalRequest);

                        NSSound.FromName("Glass").Play();

                        break;
                    }

                    case PageType.Tutorial: {
                        switch (Controller.TutorialPageNumber)
                        {
                        case 1: {
                            Header      = "What's happening next?";
                            Description = "SparkleShare creates a special folder in your personal folder " +
                                          "that will keep track of your projects.";

                            SkipTutorialButton = new NSButton()
                            {
                                Title = "Skip Tutorial"
                            };

                            SkipTutorialButton.Activated += delegate {
                                Controller.TutorialSkipped();
                            };

                            ContinueButton = new NSButton()
                            {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted();
                            };

                            string slide_image_path = Path.Combine(NSBundle.MainBundle.ResourcePath,
                                                                   "Pixmaps", "tutorial-slide-1-mac.png");

                            SlideImage = new NSImage(slide_image_path)
                            {
                                Size = new SizeF(350, 200)
                            };

                            SlideImageView = new NSImageView()
                            {
                                Image = SlideImage,
                                Frame = new RectangleF(215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview(SlideImageView);
                            Buttons.Add(ContinueButton);
                            Buttons.Add(SkipTutorialButton);

                            break;
                        }

                        case 2: {
                            Header      = "Sharing files with others";
                            Description = "All files added to your project folders are synced with the host " +
                                          "automatically, as well as with your collaborators.";

                            ContinueButton = new NSButton()
                            {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted();
                            };

                            string slide_image_path = Path.Combine(NSBundle.MainBundle.ResourcePath,
                                                                   "Pixmaps", "tutorial-slide-2-mac.png");

                            SlideImage = new NSImage(slide_image_path)
                            {
                                Size = new SizeF(350, 200)
                            };

                            SlideImageView = new NSImageView()
                            {
                                Image = SlideImage,
                                Frame = new RectangleF(215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview(SlideImageView);
                            Buttons.Add(ContinueButton);

                            break;
                        }

                        case 3: {
                            Header      = "The status icon is here to help";
                            Description = "It shows the syncing process status, " +
                                          "and contains links to your projects and the event log.";

                            ContinueButton = new NSButton()
                            {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted();
                            };

                            string slide_image_path = Path.Combine(NSBundle.MainBundle.ResourcePath,
                                                                   "Pixmaps", "tutorial-slide-3-mac.png");

                            SlideImage = new NSImage(slide_image_path)
                            {
                                Size = new SizeF(350, 200)
                            };

                            SlideImageView = new NSImageView()
                            {
                                Image = SlideImage,
                                Frame = new RectangleF(215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview(SlideImageView);
                            Buttons.Add(ContinueButton);

                            break;
                        }

                        case 4: {
                            Header      = "Adding projects to SparkleShare";
                            Description = "Just click this button when you see it on the web, and " +
                                          "the project will be automatically added:";

                            AddProjectTextField = new NSTextField()
                            {
                                Frame           = new RectangleF(190, Frame.Height - 290, 640 - 240, 44),
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                Editable        = false,
                                Font            = SparkleUI.Font,
                                StringValue     = "…or select ‘Add Hosted Project…’ from the status icon menu " +
                                                  "to add one by hand."
                            };

                            FinishButton = new NSButton()
                            {
                                Title = "Finish"
                            };

                            FinishButton.Activated += delegate {
                                InvokeOnMainThread(delegate {
                                            PerformClose(this);
                                        });
                            };

                            string slide_image_path = Path.Combine(NSBundle.MainBundle.ResourcePath,
                                                                   "Pixmaps", "tutorial-slide-4.png");

                            SlideImage = new NSImage(slide_image_path)
                            {
                                Size = new SizeF(350, 64)
                            };

                            SlideImageView = new NSImageView()
                            {
                                Image = SlideImage,
                                Frame = new RectangleF(215, Frame.Height - 215, 350, 64)
                            };

                            ContentView.AddSubview(SlideImageView);
                            ContentView.AddSubview(AddProjectTextField);
                            Buttons.Add(FinishButton);

                            break;
                        }
                        }

                        break;
                    }
                    }

                    ShowAll();
                });
            };
        }
コード例 #19
0
        public override void FinishedLaunching(NSObject notification)
        {
            // Configure logger
            string path = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "log4net.config");

            XmlConfigurator.ConfigureAndWatch(new FileInfo(path));
            logger.Info("Ventriliquest 1.0 Starting up...");

            // Get list of available audio out devices
            xamspeech ham = new xamspeech();

            OutputDevices = ham.GetDevices();

            // Setup UI
            statusMenu = new NSMenu();
            statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30);

            var outputItem = new NSMenuItem("Output Device",
                                            (a, b) => {
            });

            var deviceList = new NSMenu();

            outputItem.Submenu = deviceList;

            OutputDeviceUID = "Built-in Output";

            foreach (var entry in OutputDevices)
            {
                var test = new NSMenuItem(entry.Key.ToString(),
                                          (a, b) => {
                    foreach (NSMenuItem item in deviceList.ItemArray())
                    {
                        item.State = NSCellStateValue.Off;
                    }
                    NSMenuItem theItem  = (NSMenuItem)a;
                    theItem.State       = NSCellStateValue.On;
                    config.OutputDevice = theItem.Title;
                    foreach (var e in OutputDevices)
                    {
                        if (e.Key.ToString().Equals(theItem.Title))
                        {
                            OutputDeviceUID = e.Value.ToString();
                        }
                    }
                });
                if (entry.Key.ToString().Equals(config.OutputDevice))
                {
                    test.State      = NSCellStateValue.On;
                    OutputDeviceUID = entry.Value.ToString();
                }
                deviceList.AddItem(test);
            }

            var daItem = new NSMenuItem("Local Connections Only",
                                        (a, b) => {
                NSMenuItem theItem = (NSMenuItem)a;
                if (theItem.State == NSCellStateValue.On)
                {
                    config.LocalOnly = false;
                    theItem.State    = NSCellStateValue.Off;
                }
                else
                {
                    config.LocalOnly = true;
                    theItem.State    = NSCellStateValue.On;
                }
            });

            if (config.LocalOnly)
            {
                daItem.State = NSCellStateValue.On;
            }

            var quitItem = new NSMenuItem("Quit",
                                          (a, b) => Shutdown());

            var voiceconfigItem = new NSMenuItem("Voice Configuration",
                                                 (a, b) => Process.Start("http://127.0.0.1:7888/config"));

            statusMenu.AddItem(new NSMenuItem("Version: 1.1"));
            statusMenu.AddItem(outputItem);
            statusMenu.AddItem(daItem);
            statusMenu.AddItem(voiceconfigItem);
            statusMenu.AddItem(quitItem);
            statusItem.Menu           = statusMenu;
            statusItem.Image          = NSImage.ImageNamed("tts-1.png");
            statusItem.AlternateImage = NSImage.ImageNamed("tts-2.png");
            statusItem.HighlightMode  = true;

            speechdelegate.DidComplete += delegate {
                synthesis.Set();
            };
            sounddelegate.DidComplete += delegate {
                playback.Set();
                IsSounding = false;
                IsSpeaking = false;
                sound.Dispose();
            };

            speech.Delegate = speechdelegate;

            queuetimer          = new System.Timers.Timer(250);
            queuetimer.Elapsed += (object sender, ElapsedEventArgs e) => {
                TTSRequest r;
                if (Queue.TryDequeue(out r))
                {
                    if (r.Interrupt)
                    {
                        // stop current TTS
                        NSApplication.SharedApplication.InvokeOnMainThread(delegate {
                            if (IsSpeaking)
                            {
                                speech.StopSpeaking();
                            }
                            if (IsSounding)
                            {
                                sound.Stop();
                            }
                        });
                        // clear queue
                        SpeechQueue.Clear();
                    }
                    if (!r.Reset)
                    {
                        SpeechQueue.Enqueue(r);
                    }
                    RequestCount++;
                }
                var eventdata = new Hashtable();
                eventdata.Add("ProcessedRequests", RequestCount);
                eventdata.Add("QueuedRequests", SpeechQueue.Count);
                eventdata.Add("IsSpeaking", IsSpeaking);
                InstrumentationEvent ev = new InstrumentationEvent();
                ev.EventName = "status";
                ev.Data      = eventdata;
                NotifyGui(ev.EventMessage());
            };

            // when this timer fires, it will pull off of the speech queue and speak it
            // the 1000ms delay also adds a little pause between tts requests.
            speechtimer          = new System.Timers.Timer(250);
            speechtimer.Elapsed += (object sender, ElapsedEventArgs e) => {
                if (IsSpeaking.Equals(false))
                {
                    if (SpeechQueue.Count > 0)
                    {
                        TTSRequest r = SpeechQueue.Dequeue();
                        IsSpeaking          = true;
                        speechtimer.Enabled = false;
                        var oink = Path.Combine(audiopath, "temp.aiff");
                        NSApplication.SharedApplication.InvokeOnMainThread(delegate {
                            ConfigureSpeechEngine(r);
                            speech.StartSpeakingStringtoURL(r.Text, new NSUrl(oink, false));
                        });
                        synthesis.WaitOne();
                        NSApplication.SharedApplication.InvokeOnMainThread(delegate {
                            IsSounding     = true;
                            sound          = new NSSound(Path.Combine(audiopath, "temp.aiff"), false);
                            sound.Delegate = sounddelegate;
                            //if(OutputDeviceUID != "Default") {
                            sound.PlaybackDeviceID = OutputDeviceUID;
                            //}
                            sound.Play();
                        });
                        playback.WaitOne();
                        IsSounding          = false;
                        speechtimer.Enabled = true;
                    }
                }
            };

            queuetimer.Enabled = true;
            queuetimer.Start();
            speechtimer.Enabled = true;
            speechtimer.Start();

            InitHTTPServer();
        }
コード例 #20
0
ファイル: BowlSound.cs プロジェクト: vicenteherrera/awareness
 public BowlSound(string path) : base(path)
 {
     Sound = new NSSound(SoundPath, false);
 }