Esempio n. 1
0
 public CompressedNoteDuration(float start, float dur, PianoKey key)
 {
     this.start = start;
     end        = start + dur;
     keyNum     = key.keyNum;
     duration   = dur;
 }
 private void OnPianoKeyPressed(PianoKey key)
 {
     if (PianoKeyPressed != null)
     {
         PianoKeyPressed(this, new PianoKeyPressedEventArgs(key));
     }
 }
Esempio n. 3
0
        void CreatePianoKeys()
        {
            // If piano keys have already been created.
            if (keys != null)
            {
                // Remove and dispose of current piano keys.
                foreach (PianoKey key in keys)
                {
                    Controls.Remove(key);
                    key.Dispose();
                }
            }

            keys = new PianoKey[HighNoteID - LowNoteID + 1];

            WhiteKeyCount = 0;

            for (int i = 0; i < keys.Length; i++)
            {
                keys[i] = new PianoKey(this, i + LowNoteID);

                if (KeyTypeTable[keys[i].NoteID % 12] == KeyType.White)
                {
                    WhiteKeyCount++;
                }
                else
                {
                    keys[i].BringToFront();
                }

                keys[i].NoteOnColor = NoteOnColor;
                Controls.Add(keys[i]);
            }
        }
Esempio n. 4
0
 /**
  * @brief Handles a white key in the container being released.
  * @param[in] aWhiteKey The white key that was released.
  */
 private void HandlePianoKeyReleased(PianoKey aPianoKey)
 {
     if (EnableAudio && mVIM != null)
     {
         mVIM.ReleaseNote.Invoke(aPianoKey.Pitch);
     }
 }
        private void DrawKeys()
        {
            LayoutRoot.Children.Clear();
            double cursorX = 0;

            for (int pitch = StartingMidiPitch; pitch < StartingMidiPitch + NumberOfKeys; pitch++)
            {
                PianoKeyType keyType = KeyTypes[pitch % 12];

                double keyHeight = KeyHeight;
                int    zIndex    = 0;
                if (keyType == PianoKeyType.Small)
                {
                    keyHeight = KeyHeight * 0.6d;
                    zIndex    = 10;
                }

                PianoKey button = new PianoKey();
                button.MidiPitch = pitch;
                button.Width     = keyType == PianoKeyType.Large ? KeyWidth : KeyWidth / 2;
                button.Height    = keyHeight;
                button.Style     = keyType == PianoKeyType.Large ? LargeKeyStyle : SmallKeyStyle;
                button.Click    += button_Click;

                Canvas.SetLeft(button, pitch > StartingMidiPitch && keyType == PianoKeyType.Small ? cursorX - KeyWidth / 4 : cursorX);
                Canvas.SetZIndex(button, zIndex);
                LayoutRoot.Children.Add(button);

                if (keyType == PianoKeyType.Large)
                {
                    cursorX += KeyWidth;
                }
            }
        }
Esempio n. 6
0
 void Init()
 {
     //加载小人
     LoadPersonSetPos();
     SelectSong();
     //8个琴键脚本,8个琴键提示动画
     for (int i = 0; i < Keys.childCount; i++)
     {
         //琴键
         Transform key = Keys.GetChild(i);
         PianoKey  pk  = key.GetComponentInChildren <PianoKey>();
         pk.Init(i);
         pianoKeys.Add(pk);
         //Audio
         audioSources.Add(key.GetComponentInChildren <AudioSource>());
         //提示动画
         Animation ani = key.GetComponentInChildren <Animation>(true);
         pianoKeyAnimations.Add(ani);
         //提示物体
         GameObject reminder = key.Find("reminder").gameObject;
         reminder.SetActive(false);
         Image img_reminder = reminder.GetComponent <Image>();
         reminders.Add(img_reminder);
         //粒子特效
         ParticleSystem ps = key.GetComponentInChildren <ParticleSystem>();
         particles.Add(ps);
     }
     //按钮点击
     AddClickEvent();
 }
Esempio n. 7
0
    private void InitializePianoKeyDataByKeyType(string keyType)
    {
        int index = 0;

        while (index > -1)
        {
            //For each white piano key
            GameObject pianoKey;
            if (index == 0)
            {
                pianoKey = GameObject.Find(keyType);
            }
            else
            {
                pianoKey = GameObject.Find(keyType + " (" + index + ")");
            }

            if (pianoKey != null)
            {
                PianoKey pkScript = (PianoKey)pianoKey.GetComponent(typeof(PianoKey));
                if (pkScript != null)
                {
                    GetPianoKeyScript(pkScript);
                    GetPianoKeyNote(pkScript);
                }
            }
            else
            {
                break;
            }
            index++;
        }
    }
