java做钢琴为什么没有声音_钢琴突然没声音了是怎么回事

很多新手对于新买的钢琴总会跃跃欲试的想去弹奏,有时候会在初次接触钢琴时候遇到一些让人头疼的问题,比如就是弹奏的时候对于踏板的掌握不好,导致的钢琴“失声”,今天珠江钢琴就来和大家分析一下遇到这种情况该怎么办。

50dd48128983ca93276a3d142acb4265.png

可能是弱音踏板出了问题。钢琴突然没声音了可能因为踏板与“棉布”之间出现了连接错位问题,使得那层布无法离开内部琴弦。试试再踩一次,看它会不会回弹。又或者看看那踏板下面是不是有两级的,把它扣过来另一边会使踏板升高复原。如果怎么弄它都不升高复原,估计里面的结构坏掉了,中间踏板的作用,中间的踏板是弱音踏板,不同的钢琴它的结构不同。把钢琴的顶部的“盖子”掀开,可以看到钢琴内部有一长条类似“棉布”一样的东西。平常踩下中间的踏板时,那层“棉布”就会覆盖在内部琴弦上,这样音量就会减小。通常在不影响别人休息的时候用。

4ded59c2f578edb60cdd3e7373822885.png

钢琴,是西洋古典音乐中的一种键盘乐器,由88个琴键(52个白键,36个黑键)和金属弦音板组成。意大利人克利斯托弗利(Bartolomeo

Cristofori,1655-1731)在1709年发明了钢琴。

钢琴音域范围从A2(27.5Hz)至

c5(4186Hz),几乎囊括了乐音体系中的全部乐音。钢琴普遍用于独奏、重奏、伴奏等演出,作曲和排练音乐十分方便。演奏者通过按下键盘上的琴键,牵动钢琴里面包着绒毡的小木槌,继而敲击钢丝弦发出声音。钢琴需定时的护理,来保证它的音色不变。

