亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? keyboard.java

?? 如果你想在自己的計算機游戲中創建音樂編輯器
?? JAVA
字號:
// Keyboard.java

/*
 * Portions of Keyboard's source code were excerpted from Sun's MidiSynth.java 
 * source file. I've included Sun's original copyright and license, to be fair
 * to Sun.
 *
 * Copyright (c) 1999 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT
 * BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
 * MODIFYING OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
 * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES,
 * HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
 * THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or
 * in the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */

import java.awt.*;
import java.awt.event.*;
import java.util.Vector;

import javax.sound.midi.*;
import javax.swing.*;

/*
   This class creates a keyboard component that knows how to play a specific 
   instrument.
*/

public class Keyboard extends JPanel
{
   public final static Color KEY_BLUE = new Color (204, 204, 255);

   public final static int KEY_HEIGHT = 80, KEY_WIDTH = 16;

   private Key theKey;

   private MidiChannel channel;

   private Synthesizer synthesizer;

   private Vector blackKeys = new Vector ();
   private Vector keys = new Vector ();
   private Vector whiteKeys = new Vector ();

   public Keyboard ()
   {
      setLayout (new BorderLayout ());
      setPreferredSize (new Dimension (42*KEY_WIDTH+1, KEY_HEIGHT+1));

      int transpose = 24;  
      int [] whiteIDs = { 0, 2, 4, 5, 7, 9, 11 }; 

      for (int i = 0, x = 0; i < 6; i++) 
      {
           for (int j = 0; j < 7; j++, x += KEY_WIDTH) 
           {
                int keyNum = i * 12 + whiteIDs [j] + transpose;
                whiteKeys.add (new Key (x, 0, KEY_WIDTH, KEY_HEIGHT, keyNum));
           }
      }

      for (int i = 0, x = 0; i < 6; i++, x += KEY_WIDTH) 
      {
           int keyNum = i * 12 + transpose;

           blackKeys.add (new Key ((x += KEY_WIDTH)-4, 0, KEY_WIDTH/2,
                                   KEY_HEIGHT/2, keyNum+1));
           blackKeys.add (new Key ((x += KEY_WIDTH)-4, 0, KEY_WIDTH/2,
                                   KEY_HEIGHT/2, keyNum+3));
           x += KEY_WIDTH;

           blackKeys.add (new Key ((x += KEY_WIDTH)-4, 0, KEY_WIDTH/2,
                          KEY_HEIGHT/2, keyNum+6));
           blackKeys.add (new Key ((x += KEY_WIDTH)-4, 0, KEY_WIDTH/2,
                          KEY_HEIGHT/2, keyNum+8));
           blackKeys.add (new Key ((x += KEY_WIDTH)-4, 0, KEY_WIDTH/2,
                          KEY_HEIGHT/2, keyNum+10));
      }

      keys.addAll (blackKeys);
      keys.addAll (whiteKeys);

      addMouseListener (new MouseAdapter ()
                        {
                            public void mousePressed (MouseEvent e)
                            {
                               // Identify the key that was pressed. A null
                               // value indicates something other than a key
                               // was pressed.

                               theKey = getKey (e.getPoint ());

                               // If a key was pressed ...

                               if (theKey != null)
                               {
                                   // Tell key to start playing note.

                                   theKey.on ();

                                   // Update key's visual appearance.

                                   repaint ();
                               }
                            }

                            public void mouseReleased (MouseEvent e)
                            {
                               if (theKey != null)
                               {
                                   // Tell key to stop playing note.

                                   theKey.off ();

                                   // Update key's visual appearance.

                                   repaint ();
                               }
                            }

                            public void mouseExited (MouseEvent e) 
                            {
                               // This method is called if the mouse is moved
                               // off the keyboard component. If a key was
                               // pressed, we release that key.

                               if (theKey != null)
                               {
                                   // Tell key to stop playing note.

                                   theKey.off ();

                                   // Update key's visual appearance.

                                   repaint ();

                                   // The following assignment is needed so
                                   // that we don't execute the code within
                                   // mouseReleased()'s if statement should we
                                   // release a key after exiting the keyboard 
                                   // component. There is no need to tell the
                                   // key to stop playing a note after we have
                                   // already told it to do so. Furthermore,
                                   // we prevent an unnecessary repaint.

                                   theKey = null;
                               }
                            }

                            public Key getKey (Point point) 
                            {
                               // Identify the key that was clicked.

                               for (int i = 0; i < keys.size (); i++)
                               { 
                                    if (((Key) keys.get (i)).contains (point))
                                        return (Key) keys.get (i);
                               }

                               return null;
                            }
                        });
   }