Esempio n. 8
0
    void Awake()
    {
        if (Sort)
        {
            Regex sortReg = new Regex(@Regex);
            Notes = Notes.OrderBy(note => sortReg.Match(note.name).Value).ToArray();
        }

        var count = 0;

        for (int i = 0; i < PianoKeysParent.childCount; i++)
        {
            AudioSource keyAudioSource = PianoKeysParent.GetChild(i).GetComponent <AudioSource>();

            if (keyAudioSource)
            {
                PianoKey pianoKey = PianoKeysParent.GetChild(i).GetComponent <PianoKey>();

                keyAudioSource.clip = Notes[count];
                PianoNotes.Add(KeyString(count + Array.IndexOf(_keyIndex, StartKey)), pianoKey);
                pianoKey.PianoKeyController = this;

                count++;
            }
        }
    }
Esempio n. 9
0
        private void SetKeySizes()
        {
            WhiteKeyWidth = Width / WhiteKeyCount;
            int blackKeyWidth  = (int)(WhiteKeyWidth * blackKeyScale);
            int blackKeyHeight = (int)(Height * blackKeyScale);
            int offset         = WhiteKeyWidth - (blackKeyWidth / 2);
            int w = 0;

            for (int k = 0; k <= 0x7F; k++)
            {
                PianoKey key = Keys[k];
                if (KeyTypeTable[k % 12] == KeyType.White)
                {
                    key.Height   = Height;
                    key.Width    = WhiteKeyWidth;
                    key.Location = new Point(w * WhiteKeyWidth, 0);
                    w++;
                }
                else
                {
                    key.Height   = blackKeyHeight;
                    key.Width    = blackKeyWidth;
                    key.Location = new Point(offset + ((w - 1) * WhiteKeyWidth));
                    key.BringToFront();
                }
            }
        }
Esempio n. 10
0
    private void meshMake(PianoKey pianoKey)
    {
        Color c = NoteDecorator.pitchToColor(pianoKey.pitch);
        matBlock.Clear();
        matBlock.AddColor(colorId, c);

        int degree = 360 / spawns;
        for (int iter = 0; iter < spawns; iter++)
        {
            var pos = transform.position;
            var rot = transform.rotation;
            GameObject obj = Instantiate(legacyParticleSystem, pos, rot) as GameObject;
            obj.transform.RotateAround(pos, rot * Vector3.up,
                NoteDecorator.midiToDegree(pianoKey.midiCode, degree) + iter * degree);

            ParticleRenderer pr = obj.GetComponent<ParticleRenderer>();
            pr.SetPropertyBlock(matBlock);

            float f = pianoKey.force;
            ParticleEmitter pe = obj.GetComponent<ParticleEmitter>();
            pe.maxSize *= forceAffectSize * f;
            pe.maxEmission *= forceAffectNum * f;

            obj.SetActive(true);
        }
    }
Esempio n. 11
0
 public NoteDuration(float start, float dur, PianoKey key)
 {
     hasKeyBeenActivated = false;
     this.start          = start;
     end      = start + dur;
     keyNum   = key.keyNum;
     duration = dur;
 }
Esempio n. 12
0
    public void pianoKeyDown(PianoKeyEventArgs k)
    {
        if (PianoKeyDown == null) return;
        PianoKeyDown(this, k);

        if (lastKey != null)
            intervalPlayed(new IntervalEventArgs(lastKey, k.key));
        lastKey = k.key;
    }
Esempio n. 13
0
 private void Awake()
 {
     this.audioSource      = this.gameObject.AddComponent <AudioSource>();
     this.audioSource.clip = this.clip;
     this.pianoKey         = new PianoKey(this as IPianoKeyController);
     this.currentButton    = this.gameObject.GetComponent <Button>();
     this.pianoKeyImage    = this.gameObject.GetComponent <Image>();
     this.originalColor    = this.pianoKeyImage.color;
 }
Esempio n. 14
0
 public void Begin(PianoKey key)
 {
     if (IsVertical)
     {
         Offset = BarLength - GetOffsetFromZero(key) - BoxHeight;
         return;
     }
     Offset = GetOffsetFromMin(key);
 }