新手在aa次接触到珠江钢琴的时候,十分兴奋激动想上去弹奏是十分正常的,但是对于钢琴的各个部位的功能还是需要熟悉好了再上手,不然出现问题容易摸不着头脑。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java Swing是一种基于Java语言的图形用户界面(GUI)工具包。使用Java Swing,可以轻松地创建各种GUI应用程序,包括钢琴程序。以下是一个简单的Java Swing钢琴程序示例,支持录音等功能。 ```java import java.awt.*; import java.awt.event.*; import java.io.*; import javax.sound.midi.*; import javax.swing.*; public class Piano extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; private JButton[] whiteKeys = new JButton[7]; private JButton[] blackKeys = new JButton[5]; private JButton recordButton; private JButton playButton; private JButton stopButton; private boolean isRecording = false; private boolean isPlaying = false; private Sequence sequence; private Sequencer sequencer; private Track track; private int currentTick; private ByteArrayOutputStream byteArrayOutputStream; private AudioFormat audioFormat; private TargetDataLine targetDataLine; private AudioInputStream audioInputStream; private byte[] audioData; public Piano() { setTitle("Java Piano"); setSize(800, 300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BorderLayout()); JPanel keyboardPanel = new JPanel(); keyboardPanel.setLayout(new GridLayout(1, 0)); // Add white keys String[] whiteNotes = {"C", "D", "E", "F", "G", "A", "B"}; for (int i = 0; i < 7; i++) { whiteKeys[i] = new JButton(whiteNotes[i]); whiteKeys[i].setPreferredSize(new Dimension(80, 200)); whiteKeys[i].addActionListener(this); keyboardPanel.add(whiteKeys[i]); } // Add black keys String[] blackNotes = {"C#", "D#", "", "F#", "G#", "A#"}; for (int i = 0; i < 6; i++) { if (i != 2) { blackKeys[i] = new JButton(blackNotes[i]); blackKeys[i].setPreferredSize(new Dimension(50, 120)); blackKeys[i].setBackground(Color.BLACK); blackKeys[i].setOpaque(true); blackKeys[i].addActionListener(this); keyboardPanel.add(blackKeys[i]); } } // Add record, play, and stop buttons JPanel controlPanel = new JPanel(); controlPanel.setLayout(new FlowLayout()); recordButton = new JButton("Record"); recordButton.addActionListener(this); controlPanel.add(recordButton); playButton = new JButton("Play"); playButton.addActionListener(this); controlPanel.add(playButton); stopButton = new JButton("Stop"); stopButton.addActionListener(this); controlPanel.add(stopButton); add(keyboardPanel, BorderLayout.CENTER); add(controlPanel, BorderLayout.SOUTH); setVisible(true); } public void actionPerformed(ActionEvent e) { if (e.getSource() == recordButton) { if (!isRecording) { isRecording = true; recordButton.setText("Stop Recording"); startRecording(); } else { isRecording = false; recordButton.setText("Record"); stopRecording(); } } else if (e.getSource() == playButton) { if (!isPlaying) { isPlaying = true; playButton.setText("Stop Playing"); startPlaying(); } else { isPlaying = false; playButton.setText("Play"); stopPlaying(); } } else { JButton button = (JButton) e.getSource(); String note = button.getText(); playSound(note); if (isRecording) { addNoteToSequence(note); } } } private void startRecording() { try { audioFormat = getAudioFormat(); DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat); targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo); targetDataLine.open(audioFormat); targetDataLine.start(); byteArrayOutputStream = new ByteArrayOutputStream(); audioData = new byte[1024]; new Thread(new Runnable() { public void run() { while (isRecording) { int numBytesRead = targetDataLine.read(audioData, 0, audioData.length); byteArrayOutputStream.write(audioData, 0, numBytesRead); } } }).start(); } catch (Exception ex) { ex.printStackTrace(); } } private void stopRecording() { try { targetDataLine.stop(); targetDataLine.close(); byteArrayOutputStream.close(); byte[] byteArray = byteArrayOutputStream.toByteArray(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray); audioInputStream = new AudioInputStream(byteArrayInputStream, audioFormat, byteArray.length / audioFormat.getFrameSize()); // Convert audio data to MIDI sequence AudioToMidiConverter converter = new AudioToMidiConverter(); sequence = converter.convert(audioInputStream); // Create new track to add notes to sequencer = MidiSystem.getSequencer(); sequencer.open(); sequence.deleteTrack(sequence.getTracks()[0]); track = sequence.createTrack(); currentTick = 0; } catch (Exception ex) { ex.printStackTrace(); } } private void startPlaying() { try { sequencer.setSequence(sequence); sequencer.start(); } catch (Exception ex) { ex.printStackTrace(); } } private void stopPlaying() { sequencer.stop(); sequencer.close(); } private void addNoteToSequence(String note) { try { int velocity = 127; int duration = 100; int pitch = getMidiPitch(note); ShortMessage messageOn = new ShortMessage(ShortMessage.NOTE_ON, 0, pitch, velocity); track.add(new MidiEvent(messageOn, currentTick)); currentTick += duration; ShortMessage messageOff = new ShortMessage(ShortMessage.NOTE_OFF, 0, pitch, velocity); track.add(new MidiEvent(messageOff, currentTick)); } catch (Exception ex) { ex.printStackTrace(); } } private void playSound(String note) { try { Synthesizer synthesizer = MidiSystem.getSynthesizer(); synthesizer.open(); MidiChannel[] channels = synthesizer.getChannels(); int velocity = 127; int pitch = getMidiPitch(note); channels[0].noteOn(pitch, velocity); Thread.sleep(100); channels[0].noteOff(pitch, velocity); synthesizer.close(); } catch (Exception ex) { ex.printStackTrace(); } } private int getMidiPitch(String note) { String[] notes = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; int[] pitches = {60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71}; for (int i = 0; i < notes.length; i++) { if (note.equals(notes[i])) { return pitches[i]; } } return 0; } private AudioFormat getAudioFormat() { float sampleRate = 44100.0F; int sampleSizeInBits = 16; int channels = 1; boolean signed = true; boolean bigEndian = false; return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian); } public static void main(String[] args) { new Piano(); } } ``` 这个程序使用Java Swing创建了一个钢琴界面,包括白键和黑键。它还包括三个按钮:录音,播放和停止。当用户按下一个键时,程序将播放相应的音符,并且如果正在录音,则将该音符添加到MIDI序列中。当用户按下录音按钮时,程序开始录制音频,并将其转换为MIDI序列。当用户按下播放按钮时,程序将播放MIDI序列中的音符。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值