/// <summary> /// Throws an exception if percussion is not valid. /// </summary> /// <param name="percussion">The percussion to validate.</param> /// <exception cref="ArgumentOutOfRangeException">The percussion is out-of-range. /// </exception> public static void Validate(this Percussion percussion) { if (!percussion.IsValid()) { throw new ArgumentOutOfRangeException("Percussion out of range"); } }
/// <summary> /// Throws an exception if percussion is not valid. /// </summary> /// <param name="percussion">The percussion to validate.</param> /// <exception cref="ArgumentOutOfRangeException"> /// The percussion is out-of-range. /// </exception> public static void Validate(this Percussion percussion) { if (!percussion.IsValid()) { throw new ArgumentOutOfRangeException(nameof(percussion)); } }
/// <summary> /// Constructor /// </summary> /// <param name="percussion">Percussion enumeration</param> /// <param name="sound">Cymbal sound</param> /// <param name="boundaries">Bounding box</param> /// <param name="touchAreas">List of rectangular touch areas</param> /// <param name="image">Cymbal image</param> public Cymbal(Percussion percussion, SoundEffect sound, Rectangle boundaries, List<Rectangle> touchAreas, Texture2D image) : base(percussion, sound, boundaries, touchAreas, image) { MaxAngle = 0.26f; // Default for max angle (~15 degrees) rotate = new TimerCallback(RotateCallback); Played += new EventHandler(Cymbal_Played); }
/// <summary> /// Constructor /// </summary> /// <param name="percussion">Percussion enumeration</param> /// <param name="sound">Cymbal sound</param> /// <param name="boundaries">Bounding box</param> /// <param name="touchAreas">List of rectangular touch areas</param> /// <param name="image">Cymbal image</param> public Cymbal(Percussion percussion, SoundEffect sound, Rectangle boundaries, List <Rectangle> touchAreas, Texture2D image) : base(percussion, sound, boundaries, touchAreas, image) { MaxAngle = 0.26f; // Default for max angle (~15 degrees) rotate = new TimerCallback(RotateCallback); Played += new EventHandler(Cymbal_Played); }
private static string PercussionSymbol(Percussion p) { switch (p) { case Percussion.BassDrum1: case Percussion.BassDrum2: case Percussion.SnareDrum1: case Percussion.SnareDrum2: case Percussion.HighTom1: case Percussion.HighTom2: case Percussion.MidTom1: case Percussion.MidTom2: case Percussion.LowTom1: case Percussion.LowTom2: case Percussion.OpenHiHat: return("o"); case Percussion.CrashCymbal1: case Percussion.CrashCymbal2: case Percussion.RideCymbal1: case Percussion.RideCymbal2: case Percussion.ClosedHiHat: return("x"); } return("?"); }
/// <summary> /// Constructor /// </summary> /// <param name="percussion">Percussion enumeration</param> /// <param name="sound">Percussion sound</param> /// <param name="boundaries">Bounding box</param> /// <param name="touchAreas">List of rectangular touch areas</param> public Pad(Percussion percussion, SoundEffect sound, Rectangle boundaries, List <Rectangle> touchAreas) { Origin = new Vector2(0f, 0f); Percussion = percussion; Sound = sound; this.boundaries = boundaries; this.touchAreas = touchAreas; }
/// <summary> /// Constructor /// </summary> /// <param name="percussion">Percussion enumeration</param> /// <param name="sound">Cymbal sound</param> /// <param name="boundaries">Bounding box</param> /// <param name="touchAreas">List of rectangular touch areas</param> /// <param name="image">Cymbal image</param> public Drum(Percussion percussion, SoundEffect sound, Rectangle boundaries, List<Rectangle> touchAreas, Texture2D image) : base(percussion, sound, boundaries, touchAreas, image) { MaxMagnitude = -0.04f; Origin = new Vector2(boundaries.Width / 2, boundaries.Height / 2); shake = new TimerCallback(ShakeCallback); Played += new EventHandler(Drum_Played); }
/// <summary> /// Constructor /// </summary> /// <param name="percussion">Percussion enumeration</param> /// <param name="sound">Percussion sound</param> /// <param name="boundaries">Bounding box</param> /// <param name="touchAreas">List of rectangular touch areas</param> public Pad(Percussion percussion, SoundEffect sound, Rectangle boundaries, List<Rectangle> touchAreas) { Origin = new Vector2(0f, 0f); Percussion = percussion; Sound = sound; this.boundaries = boundaries; this.touchAreas = touchAreas; }
/// <summary> /// Constructor /// </summary> /// <param name="percussion">Percussion enumeration</param> /// <param name="sound">Cymbal sound</param> /// <param name="boundaries">Bounding box</param> /// <param name="touchAreas">List of rectangular touch areas</param> /// <param name="image">Cymbal image</param> public Drum(Percussion percussion, SoundEffect sound, Rectangle boundaries, List <Rectangle> touchAreas, Texture2D image) : base(percussion, sound, boundaries, touchAreas, image) { MaxMagnitude = -0.04f; Origin = new Vector2(boundaries.Width / 2, boundaries.Height / 2); shake = new TimerCallback(ShakeCallback); Played += new EventHandler(Drum_Played); }
public PercussionItem(Texture2D released, Texture2D pressed, Percussion percussion) : base(released, pressed, pressed) { Percussion = percussion; Clicked += new EventHandler(PercussionItem_Clicked); // Since only one percussion item can be selected at the time, a static Selected event // is used to notify other Percussion items to set themselves to unselected state Selected += new EventHandler(PercussionItem_Selected); }
/// <summary> /// Sends a Note On message to Channel10 of this MIDI output device. /// </summary> /// <param name="percussion">The percussion.</param> /// <param name="velocity">The velocity 0..127.</param> /// <remarks>This is simply shorthand for a Note On message on Channel10 with a /// percussion-specific note, so there is no corresponding message to receive from an input /// device.</remarks> /// <exception cref="ArgumentOutOfRangeException">percussion or velocity is out-of-range. /// </exception> /// <exception cref="InvalidOperationException">The device is not open.</exception> /// <exception cref="DeviceException">The message cannot be sent.</exception> public void SendPercussion(Percussion percussion, int velocity) { lock (this) { CheckOpen(); CheckReturnCode(Win32API.midiOutShortMsg(handle, ShortMsg.EncodeNoteOn( Channel.Channel10, (Pitch)percussion, velocity))); } }
/// <summary> /// Creates a new percussion note instance. /// </summary> /// <param name="start">The starting position of the note, in ticks, with 0 as the beginning of the measure.</param> /// <param name="percussion">The percussion voice played.</param> /// <param name="velocity">The Velocity of the note, 0-127.</param> public PercussionNote(double start, Percussion percussion, Velocity velocity) { Start = start; Percussion = percussion; Velocity = velocity; if ((int)velocity > 127 || (int)velocity < 0) { throw new Exception("Velocity must be between 0 and 127 inclusive."); } }
/// <summary> /// Constructs a Percussion message. /// </summary> /// <param name="device">The device associated with this message.</param> /// <param name="percussion">Percussion.</param> /// <param name="velocity">Velocity, 0..127.</param> /// <param name="time">The timestamp for this message.</param> public PercussionMessage(IDeviceBase device, Percussion percussion, int velocity, float time) : base(device, time) { percussion.Validate(); if (velocity < 0 || velocity > 127) { throw new ArgumentOutOfRangeException(nameof(velocity)); } Percussion = percussion; Velocity = velocity; }
/// <summary> /// Constructs a Percussion message. /// </summary> /// <param name="device">The device associated with this message.</param> /// <param name="percussion">Percussion.</param> /// <param name="velocity">Velocity, 0..127.</param> /// <param name="beatTime">Milliseconds since the music started.</param> public PercussionMessage(DeviceBase device, Percussion percussion, int velocity, float beatTime) : base(device, beatTime) { percussion.Validate(); if (velocity < 0 || velocity > 127) { throw new ArgumentOutOfRangeException("velocity"); } this.percussion = percussion; this.velocity = velocity; }
public override void Run() { OutputDevice outputDevice = ExampleUtil.ChooseOutputDeviceFromConsole(); char inp; int dx; Pitch[] notes=new Pitch[7] { Pitch.A4, Pitch.B4, Pitch.C4, Pitch.D4, Pitch.E4, Pitch.F4, Pitch.G4 }; Percussion[] drums=new Percussion[3] { Percussion.BassDrum1, Percussion.MidTom1, Percussion.CrashCymbal1 }; if(outputDevice==null) { Console.WriteLine("\nNo output devices, so can't run this example."); ExampleUtil.PressAnyKeyToContinue(); return; } if(!File.Exists(PiPath)) { Console.WriteLine("\nCould not find the data file: {0}", PiPath); ExampleUtil.PressAnyKeyToContinue(); return; } Console.WriteLine("This didn't turn out well at all. A back beat may help it but I'm moving on for now.\n\n"); Console.WriteLine("The follow 10 notes will be used:"); for(dx=0; dx<10 && Console.KeyAvailable==false; dx++) { if(dx>=notes.Length) { Console.WriteLine("\tDigit {0} is represented by a {1} drum.", dx, drums[dx-notes.Length].ToString()); } else { Console.WriteLine("\tDigit {0} is represented by a {1} note.", dx, notes[dx].ToString()); } } Console.WriteLine("Interpreting Pi...Press any key to stop...\n\n"); outputDevice.Open(); // outputDevice.SendProgramChange(Channel.Channel1, Instrument.AltoSax); outputDevice.SendControlChange(Channel.Channel1, Control.SustainPedal, 0); try { using(StreamReader sr=new StreamReader(PiPath)) { while(sr.Peek()>=0 && Console.KeyAvailable==false) { inp=(char)sr.Read(); if(Char.IsNumber(inp)) { // Skip over non numbers. Console.Write(inp); dx=(int)Char.GetNumericValue(inp); if(dx>=notes.Length) outputDevice.SendPercussion(drums[dx-notes.Length], 90); else outputDevice.SendNoteOn(Channel.Channel1, notes[dx], 80); Thread.Sleep(500); } } } } catch(FieldAccessException e) { Console.WriteLine("\nError: Could not access file {0}\n\nThe exception was: {1}\n", PiPath, e.Message); } catch(Exception e) { Console.WriteLine("\nError: {1}\n", PiPath, e.Message); } outputDevice.Close(); while(Console.KeyAvailable) { Console.ReadKey(false); } Console.WriteLine(); ExampleUtil.PressAnyKeyToContinue(); }
public override void Run() { // Utility function prompts user to choose an output device (or if there is only one, // returns that one). OutputDevice outputDevice = ExampleUtil.ChooseOutputDeviceFromConsole(); if (outputDevice == null) { Console.WriteLine("No output devices, so can't run this example."); ExampleUtil.PressAnyKeyToContinue(); return; } outputDevice.Open(); Console.WriteLine("Press alphabetic keys (with and without SHIFT) to play MIDI " + "percussion sounds."); Console.WriteLine("Press Escape when finished."); Console.WriteLine(); while (true) { ConsoleKeyInfo keyInfo = Console.ReadKey(true); if (keyInfo.Key == ConsoleKey.Escape) { break; } else if ((keyInfo.Modifiers & ConsoleModifiers.Shift) != 0) { if (shiftedNotes.ContainsKey(keyInfo.Key)) { Percussion note = shiftedNotes[keyInfo.Key]; Console.Write("\rNote {0} ({1}) ", (int)note, note.Name()); outputDevice.SendPercussion(note, 90); } } else { if (unshiftedNotes.ContainsKey(keyInfo.Key)) { Percussion note = unshiftedNotes[keyInfo.Key]; Console.Write("\rNote {0} ({1}) ", (int)note, note.Name()); outputDevice.SendPercussion(note, 90); } } } // Close the output device. outputDevice.Close(); // All done. }
public DrumStyle(SectionType type, double probabilityOfBlastbeats = 0) { _timeKeeper = GetTimeKeeper(type); Notes = new List <PercussionNote>(); if (Randomizer.ProbabilityOfTrue(probabilityOfBlastbeats) && (type == SectionType.Chorus || type == SectionType.Verse)) { _blast = true; } else if (Randomizer.ProbabilityOfTrue(probabilityOfBlastbeats)) { _doubleKick = true; } }
public Drummer(Clock clock, OutputDevice outputDevice, int beatsPerMeasure) { this.clock = clock; this.outputDevice = outputDevice; this.beatsPerMeasure = beatsPerMeasure; this.messagesForOneMeasure = new List <Message>(); for (int i = 0; i < beatsPerMeasure; ++i) { Percussion percussion = i == 0 ? Percussion.PedalHiHat : Percussion.MidTom1; int velocity = i == 0 ? 100 : 40; messagesForOneMeasure.Add(new PercussionMessage(outputDevice, percussion, velocity, i)); } messagesForOneMeasure.Add(new CallbackMessage( new CallbackMessage.CallbackType(CallbackHandler), 0)); clock.Schedule(messagesForOneMeasure, 0); }
public WoplFile(GlobalTimbreLibrary timbreLibrary) { Version = 3; GlobalFlags = GlobalBankFlags.DeepTremolo | GlobalBankFlags.DeepVibrato; VolumeModel = VolumeModel.Auto; Melodic.Add(new WoplBank { Id = 0, Name = "" }); Percussion.Add(new WoplBank { Id = 0, Name = "" }); for (int i = 0; i < timbreLibrary.Data.Count; i++) { var timbre = timbreLibrary.Data[i]; WoplInstrument x = i < 128 ? Melodic[0].Instruments[i] ?? new WoplInstrument() : Percussion[0].Instruments[i - 128 + 35] ?? new WoplInstrument(); x.Name = ""; x.NoteOffset1 = timbre.MidiPatchNumber; x.NoteOffset2 = timbre.MidiBankNumber; x.InstrumentMode = InstrumentMode.TwoOperator; x.FbConn1C0 = timbre.FeedbackConnection; x.Operator0 = timbre.Carrier; x.Operator1 = timbre.Modulation; x.Operator2 = Operator.Blank; x.Operator3 = Operator.Blank; if (i < 128) { Melodic[0].Instruments[i] = x; } else { Percussion[0].Instruments[i - 128 + 35] = x; } } }
static void Main(string[] args) { IDummy d = new Dumb(); d.Print(); d.Print(4); d.Print("Hello"); Console.WriteLine("------------------------------------------------------------------------------------------------------------"); D b = new ClassB(); M1(b); M2(b); M3(b); M4(b); ClassAbstract c = new ClassB(); c.PrintMe(); //GC.Collect(); //GC.WaitForPendingFinalizers(); IFastFood f = new Sandwich(); f.FastFood(); Console.WriteLine("------------------------------------------------------------------------------------------------------------"); Sandwich a = new Sandwich(); a.FastFood(); Console.WriteLine("------------------------------------------------------------------------------------------------------------"); IPlayableInstrument[] orchestra = new IPlayableInstrument[5]; int i = 0; orchestra[i++] = new Wind(); orchestra[i++] = new Percussion(); orchestra[i++] = new Stringed(); orchestra[i++] = new Brass(); orchestra[i++] = new Woodwind(); TuneAll(orchestra); }
private static int SortValue(Percussion p) { switch (p) { case Percussion.CrashCymbal1: case Percussion.CrashCymbal2: return(1); case Percussion.RideCymbal1: case Percussion.RideCymbal2: return(2); case Percussion.ClosedHiHat: case Percussion.OpenHiHat: case Percussion.PedalHiHat: return(3); case Percussion.HighTom1: case Percussion.HighTom2: return(4); case Percussion.MidTom1: case Percussion.MidTom2: return(5); case Percussion.LowTom1: case Percussion.LowTom2: return(6); case Percussion.SnareDrum1: case Percussion.SnareDrum2: return(7); case Percussion.BassDrum1: case Percussion.BassDrum2: return(8); } return(100); }
private static string PercussionCode(Percussion p) { switch (p) { case Percussion.BassDrum1: case Percussion.BassDrum2: return("B"); case Percussion.SnareDrum1: case Percussion.SnareDrum2: return("S"); case Percussion.CrashCymbal1: case Percussion.CrashCymbal2: return("C"); case Percussion.RideCymbal1: case Percussion.RideCymbal2: return("R"); case Percussion.ClosedHiHat: case Percussion.OpenHiHat: case Percussion.PedalHiHat: return("H"); case Percussion.HighTom1: case Percussion.HighTom2: return("Th"); case Percussion.MidTom1: case Percussion.MidTom2: return("Tm"); case Percussion.LowTom1: case Percussion.LowTom2: return("Tl"); } return("?"); }
/// <summary> /// Returns the human-readable name of a MIDI percussion. /// </summary> /// <param name="percussion">The percussion.</param> public static string Name(this Percussion percussion) { percussion.Validate(); return(PercussionNames[(int)percussion - 35]); }
/// <summary> /// Constructor /// </summary> /// <param name="percussion">Percussion enumeration</param> /// <param name="sound">Percussion sound</param> /// <param name="boundaries">Bounding box</param> /// <param name="touchAreas">List of rectangular touch areas</param> /// <param name="image">Cymbal image</param> public Pad(Percussion percussion, SoundEffect sound, Rectangle boundaries, List<Rectangle> touchAreas, Texture2D image) : this(percussion, sound, boundaries, touchAreas) { this.image = image; }
/// <summary> /// Constructor /// </summary> /// <param name="percussion">Percussion enumeration</param> /// <param name="sound">Percussion sound</param> /// <param name="boundaries">Bounding box</param> /// <param name="touchAreas">List of rectangular touch areas</param> /// <param name="image">Cymbal image</param> public Pad(Percussion percussion, SoundEffect sound, Rectangle boundaries, List <Rectangle> touchAreas, Texture2D image) : this(percussion, sound, boundaries, touchAreas) { this.image = image; }
public override void Run() { // Prompt the user to choose an output device (or if there is only one, use that one). OutputDevice outputDevice = ExampleUtil.ChooseOutputDeviceFromConsole(); if (outputDevice == null) { Console.WriteLine("No output devices, so can't run this example."); ExampleUtil.PressAnyKeyToContinue(); return; } outputDevice.Open(); // Generate two maps from console keys to percussion sounds: one for when alphabetic // keys are pressed and one for when they're pressed with shift. Dictionary <ConsoleKey, Percussion> unshiftedKeys = new Dictionary <ConsoleKey, Percussion>(); Dictionary <ConsoleKey, Percussion> shiftedKeys = new Dictionary <ConsoleKey, Percussion>(); for (int i = 0; i < 26; ++i) { unshiftedKeys[QwertyOrder[i]] = Percussion.BassDrum1 + i; if (i < 20) { shiftedKeys[QwertyOrder[i]] = Percussion.BassDrum1 + 26 + i; } } Console.WriteLine("Press alphabetic keys (with and without SHIFT) to play MIDI " + "percussion sounds."); Console.WriteLine("Press Escape when finished."); Console.WriteLine(); while (true) { ConsoleKeyInfo keyInfo = Console.ReadKey(true); if (keyInfo.Key == ConsoleKey.Escape) { break; } else if ((keyInfo.Modifiers & ConsoleModifiers.Shift) != 0) { if (shiftedKeys.ContainsKey(keyInfo.Key)) { Percussion note = shiftedKeys[keyInfo.Key]; Console.Write("\rNote {0} ({1}) ", (int)note, note.Name()); outputDevice.SendPercussion(note, 90); } } else { if (unshiftedKeys.ContainsKey(keyInfo.Key)) { Percussion note = unshiftedKeys[keyInfo.Key]; Console.Write("\rNote {0} ({1}) ", (int)note, note.Name()); outputDevice.SendPercussion(note, 90); } } } // Close the output device. outputDevice.Close(); // All done. }
/// <summary> /// Constructs a Percussion message. /// </summary> /// <param name="device">The device associated with this message.</param> /// <param name="percussion">Percussion.</param> /// <param name="velocity">Velocity, 0..127.</param> /// <param name="time">The timestamp for this message.</param> public PercussionMessage(DeviceBase device, Percussion percussion, int velocity, float time) : base(device, time) { percussion.Validate(); if (velocity < 0 || velocity > 127) { throw new ArgumentOutOfRangeException("velocity"); } this.percussion = percussion; this.velocity = velocity; }
public FillSection(Percussion note, double length) { Note = note; Length = length; }
public static void Do(Action quit) { OutputDevice outputDevice = OutputDevice.InstalledDevices[0]; outputDevice.Open(); Hook.GlobalEvents().KeyPress += (sender, e) => { mostRecent += e.KeyChar; mostRecent = mostRecent.TruncateStart(20).ToLower(); if (e.KeyChar >= '0' && e.KeyChar <= '9') { Percussion percussion = Percussion.BassDrum1; switch (e.KeyChar) { case '0': percussion = Percussion.BassDrum2; break; case '1': percussion = Percussion.Cowbell; break; case '2': percussion = Percussion.CrashCymbal1; break; case '3': percussion = Percussion.HandClap; break; case '4': percussion = Percussion.HighTom1; break; case '5': percussion = Percussion.HighWoodBlock; break; case '6': percussion = Percussion.LowWoodBlock; break; case '7': percussion = Percussion.Maracas; break; case '8': percussion = Percussion.OpenTriangle; break; case '9': percussion = Percussion.SnareDrum1; break; case '-': case '_': percussion = Percussion.BassDrum2; break; case '=': case '+': percussion = Percussion.BassDrum2; break; } Console.WriteLine(percussion.ToString()); outputDevice.SendPercussion(percussion, 80); } else { Pitch pitch = Pitch.C4; switch (e.KeyChar) { case 'z': case 'Z': pitch = Pitch.F3; break; case 'x': case 'X': pitch = Pitch.G3; break; case 'c': case 'C': pitch = Pitch.A4; break; case 'v': case 'V': pitch = Pitch.B4; break; case 'b': case 'B': pitch = Pitch.C4; break; case 'n': case 'N': pitch = Pitch.D4; break; case 'm': case 'M': pitch = Pitch.E4; break; case ',': case '<': pitch = Pitch.F4; break; case '.': case '>': pitch = Pitch.G4; break; case '/': case '?': pitch = Pitch.A5; break; case 'a': case 'A': pitch = Pitch.F3; break; case 's': case 'S': pitch = Pitch.G3; break; case 'd': case 'D': pitch = Pitch.A4; break; case 'f': case 'F': pitch = Pitch.B4; break; case 'g': case 'G': pitch = Pitch.C4; break; case 'h': case 'H': pitch = Pitch.D4; break; case 'j': case 'J': pitch = Pitch.E4; break; case 'k': case 'K': pitch = Pitch.F4; break; case 'l': case 'L': pitch = Pitch.G4; break; case ';': case ':': pitch = Pitch.A5; break; case 'q': case 'Q': pitch = Pitch.DSharp3; break; case 'w': case 'W': pitch = Pitch.FSharp3; break; case 'e': case 'E': pitch = Pitch.ASharp3; break; case 'r': case 'R': pitch = Pitch.ASharp3; break; case 't': case 'T': pitch = Pitch.CSharp4; break; case 'y': case 'Y': pitch = Pitch.DSharp4; break; case 'u': case 'U': pitch = Pitch.DSharp4; break; case 'i': case 'I': pitch = Pitch.FSharp4; break; case 'o': case 'O': pitch = Pitch.GSharp4; break; case 'p': case 'P': pitch = Pitch.ASharp5; break; case '[': case '{': pitch = Pitch.ASharp5; break; case ']': case '}': pitch = Pitch.CSharp5; break; } Console.WriteLine(pitch.ToString()); foreach (var instrument in Enum.GetValues(typeof(Instrument))) { if (mostRecent.EndsWith(instrument.ToString().ToLower())) { outputDevice.SendProgramChange(Channel.Channel1, (Instrument)instrument); Console.WriteLine(instrument.ToString()); } } outputDevice.SendNoteOn(Channel.Channel1, pitch, 80); // Middle C, velocity 80 outputDevice.SendPitchBend(Channel.Channel1, 7000); // 8192 is centered, so 7000 is bent down Task.Run(() => { Thread.Sleep(200); outputDevice.SendNoteOff(Channel.Channel1, pitch, 80); }); } }; }
/// <summary> /// Returns true if the specified percussion is valid. /// </summary> /// <param name="percussion">The percussion to test.</param> public static bool IsValid(this Percussion percussion) { return((int)percussion >= 35 && (int)percussion <= 81); }