Esempio n. 15
0
    public void replayFirstMissingNote()
    {
        if (currentlyPlaying)
        {
            return;
        }

        audioSource.pitch = PianoKey.calcPitch((int)problemSequence[currentMissingNote].note, problemSequence[currentMissingNote].octaveShift);
        audioSource.Play();
    }
Esempio n. 16
0
    public IEnumerator playProblem(ProblemNote[] problem)
    {
        for (int i = 0; i < problem.Length; i++)
        {
            audioSource.pitch = PianoKey.calcPitch((int)problem[i].note, problem[i].octaveShift);
            audioSource.Play();
            yield return(new WaitForSeconds(noteDelay));
        }

        currentlyPlaying = false;
    }
        IDisposable SetupSpawnNodeStream(PianoKey key)
        {
            var result = key.IsPressingReactiveProperty
                         .Where(pressing => pressing)
                         .Select(_ => key.Velocity)
                         .Subscribe(velocity =>
            {
            });

            return(result);
        }
Esempio n. 18
0
    /**
     * @brief Handles a key in the container being pressed.
     * @param[in] aPianoKey The white key that was pressed.
     */
    private void HandleKeyPressed(PianoKey aPianoKey, int aNoteVelocity)
    {
        if (EnableAudio && mVIM != null)
        {
            #if DEBUG_AUDIO_DIAGNOSTICS
            mVIM.GetDiagnosticsHandler().SetInputTime.Invoke();
            #endif

            mVIM.PlayNote.Invoke(aPianoKey.Pitch, aNoteVelocity);
        }
    }
Esempio n. 19
0
        public void Piano_FindKey_WhenKeyDoesNotExist_ShouldReturnNull()
        {
            // Arrange
            Piano p = new Piano();

            // Act
            PianoKey pk = p.FindKey(4, "Q", false);

            // Assert
            Assert.IsNull(pk);
        }
Esempio n. 20
0
        private void CreatePianoKeys()
        {
            // If piano keys have already been created.
            if (keys != null)
            {
                // Remove and dispose of current piano keys.
                foreach (PianoKey key in keys)
                {
                    Controls.Remove(key);
                    key.Dispose();
                }
            }

            keys     = new PianoKey[1 + HighNoteID - LowNoteID];
            KeyCount = 1 + HighNoteID - LowNoteID;              // Total number of keys

            whiteKeyCount = 0;


            for (int i = 0; i < keys.Length; i++)
            {
                keys[i] = new PianoKey(this);

                if (_orientation == Orientation.Horizontal)
                {
                    keys[i].NoteID = i + LowNoteID;  // from bass to trebble for horizontal view
                }
                else
                {
                    keys[i].NoteID = highNoteID - i;  // from trebble to bass for vertical view
                }
                int note = keys[i].NoteID;


                if (KeyTypeTable[note] == KeyType.White)
                {
                    whiteKeyCount++;
                }
                else
                {
                    keys[i].NoteOffColor = Color.Black;
                    keys[i].BringToFront();
                }

                keys[i].NoteOnColor = NoteOnColor;

                int idx    = note % 12;
                int octave = (note + 3) / 12 - 1;

                keys[i].NoteLetter = NotesTable[idx] + octave.ToString();

                Controls.Add(keys[i]);
            }
        }
Esempio n. 21
0
        public PianoKey[] GetNextKeyLine(int numberInWidth, Note note)
        {
            var keyLine = new PianoKey[numberInWidth];

            for (var i = 0; i < numberInWidth; i++)
            {
                keyLine[i] = new PianoKey();
            }
            keyLine[0] = new PianoKey(note);
            return(keyLine);
        }
Esempio n. 22
0
 public double GetKeyWidth(PianoKey key)
 {
     if (key.Scale > 0)
     {
         return(BlackKeyWidth);
     }
     if (!IsSameGap)
     {
         return(WhiteKeyWidth);
     }
     return((IsLargeWhiteKey(key) ? 2 : 1.5) * BlackKeyWidth);
 }
Esempio n. 23
0
        public double GetOffsetFromZero(PianoKey key)
        {
            var bw = BlackKeyWidth;

            if (IsSameGap)
            {
                return(key.ToKey127() * BlackKeyWidth -
                       (key.Scale == 0 && key.Code != 1 && key.Code != 4 ? .5 * bw : 0));
            }
            var ww = WhiteKeyWidth;

            return(((key.Beat + 4) * 7 + key.Code - 1) * ww + (key.Scale > 0 ? (ww - bw / 2) : 0));
        }
