You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCETICE project - Copyright 2009 by Lucio Asnaghi.
  4. JUCETICE is based around the JUCE library - "Jules' Utility Class Extensions"
  5. Copyright 2007 by Julian Storer.
  6. ------------------------------------------------------------------------------
  7. JUCE and JUCETICE can be redistributed and/or modified under the terms of
  8. the GNU General Public License, as published by the Free Software Foundation;
  9. either version 2 of the License, or (at your option) any later version.
  10. JUCE and JUCETICE are distributed in the hope that they will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with JUCE and JUCETICE; if not, visit www.gnu.org/licenses or write to
  16. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  17. Boston, MA 02111-1307 USA
  18. ==============================================================================
  19. */
  20. BEGIN_JUCE_NAMESPACE
  21. //==============================================================================
  22. PianoGridKeyboard::PianoGridKeyboard (MidiKeyboardState& state)
  23. : MidiKeyboardComponent (state, MidiKeyboardComponent::verticalKeyboardFacingRight)
  24. {
  25. }
  26. PianoGridKeyboard::~PianoGridKeyboard()
  27. {
  28. }
  29. //==============================================================================
  30. void PianoGridKeyboard::getKeyPosition (int midiNoteNumber, float keyWidth, int& x, int& w) const
  31. {
  32. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  33. static const float blackNoteWidth = 0.7f;
  34. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  35. 1.0f, 2 - blackNoteWidth * 0.4f,
  36. 2.0f,
  37. 3.0f, 4 - blackNoteWidth * 0.7f,
  38. 4.0f, 5 - blackNoteWidth * 0.5f,
  39. 5.0f, 6 - blackNoteWidth * 0.3f,
  40. 6.0f };
  41. static const float widths[] = { 1.0f, blackNoteWidth,
  42. 1.0f, blackNoteWidth,
  43. 1.0f,
  44. 1.0f, blackNoteWidth,
  45. 1.0f, blackNoteWidth,
  46. 1.0f, blackNoteWidth,
  47. 1.0f };
  48. const int octave = midiNoteNumber / 12;
  49. const int note = midiNoteNumber % 12;
  50. x = roundFloatToInt ((octave * 7.0f * keyWidth) + notePos [note] * keyWidth);
  51. w = roundFloatToInt (widths [note] * keyWidth);
  52. }
  53. String PianoGridKeyboard::getWhiteNoteText (const int midiNoteNumber)
  54. {
  55. if (midiNoteNumber % 12 == 0)
  56. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, getOctaveForMiddleC ());
  57. return String();
  58. }
  59. //==============================================================================
  60. void PianoGridKeyboard::mouseWheelMove (const MouseEvent&, const MouseWheelDetails& wheel)
  61. {
  62. int newNote = getLowestVisibleKey();
  63. if ((wheel.deltaX != 0 ? wheel.deltaX : wheel.deltaY) < 0)
  64. newNote = (newNote - 1) / 12;
  65. else
  66. newNote = newNote / 12 + 1;
  67. setLowestVisibleKey (newNote * 12);
  68. }
  69. END_JUCE_NAMESPACE