/*
* Musical Skill Coach - An interactive midi device friendly program to help music students improve their skills
* Copyright (C) 2011 Paul-Emile Gaudet
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package music.ui.panels;
import javax.swing.*;
import music.lib.MusicScore;
import music.lib.MusicScoreNote;
import music.ui.images.BassClefImage;
import music.ui.images.TrebleClefImage;
import music.ui.lib.Bar;
import music.ui.lib.FiveStaff;
import music.ui.lib.JoinedNotes;
import music.ui.lib.MusicCanvas;
import music.ui.lib.Note;
public class TrebleBassStaff extends JPanel
{
/**
*
*/
private static final long serialVersionUID = 1L;
protected JTextField keepFrames;
protected JPanel segmentPane;
protected FiveStaff treble;
protected FiveStaff bass;
protected MusicCanvas musicCanvas;
protected boolean processEvent;
protected TrebleClefImage tcImage;
protected BassClefImage bcImage;
public TrebleBassStaff()
{
super();
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
add(musicCanvas = new MusicCanvas());
treble = new FiveStaff();
bass = new FiveStaff();
tcImage = new TrebleClefImage();
bcImage = new BassClefImage();
musicCanvas.setTopStaff(treble);
musicCanvas.setBottomStaff(bass);
musicCanvas.setTopClef(tcImage);
musicCanvas.setBottomClef(bcImage);
processEvent = true;
}
public void loadNotesFromMusicScore(MusicScore musicScore)
{
if (musicScore == null)
return;
int notes = musicScore.getTotalNotes();
MusicScoreNote scoreNote;
Note note;
JoinedNotes topJoinedNotes = null;
JoinedNotes bottomJoinedNotes = null;
Bar bar = null;
int channel;
int midiNote;
int measure;
for (int i = 0;i < notes;i ++)
{
scoreNote = musicScore.getNote(i);
if (scoreNote.isBar())
{
if (bar != null)
musicCanvas.addBar(bar);
bar = new Bar();
topJoinedNotes = bottomJoinedNotes = null;
}
else if (bar != null)
{
channel = scoreNote.getChannel();
midiNote = scoreNote.getMidiNote();
measure = scoreNote.getMeasure();
note = null;
if ((midiNote > 0) && (midiNote < 127) &&
((measure == 1) || (measure == 2) || (measure == 4) || (measure == 8) || (measure == 16)))
{
if (channel == 0)
{
note = new Note(0);
if (scoreNote.getBeamToNextNote() != 0)
{
if (bottomJoinedNotes == null)
{
bottomJoinedNotes = new JoinedNotes();
musicCanvas.addJoinedNotes(bottomJoinedNotes, true);
}
bottomJoinedNotes.addNote(note);
}
else if (bottomJoinedNotes != null)
{
bottomJoinedNotes.addNote(note);
bottomJoinedNotes = null;
}
else
musicCanvas.addNote(note, true);
}
else if (channel == 1)
{
note = new Note(1);
if (scoreNote.getBeamToNextNote() != 0)
{
if (topJoinedNotes == null)
{
topJoinedNotes = new JoinedNotes();
musicCanvas.addJoinedNotes(topJoinedNotes, false);
}
topJoinedNotes.addNote(note);
}
else if (topJoinedNotes != null)
{
topJoinedNotes.addNote(note);
topJoinedNotes = null;
}
else
musicCanvas.addNote(note, false);
}
note.setMidiNote(midiNote, measure, 0);
}
}
}
if (bar != null)
musicCanvas.addBar(bar);
}
public void removeNotes()
{
musicCanvas.removeNotes();
}
public void removeFirstObject()
{
musicCanvas.removeFirstObject();
}
public void addNote(int note, int randomNo)
{
if (note > 62)
{
Note n = new Note(1);
n.setMidiNote(note, 4, randomNo);
musicCanvas.addNote(n, false);
}
else if (note > 55)
{
if (randomNo < 1)
{
Note n = new Note(0);
n.setMidiNote(note, 4, randomNo);
musicCanvas.addNote(n, true);
}
else
{
Note n = new Note(1);
n.setMidiNote(note, 4, randomNo);
musicCanvas.addNote(n, false);
}
}
else if (note >= 36)
{
Note n = new Note(0);
n.setMidiNote(note, 4, randomNo);
musicCanvas.addNote(n, true);
}
invalidate();
repaint();
}
}