Back to project page Musicdroid.
The source code is released under:
GNU General Public License
If you think the Android project Musicdroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * Catroid: An on-device visual programming system for Android devices * Copyright (C) 2010-2013 The Catrobat Team * (<http://developer.catrobat.org/credits>) */* w w w.ja va2 s .c o m*/ * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * An additional term exception under section 7 of the GNU Affero * General Public License, version 3, is available at * http://developer.catrobat.org/license_additional_term * * 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.catrobat.musicdroid.pocketmusic.note.draw; import android.content.res.Resources; import android.graphics.Paint; import org.catrobat.musicdroid.pocketmusic.note.MusicalKey; import org.catrobat.musicdroid.pocketmusic.note.NoteName; import org.catrobat.musicdroid.pocketmusic.note.symbol.NoteSymbol; import org.catrobat.musicdroid.pocketmusic.note.symbol.Symbol; public class NoteDrawer extends SymbolDrawer { private NoteCrossDrawer noteCrossDrawer; private NoteStemDrawer noteStemDrawer; private NoteBodyDrawer noteBodyDrawer; protected NotePositionInformation notePositionInformation; public NoteDrawer(NoteSheetCanvas noteSheetCanvas, Paint paint, Resources resources, MusicalKey key, NoteSheetDrawPosition drawPosition, int distanceBetweenLines) { super(noteSheetCanvas, paint, resources, key, drawPosition, distanceBetweenLines); noteCrossDrawer = new NoteCrossDrawer(noteSheetCanvas, resources, distanceBetweenLines); noteStemDrawer = new NoteStemDrawer(noteSheetCanvas, paint, distanceBetweenLines); noteBodyDrawer = new NoteBodyDrawer(this, noteSheetCanvas, paint, key, distanceBetweenLines); } public void drawSymbol(Symbol symbol) { if (false == (symbol instanceof NoteSymbol)) { return; } NoteSymbol noteSymbol = (NoteSymbol) symbol; drawCross(noteSymbol); drawBody(noteSymbol); drawStem(noteSymbol); drawHelpLines(); } protected void drawCross(NoteSymbol noteSymbol) { Integer xPositionForCrosses = null; for (NoteName noteName : noteSymbol.getNoteNamesSorted()) { if (noteName.isSigned()) { if (xPositionForCrosses == null) { xPositionForCrosses = getCenterPointForNextSmallSymbol().x; } int yPositionForCross = noteSheetCanvas.getHeightHalf() + NoteName.calculateDistanceToMiddleLineCountingSignedNotesOnly(key, noteName) * distanceBetweenLines / 2; noteCrossDrawer.drawCross(xPositionForCrosses, yPositionForCross); } } } protected void drawBody(NoteSymbol noteSymbol) { notePositionInformation = noteBodyDrawer.drawBody(noteSymbol); } protected void drawStem(NoteSymbol noteSymbol) { if (noteSymbol.hasStem()) { noteStemDrawer.drawStem(notePositionInformation, noteSymbol.isStemUp(key)); } } protected void drawHelpLines() { float topEndOfNoteLines = noteSheetCanvas.getHeightHalf() - distanceBetweenLines * NoteSheetDrawer.NUMBER_OF_LINES_FROM_CENTER_LINE_IN_BOTH_DIRECTIONS; float bottomEndOfNoteLines = noteSheetCanvas.getHeightHalf() + distanceBetweenLines * NoteSheetDrawer.NUMBER_OF_LINES_FROM_CENTER_LINE_IN_BOTH_DIRECTIONS; float topEndOfHelpLines = notePositionInformation.getTopOfSymbol() + distanceBetweenLines / 2; float bottomEndOfHelpLines = notePositionInformation.getBottomOfSymbol() - distanceBetweenLines / 2; int lengthOfHelpLine = ((int) notePositionInformation.getRightSideOfSymbol() - (int) notePositionInformation.getLeftSideOfSymbol()) / 3; topEndOfNoteLines -= distanceBetweenLines; while(topEndOfHelpLines <= topEndOfNoteLines) { int startX = (int) (notePositionInformation.getLeftSideOfSymbol() - lengthOfHelpLine); int stopX = (int) (notePositionInformation.getRightSideOfSymbol() + lengthOfHelpLine); int startY = (int) topEndOfNoteLines; int stopY = startY; noteSheetCanvas.drawLine(startX, startY, stopX, stopY, paint); topEndOfNoteLines -= distanceBetweenLines; } bottomEndOfNoteLines += distanceBetweenLines; while(bottomEndOfHelpLines >= bottomEndOfNoteLines) { int startX = (int) (notePositionInformation.getLeftSideOfSymbol() - lengthOfHelpLine); int stopX = (int) (notePositionInformation.getRightSideOfSymbol() + lengthOfHelpLine); int startY = (int) bottomEndOfNoteLines; int stopY = startY; noteSheetCanvas.drawLine(startX, startY, stopX, stopY, paint); bottomEndOfNoteLines += distanceBetweenLines; } } }