Esempio n. 24
0
        public void Piano_FindKey_WhenKeyExists_ShouldReturnKey()
        {
            // Arrange
            Piano p = new Piano();

            // Act
            PianoKey pk = p.FindKey(4, "C", false);

            // Assert
            Assert.AreEqual("C", pk.Name);
            Assert.AreEqual(4, pk.Octave);
            Assert.AreEqual(false, pk.Black);
        }
Esempio n. 25
0
        /// <summary>
        /// 获取每一个的值,
        /// </summary>
        /// <param name="key"></param>
        /// <returns>[left,top,width, height]</returns>
        public double[] Invalidate(PianoKey key)
        {
            Invalidate();
            var x = GetOffsetFromMin(key);
            var y = .0;
            var w = GetKeyWidth(key);
            var h = key.Scale > 0 ? BlackKeyHeight : WhiteKeyHeight;

            if (IsHorizontal)
            {
                return(new double[] { x - Offset, y, w, h });
            }
            return(new double[] { y, BarLength - Offset - x - w, h, w });
        }
        void button_Click(object sender, RoutedEventArgs e)
        {
            PianoKey key = sender as PianoKey;

            OnPianoKeyPressed(key);
            if (PianoKeyPressedCommand == null)
            {
                return;
            }
            if (!PianoKeyPressedCommand.CanExecuteCommand(key))
            {
                return;
            }
            PianoKeyPressedCommand.ExecuteCommand(key);
        }
Esempio n. 27
0
 public PianoControl()
 {
     SetStyle(ControlStyles.Selectable, false);
     for (byte k = 0; k <= 0x7F; k++)
     {
         var key = new PianoKey(k);
         Keys[k] = key;
         if (KeyTypeTable[k % 12] == KeyType.Black)
         {
             key.BringToFront();
         }
         Controls.Add(key);
     }
     SetKeySizes();
 }
Esempio n. 28
0
        private void CreatePianoKey(Transform parent, PianoKeyColor pianoKeyColor, int midiNote, float distanceBetweenWhiteKeys)
        {
            PianoKeyObjectSettings pianoKeyObjectSettings = GetPianoKeyObjectSettings(pianoKeyColor);
            Vector3 position = GetPosition(pianoKeyColor, pianoKeyObjectSettings, distanceBetweenWhiteKeys);

            GameObject pianoKeyObject = PrefabUtility.InstantiatePrefab(pianoKeyObjectSettings.prefab) as GameObject;

            pianoKeyObject.transform.parent        = parent;
            pianoKeyObject.transform.localPosition = position;
            pianoKeyObject.transform.localRotation = Quaternion.identity;

            //PianoKey pianoKey = pianoKeyObject.GetComponent<PianoKey>();
            PianoKey pianoKey = pianoKeyObject.GetComponentInChildren <PianoKey>();

            pianoKey.SetMidiPlayer(midiPlayer);
            pianoKey.SetMidiNote(midiNote);
        }
Esempio n. 29
0
        public void Piano_Enable_WhenKeyExists_ShouldSetEnabledToTrue()
        {
            // Arrange
            Piano  p       = new Piano();
            int    oct     = Piano.BASE_OCTAAF;
            string letter  = "C";
            bool   special = false;

            // Act
            p.Enable(oct, letter, special);

            // Assert
            PianoKey pk = p.FindKey(oct, letter, special);

            Assert.IsNotNull(pk);
            Assert.IsTrue(pk.Enabled);
        }
Esempio n. 30
0
        public void TestDraw()
        {
            var helper = new PianoDraw()
            {
                BoxWidth       = 200,
                BoxHeight      = 200,
                BlackKeyHeight = 50,
                WhiteKeyHeight = 100,
                WhiteKeyWidth  = 60,
                BlackKeyWidth  = 30,
                Min            = PianoKey.Create127(0),
                Max            = PianoKey.Create127(131),
                Offset         = -61
            };
            var key = helper.Get(0);

            Assert.AreEqual(key.ToKey127(), (byte)1);
        }
