Beispiel #1
0
		public SoundItem(SoundItemTree soundItemTree, SoundBlock soundOrMidiRender, int soundInputs, int soundOutputs, int midiInputs, int midiOutputs) : base() 
		{ 
			this.soundBlock = soundOrMidiRender;
			if (soundOrMidiRender is ISoundRender) 
				this.soundRender = (ISoundRender) soundOrMidiRender;
			if (soundOrMidiRender is IMidiRender) 
				this.midiRender = (IMidiRender) soundOrMidiRender;
			this.soundItemTree = soundItemTree;
			this.soundInputs = soundInputs;
			this.soundOutputs = soundOutputs;
			this.midiInputs = midiInputs;
			this.midiOutputs = midiOutputs;		
			this.Size = new System.Drawing.Size(64, 64);
			this.SetStyle(ControlStyles.AllPaintingInWmPaint |
			              ControlStyles.UserPaint |
			              ControlStyles.DoubleBuffer,true);
			this.unselectedBackground = ((System.Drawing.Image)(soundItemTree.Resources.GetObject("unsel-block")));
			this.selectedBackground = ((System.Drawing.Image)(soundItemTree.Resources.GetObject("sel-block")));
			this.nameFont = new System.Drawing.Font(new System.Drawing.FontFamily("Arial"),
			                                                   9,
			                                                   System.Drawing.FontStyle.Regular,
			                                                   System.Drawing.GraphicsUnit.Pixel);
			this.nameFontBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
			
			ContextMenu BlockContextMenu = new ContextMenu();
			this.ContextMenu = BlockContextMenu;
			
			if ((this.soundRender != null) && (this.soundRender.Editable)) {
				MenuItem EditMenuItem = new MenuItem();
				EditMenuItem.Index = 0;
				EditMenuItem.Text = "Edit block";
				EditMenuItem.Click += new System.EventHandler(this.EditBlockClick);
				EditMenuItem.DefaultItem = true;
				BlockContextMenu.MenuItems.Add(EditMenuItem);
				this.DoubleClick += new EventHandler(EditBlockClick);
			}
			MenuItem DeleteMenuItem = new MenuItem();
			DeleteMenuItem.Index = 1;
			DeleteMenuItem.Text = "Delete block";
			DeleteMenuItem.Click += new System.EventHandler(this.DeleteBlockClick);
			BlockContextMenu.MenuItems.Add(DeleteMenuItem);		
			
			soundItemLinkSoundInput = new SoundItemLink[soundInputs];
			soundItemLinkSoundOutput = new SoundItemLink[soundOutputs];
			soundItemLinkMidiInput = new SoundItemLink[midiInputs];
			soundItemLinkMidiOutput = new SoundItemLink[midiOutputs];
			
			for (int i=0; i<soundInputs;i++) {
				soundItemLinkSoundInput[i] = new SoundItemLink(this,i,SoundItemLink.SoundItemLinkType.SoundInput);
				this.Controls.Add(soundItemLinkSoundInput[i]);
			}
			for (int i=0; i<soundOutputs;i++) {
				soundItemLinkSoundOutput[i] = new SoundItemLink(this,i,SoundItemLink.SoundItemLinkType.SoundOutput);
				this.Controls.Add(soundItemLinkSoundOutput[i]);
			}
			for (int i=0; i<midiInputs;i++) {
				soundItemLinkMidiInput[i] = new SoundItemLink(this,i,SoundItemLink.SoundItemLinkType.MidiInput);
				this.Controls.Add(soundItemLinkMidiInput[i]);
			}
			for (int i=0; i<midiOutputs;i++) {
				soundItemLinkMidiOutput[i] = new SoundItemLink(this,i,SoundItemLink.SoundItemLinkType.MidiOutput);
				this.Controls.Add(soundItemLinkMidiOutput[i]);
			}
		}
