示例#1
0
文件: IO.cs 项目: mattsains/midImprov
        /// <summary>
        /// Gets notes from a file in the following format:
        /// Cm,1 (1=number of beats)
        /// E,3
        /// F#m,4
        /// </summary>
        /// <param name="filepath">the path to the file.</param>
        /// <returns>true if success, false if fail.</returns>
        public bool GetFromCSV(string filepath)
        {
            StreamReader file = new StreamReader(filepath);
            string line = "";
            song.Clear(); //make way for new notes

            while ((line = file.ReadLine()) != null) //while getting a new line doens't fail
            {
                string note, mode;
                string[] parms= line.Split(',');
                string key = parms[0];
                string len = parms[1];

                if (key.Length > 1)
                {
                    if (key[1] == '#') { note = key.Substring(0, 2); key = key.Substring(2); }
                    else { note = key.Substring(0, 1); key = key.Substring(1); }
                }
                else { note = key[0].ToString(); key = key.Substring(1); }

                if (key.Length > 0) { mode = key; }
                else { mode = "M"; }
                Keys k = new Keys(note, mode);
                byte l =byte.Parse(len);
                song.Add(new Tuple<Keys,byte>(k,l));
            }
            return true;
        }
示例#2
0
文件: IO.cs 项目: mattsains/midImprov
        private void play_chord(Keys k, int t)
        {
            int n1 = (int)Mozart.Component(k, 1) + 57;
            int n2 = (int)Mozart.Component(k, 3) + 57;
            int n3 = (int)Mozart.Component(k, 5) + 57;

            while (n1 < low) { n1 += 12; }
            while (n2 < n1) { n2 += 12; }
            while (n3 < n2) { n3 += 12; }

            ChannelMessageBuilder builder = new ChannelMessageBuilder();
            builder.Command = ChannelCommand.NoteOn;
            builder.MidiChannel = 0;
            builder.Data1 = n1;
            builder.Data2 = 127;
            builder.Build();
            outDevice.Send(builder.Result);

            builder.Command = ChannelCommand.NoteOn;
            builder.MidiChannel = 0;
            builder.Data1 = n2;
            builder.Data2 = 127;
            builder.Build();
            outDevice.Send(builder.Result);

            builder.Command = ChannelCommand.NoteOn;
            builder.MidiChannel = 0;
            builder.Data1 = n3;
            builder.Data2 = 127;
            builder.Build();
            outDevice.Send(builder.Result);

            System.Threading.Thread.Sleep(t);

            builder.Command = ChannelCommand.NoteOff;
            builder.MidiChannel = 0;
            builder.Data1 = n1;
            builder.Data2 = 127;
            builder.Build();
            outDevice.Send(builder.Result);

            builder.Command = ChannelCommand.NoteOff;
            builder.MidiChannel = 0;
            builder.Data1 = n2;
            builder.Data2 = 127;
            builder.Build();
            outDevice.Send(builder.Result);

            builder.Command = ChannelCommand.NoteOff;
            builder.MidiChannel = 0;
            builder.Data1 = n3;
            builder.Data2 = 127;
            builder.Build();
            outDevice.Send(builder.Result);
        }
示例#3
0
 /// <summary>
 /// gives a specific note of a scale
 /// </summary>
 /// <param name="key">The key to select the component from</param>
 /// <param name="interval">the interval to select. 1=root, 5=fifth, etc</param>
 /// <returns>the note offset from middle A (57)</returns>
 public static byte Component(Keys key, int interval)
 {
     interval = ((interval - 1) % 7) + 1;//translate octaves back onto the domain of this function
     byte note = (byte)key.note;
     switch (interval)
     {
         case 2: note += 2; break;
         case 3:
             switch (key.mode)
             {
                 case Mode.Major: note += 4; break;
                 case Mode.Minor:
                 case Mode.Diminished: note += 3; break;
             } break;
         case 4: note += 5; break;
         case 5:
             switch (key.mode)
             {
                 case Mode.Diminished: note += 6; break;
                 case Mode.Minor:
                 case Mode.Major: note += 7; break;
             } break;
         case 6:
             switch (key.mode)
             {
                 case Mode.Minor:
                 case Mode.Diminished: note += 8; break;
                 case Mode.Major: note += 9; break;
             } break;
         case 7: note += 11; break;
         case 8: note = (byte)(Component(key, interval) + 12); break;
     }
     note %= 12;
     return note;
 }