Esempio n. 31
0
        public void Piano_ResetAll()
        {
            // Arrange
            Piano  p       = new Piano();
            int    oct     = Piano.BASE_OCTAAF;
            string letter  = "C";
            bool   special = false;

            // Act
            p.Enable(oct, letter, special);
            p.ResetAll();

            // Asset
            PianoKey pk = p.FindKey(oct, letter, special);

            Assert.IsNotNull(pk);
            Assert.IsFalse(pk.Enabled);
        }
Esempio n. 32
0
    // CLASS FUNCTIONS
    void generatePianoUI()
    {
        int        whiteKeyIndex = 0;
        int        blackKeyIndex = 0;
        Vector2    prevPos       = Vector2.zero;
        GameObject tmp           = Instantiate(whiteKeyPrefab);
        float      whiteKeyWidth = tmp.GetComponent <RectTransform>().rect.width;

        Destroy(tmp);
        for (int i = 21; i <= 108; ++i)
        {
            if (!MusicSheet.getNoteNameByNumber(i).Contains("#"))
            {
                PianoKey key = Instantiate(whiteKeyPrefab, transform).GetComponent <PianoKey>();
                key.number = i;
                key.GetComponent <RectTransform>().localPosition = new Vector2(key.GetComponent <RectTransform>().rect.width *whiteKeyIndex - 960, 0);
                keyDict[i] = key;
                whiteKeyIndex++;
            }
            else
            {
                PianoKey key = Instantiate(blackKeyPrefab, transform).GetComponent <PianoKey>();
                key.number = i;
                if (i == 22)
                {
                    key.GetComponent <RectTransform>().localPosition = new Vector2(whiteKeyWidth - key.GetComponent <RectTransform>().rect.width * 0.5f - 960, 0);
                }
                else
                {
                    if (blackKeyIndex % 5 == 1 || blackKeyIndex % 5 == 3)
                    {
                        key.GetComponent <RectTransform>().localPosition = new Vector2(prevPos.x + 2 * whiteKeyWidth, 0);
                    }
                    else if (blackKeyIndex % 5 == 0 || blackKeyIndex % 5 == 2 || blackKeyIndex % 5 == 4)
                    {
                        key.GetComponent <RectTransform>().localPosition = new Vector2(prevPos.x + whiteKeyWidth, 0);
                    }
                }
                prevPos    = key.GetComponent <RectTransform>().localPosition;
                keyDict[i] = key;
                blackKeyIndex++;
            }
        }
    }
Esempio n. 33
0
 public PianoKeyEventArgs(PianoKey k)
 {
     key = k;
 }
Esempio n. 34
0
 // public float timeBetween
 public IntervalEventArgs(PianoKey last, PianoKey next)
 {
     lastKey = last;
     newKey = next;
     intervalFrequency = next.midiCode - last.midiCode;
 }
Esempio n. 35
0
        private void CreatePianoKeys()
        {
            // If piano keys have already been created.
            if(keys != null)
            {
                // Remove and dispose of current piano keys.
                foreach(PianoKey key in keys)
                {
                    Controls.Remove(key);
                    key.Dispose();
                }
            }

            keys = new PianoKey[HighNoteID - LowNoteID];

            whiteKeyCount = 0;

            for(int i = 0; i < keys.Length; i++)
            {
                keys[i] = new PianoKey(this);
                keys[i].NoteID = i + LowNoteID;

                if(KeyTypeTable[keys[i].NoteID] == KeyType.White)
                {
                    whiteKeyCount++;
                }
                else
                {
                    keys[i].NoteOffColor = Color.Black;
                    keys[i].BringToFront();
                }

                keys[i].NoteOnColor = NoteOnColor;

                Controls.Add(keys[i]);
            }
        }
Esempio n. 36
0
    private void debug()
    {
        // Test call to piano key down
        musicEvents.pianoKeyDown(new PianoKeyEventArgs(new PianoKey(60)));

        // Debugging statements.
        print("Version: " + Environment.Version.ToString());
        var key = new PianoKey(Pitch.C, 4, 0.4f);
        print("Test: 60   ? = ?   " + key.midiCode.ToString());
        print("Running test methods.");
        PianoKey.TestMIDIMethods();

        //print("Testing .NET and C# features. Next - LINQ");

        //int[] ints = { 1, 2, 3, 4, 5 };
        //var q = from i in ints
        //        select new { i };
        //foreach (var v in q)
        //{
        //    Debug.Log(v);
        //}
    }