Beispiel #2
0
		public SoundItemLink GetSoundItemLink(SoundItemLink.SoundItemLinkType linkType, int index) {
			switch (linkType) {
				case SoundItemLink.SoundItemLinkType.SoundInput :
					return soundItemLinkSoundInput[index];
				case SoundItemLink.SoundItemLinkType.SoundOutput :
					return soundItemLinkSoundOutput[index];
				case SoundItemLink.SoundItemLinkType.MidiInput :
					return soundItemLinkMidiInput[index];
				case SoundItemLink.SoundItemLinkType.MidiOutput :
					return soundItemLinkMidiOutput[index];
			}
			return null;
		}
		public void EndLink(SoundItemLink soundItemLink)
		{
			SoundItemLink foundLink = null;
			linking = false;
			for (int i=0; i<soundItems.Count; i++) {
				SoundItem tempSI = (SoundItem) soundItems[i];
				if (tempSI != soundItemLink.SoundItem) {
					foundLink = tempSI.GetLink(linkX2-tempSI.Location.X,linkY2-tempSI.Location.Y);
					if (foundLink != null) break;
				}
			}
			if (foundLink == null) {
				Unlink(soundItemLink);
				if (soundItemLink.Type == SoundItemLink.SoundItemLinkType.MidiOutput) {
					Unlink(soundItemLink.SoundItem.SoundBlock);
				}
			} else {
				if ((foundLink.Type == SoundItemLink.SoundItemLinkType.SoundInput)
					|| (foundLink.Type == SoundItemLink.SoundItemLinkType.MidiInput)) {
						//swap
						SoundItemLink temp = foundLink;
						foundLink = soundItemLink;
						soundItemLink = temp;
					}
				
				
				bool isMidiLink = ((soundItemLink.Type == SoundItemLink.SoundItemLinkType.MidiInput) &&
					(foundLink.Type == SoundItemLink.SoundItemLinkType.MidiOutput));
				bool isSoundLink = ((soundItemLink.Type == SoundItemLink.SoundItemLinkType.SoundInput) &&
					(foundLink.Type == SoundItemLink.SoundItemLinkType.SoundOutput));
				
				if (isSoundLink) {
					Unlink(soundItemLink);
					Unlink(foundLink);
				}
				if (isMidiLink) {
					if (soundItemLink.Linked) Unlink(soundItemLink);
				}
				    
				if (isSoundLink || isMidiLink)
					 {
					 	soundItemLink.Link(foundLink);
					 	//Console.WriteLine("connected: "+soundItemLink.SoundItem.Name+" - "+soundItemLink.LinkedSoundItemLink.SoundItem.Name);
					 	if (soundItemLink.Type == SoundItemLink.SoundItemLinkType.SoundInput) {
					 		soundItemLink.SoundItem.SoundRender.SoundInputs[soundItemLink.Index] = soundItemLink.LinkedSoundItemLink.SoundItem.SoundRender;
					 	}
					 	else if (soundItemLink.Type == SoundItemLink.SoundItemLinkType.MidiInput) {
					 		SoundBlock sb = (SoundBlock) soundItemLink.SoundItem.SoundBlock;
					 		IMidiRender midiRender = (IMidiRender) soundItemLink.LinkedSoundItemLink.SoundItem.MidiRender;	
							IMidiHandler midiHandler = (IMidiHandler) sb;
					 		sb.MidiInputs[soundItemLink.Index] = midiRender;	
					 		midiRender.OnMidiMessage += midiHandler.MidiMessageHandler;
					 	}
					 }
			}
			this.Invalidate();
			this.Update();
		}
		public void Unlink(SoundItemLink soundItemLink)
		{
			if (!soundItemLink.Linked) return;
			
			SoundItemLink producerSIL = null, consumerSIL = null;
			SoundItemLink soundItemLinkA = soundItemLink;
			SoundItemLink soundItemLinkB = soundItemLink.LinkedSoundItemLink;
			
			if (((soundItemLinkA.Type == SoundItemLink.SoundItemLinkType.SoundOutput)
				&& (soundItemLinkB.Type == SoundItemLink.SoundItemLinkType.SoundInput))
				|| ((soundItemLinkA.Type == SoundItemLink.SoundItemLinkType.MidiOutput)
				&& (soundItemLinkB.Type == SoundItemLink.SoundItemLinkType.MidiInput))) {
				
				producerSIL = soundItemLinkA;
				consumerSIL = soundItemLinkB;
			}
			
			if (((soundItemLinkB.Type == SoundItemLink.SoundItemLinkType.SoundOutput)
				&& (soundItemLinkA.Type == SoundItemLink.SoundItemLinkType.SoundInput))
				|| ((soundItemLinkB.Type == SoundItemLink.SoundItemLinkType.MidiOutput)
				&& (soundItemLinkA.Type == SoundItemLink.SoundItemLinkType.MidiInput))) {
				
				producerSIL = soundItemLinkB;
				consumerSIL = soundItemLinkA;
			}
			
			if ((producerSIL == null) || (consumerSIL == null)) return;
		
		// NOTE: these two lines were causing problems with midi and are not needed!	
		//	if ((producerSIL.LinkedSoundItemLink != consumerSIL) 
		//		|| (consumerSIL.LinkedSoundItemLink != producerSIL)) return;
			
			if (producerSIL.Type == SoundItemLink.SoundItemLinkType.SoundOutput) {
				consumerSIL.SoundItem.SoundRender.SoundInputs[consumerSIL.Index] = new H3.Sound.Wave.SoundRender.NullSoundRender();
			} else if (producerSIL.Type == SoundItemLink.SoundItemLinkType.MidiOutput) {
				IMidiRender midiRender = (IMidiRender) producerSIL.SoundItem.MidiRender;
				IMidiHandler midiHandler = (IMidiHandler) consumerSIL.SoundItem.SoundBlock;
				if ((midiRender!= null) && (midiHandler!=null)) midiRender.OnMidiMessage -= midiHandler.MidiMessageHandler;
			}
		
			consumerSIL.Unlink();
			producerSIL.Unlink();
		}
		public void Unlink()
		{
			if (this.linkedSoundItemLink != null) {
				this.linkedSoundItemLink.linkedSoundItemLink = null;
				this.linkedSoundItemLink = null;
			}
		}
		public void Link(SoundItemLink soundItemLink)
		{
			this.linkedSoundItemLink = soundItemLink;
			soundItemLink.LinkedSoundItemLink = this;
		}