   public boolean chooseInstrument (int instrumentID)
   {
      if (channel == null)
          return false;

      // Select new instrument based on ID.

      channel.programChange (instrumentID);

      return true;
   }

   public String [] getInstruments ()
   {
      if (synthesizer == null)
          return null;

      Instrument [] instruments = synthesizer.getLoadedInstruments ();

      String [] ins = new String [instruments.length];

      for (int i = 0; i < instruments.length; i++)
           ins [i] = instruments [i].toString ();

      return ins;
   }

   public void paint (Graphics g)
   {
      Graphics2D g2 = (Graphics2D) g;
      Dimension d = getSize ();

      g2.setBackground (getBackground ());
      g2.clearRect (0, 0, d.width, d.height);

      g2.setColor (Color.white);
      g2.fillRect (0, 0, 42*KEY_WIDTH, KEY_HEIGHT);

      for (int i = 0; i < whiteKeys.size (); i++)
      {
           Key key = (Key) whiteKeys.get (i);
           if (key.isNoteOn ()) 
           {
               g2.setColor (KEY_BLUE);
               g2.fill (key);
           }

           g2.setColor (Color.black);
           g2.draw (key);
      }

      for (int i = 0; i < blackKeys.size (); i++) 
      {
           Key key = (Key) blackKeys.get (i);
           if (key.isNoteOn ()) 
           {
               g2.setColor (KEY_BLUE);
               g2.fill (key);

               g2.setColor (Color.black);
               g2.draw (key);
           } 
           else 
           {
               g2.setColor (Color.black);
               g2.fill (key);
           }
      }
   }

   public void turnOff ()
   {
      if (synthesizer == null)
          return;

      // Attempt to unload all instruments.

      synthesizer.unloadAllInstruments (synthesizer.getDefaultSoundbank ());

      // Close the synthesizer, so that it can release any system resources
      // previously acquired during the open() call.

      synthesizer.close ();
      synthesizer = null;
   }

   public boolean turnOn ()
   {
      try
      {
          if (synthesizer == null) 
          {
              // Obtain the default synthesizer.

              if ((synthesizer = MidiSystem.getSynthesizer ()) == null)
                  return false;

              // Open the synthesizer, so that it can acquire any system
              // resources and become operational.

              synthesizer.open ();

          }
      }
      catch (Exception e)
      {
          e.printStackTrace();
          return false;
      }

      // Attempt load all instruments.

      synthesizer.loadAllInstruments (synthesizer.getDefaultSoundbank ());

      // Obtain the set of MIDI channels controlled by the synthesizer.

      MidiChannel [] midiChannels = synthesizer.getChannels ();

      // There must be at least one channel. Furthermore, we assume that the
      // first channel is used by the synthesizer. If you run into a problem,
      // use the index (other than 0) of the first non-null midiChannels
      // entry.

      if (midiChannels.length == 0 || midiChannels [0] == null)
      {
          synthesizer.close ();
          synthesizer = null;
          return false;
      }

      // Identify the channel to which note messages are sent.

      channel = midiChannels [0];

      return true;
   }

   /*
      This inner class describes an instrument key that knows how to start
      sounding and stop sounding its note. Furthermore, each key knows its
      size and location.
   */

   class Key extends Rectangle 
   {
      final static int ON = 0, OFF = 1, VELOCITY = 64;

      int kNum, noteState = OFF;

      public Key (int x, int y, int width, int height, int num) 
      {
         super (x, y, width, height);
         kNum = num;
      }

      public boolean isNoteOn () 
      {
          return noteState == ON;
      }

      public void off () 
      {
         setNoteState (OFF);
         //Keyboard.this.repaint ();

         // Send the key number to the channel so the note stops sounding.
         // Also send a keyup VELOCITY, which might affect how quickly the
         // note decays.

         if (channel != null)
             channel.noteOff (kNum, VELOCITY);
      }

      public void on () 
      {
         setNoteState (ON);
         //Keyboard.this.repaint ();

         // Send the key number (0 - 127, where 60 indicates Middle C) to the
         // channel so the note starts to sound. Also send a keydown VELOCITY,
         // which indicates the speed at which a key was pressed (the loudness
         // or volume of the note).

         if (channel != null)
             channel.noteOn (kNum, VELOCITY);
      }

      public void setNoteState (int state) 
      {
         noteState = state;
      }
   }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩欧美中文字幕精品| 国产成人在线视频网址| 中文字幕的久久| 盗摄精品av一区二区三区| 洋洋成人永久网站入口| 欧美一级精品在线| av资源网一区| 久久99久国产精品黄毛片色诱| 一区二区三区精密机械公司| 久久综合色之久久综合| 欧美一区二区三区免费观看视频| 99久免费精品视频在线观看 | 亚洲午夜久久久久久久久电影院 | 久久综合狠狠综合| 欧美大片国产精品| 宅男在线国产精品| 欧美精品久久天天躁| 欧美综合亚洲图片综合区| av亚洲精华国产精华精华| 国产很黄免费观看久久| 久久精品国产亚洲a| 久久99精品久久久久久国产越南| 午夜精品久久久久久久| 亚洲国产aⅴ天堂久久| 亚洲第一成人在线| 视频一区二区三区入口| 奇米在线7777在线精品| 免费看欧美美女黄的网站| 美女精品一区二区| 激情五月婷婷综合网| 国产精品影视天天线| 国产69精品久久久久毛片| 成人99免费视频| 成人午夜免费电影| 91视频在线看| 欧美日韩国产综合一区二区三区| 欧美精品电影在线播放| 精品欧美乱码久久久久久| 国产午夜亚洲精品不卡| 国产精品国产三级国产三级人妇 | 国产精品久久久久影院| 国产精品久久夜| 樱花影视一区二区| 日韩精品一卡二卡三卡四卡无卡| 久久国产精品第一页| 国产激情视频一区二区在线观看| 9i在线看片成人免费| 欧美色偷偷大香| 欧美精品一区二区蜜臀亚洲| 国产精品女主播在线观看| 一区二区三区四区不卡视频| 美女国产一区二区| fc2成人免费人成在线观看播放| 91免费视频网| 久久众筹精品私拍模特| 一区二区三区中文在线观看| 日韩精品乱码免费| 国产.欧美.日韩| 欧美精品日韩精品| 国产精品久久久久久久久免费樱桃| 亚洲黄色尤物视频| 国产一区在线精品| 欧美日韩中文另类| 中文字幕精品三区| 美美哒免费高清在线观看视频一区二区| 国产99久久精品| 91精品婷婷国产综合久久性色| 亚洲国产高清aⅴ视频| 日韩和的一区二区| av日韩在线网站| 91精品国产色综合久久| 亚洲品质自拍视频| 国产成人丝袜美腿| 欧美成人午夜电影| 亚洲人午夜精品天堂一二香蕉| 青青草97国产精品免费观看 | 国产在线精品一区二区夜色| 日本国产一区二区| 欧美激情自拍偷拍| 狠狠狠色丁香婷婷综合激情| 欧美探花视频资源| 一级日本不卡的影视| 成a人片亚洲日本久久| 日韩精品最新网址| 日本不卡视频在线| 欧美精品第一页| 樱桃视频在线观看一区| 99久久久精品免费观看国产蜜| 久久久精品蜜桃| 久草这里只有精品视频| 欧美一区二区三区四区在线观看| 亚洲人成精品久久久久久| 99国产一区二区三精品乱码| 国产目拍亚洲精品99久久精品| 久88久久88久久久| 久久久久久久久久电影| 国产一区二区伦理| 国产欧美日韩亚州综合| 午夜精品一区二区三区免费视频| 91传媒视频在线播放| 国产人久久人人人人爽| 国产精品系列在线观看| 国产视频一区二区在线| 国产一区二区视频在线播放| 欧美xfplay| 成人妖精视频yjsp地址| 亚洲色图色小说| 欧美午夜宅男影院| 日韩成人精品在线| 日韩欧美国产麻豆| 国产不卡视频在线播放| 中文字幕在线一区免费| 91久久国产综合久久| 水蜜桃久久夜色精品一区的特点| 91麻豆精品国产91久久久更新时间 | 国产精品久久久久久久久图文区 | 福利电影一区二区| 欧美激情一区二区三区全黄| 暴力调教一区二区三区| 亚洲欧美另类综合偷拍| 欧洲视频一区二区| 亚洲精品水蜜桃| 91精品国产综合久久精品app| 国产呦精品一区二区三区网站| 国产精品九色蝌蚪自拍| 欧美日韩免费一区二区三区| 激情综合色播激情啊| 亚洲男人的天堂一区二区| 日韩一区二区电影在线| www.日韩精品| 日韩黄色免费网站| 综合分类小说区另类春色亚洲小说欧美| 欧美日韩久久一区二区| 国产精品99精品久久免费| 一区二区三区精品| 国产亚洲va综合人人澡精品| 欧美在线免费观看亚洲| 国产精品一二三四| 午夜av一区二区| 中文字幕在线观看一区二区| 欧美日韩国产小视频在线观看| 国产精品一级二级三级| 婷婷中文字幕一区三区| 日本一区二区电影| 日韩免费视频一区| 欧美性色黄大片手机版| eeuss影院一区二区三区| 美女mm1313爽爽久久久蜜臀| 一区二区三区四区乱视频| 国产日韩欧美精品一区| 日本道在线观看一区二区| 国产一区二区不卡老阿姨| 亚洲欧美另类久久久精品 | 久久网站热最新地址| 欧美日韩精品一区二区三区四区| 久久精品99国产国产精| 国产精品视频线看| 欧美日韩第一区日日骚| 99re66热这里只有精品3直播 | ...中文天堂在线一区| 精品国产一区二区三区四区四| 欧美丰满高潮xxxx喷水动漫| 91在线精品一区二区| 高清不卡一二三区| 国产剧情一区二区| 精品亚洲porn| 激情综合五月婷婷| 奇米精品一区二区三区在线观看一| 亚洲免费在线视频一区 二区| 国产精品久久久久久久久久久免费看 | 日韩欧美第一区| 欧美一级理论片| 日韩欧美中文字幕制服| 日韩欧美三级在线| 精品久久久久久久久久久院品网| 91精品久久久久久久99蜜桃 | 亚洲精品福利视频网站| 亚洲欧洲av另类| 免费久久99精品国产| 视频在线观看91| 亚洲视频小说图片| 亚洲免费在线视频| 亚洲国产综合在线| 午夜婷婷国产麻豆精品| 成人的网站免费观看| 亚洲午夜视频在线观看| 九九**精品视频免费播放| 高清在线不卡av| 欧美放荡的少妇| 国产日韩精品一区二区三区| 亚洲精品乱码久久久久久日本蜜臀| 亚洲国产精品综合小说图片区| 精品一区二区三区久久| 91麻豆成人久久精品二区三区| 91精品国产色综合久久久蜜香臀| 国产精品水嫩水嫩| 免费不卡在线视频| 日本韩国欧美在线| 日本一区二区电影| 精品综合免费视频观看|