Source Code Cross Referenced for Track.java in  » Apache-Harmony-Java-SE » javax-package » javax » sound » midi » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » javax package » javax.sound.midi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package javax.sound.midi;
019:
020:        import java.util.ArrayList;
021:
022:        import org.apache.harmony.sound.internal.nls.Messages;
023:
024:        public class Track {
025:            private ArrayList<MidiEvent> events; //vector of events contain in the Track
026:
027:            private MidiEvent badEvent; //variable to save event which I try to add
028:            //to empty Track; see description below
029:
030:            private long tick;
031:
032:            Track() {
033:                /*
034:                 * create an empty Track; new Track must contain only meta-event End of Track.
035:                 * MetaMessage with MetaMessage.data contains -1, 47 and 0 is meta-event
036:                 */
037:                events = new ArrayList<MidiEvent>();
038:                events.add(new MidiEvent(new MetaMessage(
039:                        new byte[] { -1, 47, 0 }), 0));
040:            }
041:
042:            public boolean add(MidiEvent event) {
043:                //FIXME
044:                /*
045:                 * Some words about badEvent.
046:                 * When I write tests, I find following situation in the RI:
047:                 * if I want to add to empty Track new event that is not meta-event End of Track,
048:                 * I catch exception ArrayIndexOutOfBoundsException with meaning -1, and my
049:                 * event doesn't add to Track, but meta-event adds. If I try to add the same 
050:                 * event after it, method Track.add(MidiEvent) return 'false', and my event
051:                 * doesn't add again. So, I want to delete this event and use method 
052:                 * Track.remove(MidiEvent) for it, but it return 'false' too! And only after
053:                 * this "shamanism" I can add this event to Track normally. 
054:                 * And only for this situation I use variable badEvent. 
055:                 * 
056:                 * See test org.apache.harmony.sound.tests.javax.sound.midi.TrackTest 
057:                 * for more details
058:                 */
059:
060:                /*
061:                 * if event equals null or badEvent, this method return 'false'
062:                 */
063:                if (event == null || event == badEvent) {
064:                    return false;
065:                }
066:                /*
067:                 * If event equals meta-event End of Track and Track in this moment
068:                 * doesn't contain some events, i.e. Track.size() return 0, this 
069:                 * event accrue to Track; 
070:                 * if Track is not empty, but it doesn't contain meta-event, 
071:                 * this event accrue to the end of Track;
072:                 * in any case addition of this meta-event is successful, this method 
073:                 * return 'true' even if meta-event End of Track already contains in the Track
074:                 */
075:                if (event.getMessage().getMessage()[0] == -1
076:                        && event.getMessage().getMessage()[1] == 47
077:                        && event.getMessage().getMessage()[2] == 0) {
078:                    if (events.size() == 0) {
079:                        return events.add(event);
080:                    }
081:                    byte[] bt = events.get(events.size() - 1).getMessage()
082:                            .getMessage();
083:                    if ((bt[0] != -1) && (bt[1] != 47) && (bt[2] != 0)) {
084:                        return events.add(event);
085:                    }
086:                    return true;
087:                }
088:                /*
089:                 * after use method Track.add(MidiEvent) Track must contain meta-event
090:                 * End of Track; so, at first I add this event to Track if it doesn't 
091:                 * contain meta-event and parameter 'event' is not meta-event
092:                 */
093:                if (events.size() == 0) {
094:                    events.add(new MidiEvent(new MetaMessage(new byte[] { -1,
095:                            47, 0 }), 0));
096:                    badEvent = event;
097:                    // sounds.01=-1
098:                    throw new ArrayIndexOutOfBoundsException(Messages
099:                            .getString("sound.01")); //$NON-NLS-1$
100:                }
101:                byte[] bt = events.get(events.size() - 1).getMessage()
102:                        .getMessage();
103:                if ((bt[0] != -1) && (bt[1] != 47) && (bt[2] != 0)) {
104:                    events.add(new MidiEvent(new MetaMessage(new byte[] { -1,
105:                            47, 0 }), 0));
106:                }
107:
108:                if (events.contains(event)) {
109:                    return false;
110:                }
111:
112:                /*
113:                 * events in the Track must take up position in ascending ticks
114:                 */
115:                if (events.size() == 1) {
116:                    events.add(0, event);
117:                }
118:                for (int i = 0; i < events.size() - 1; i++) {
119:                    if (events.get(i).getTick() <= event.getTick()) {
120:                        continue;
121:                    }
122:                    events.add(i, event);
123:                    break;
124:                }
125:                /*
126:                 * method Track.ticks() return the biggest value of tick of all events
127:                 * and save it even I remove event with the biggest values of tick
128:                 */
129:                if (tick < event.getTick()) {
130:                    tick = event.getTick();
131:                }
132:                return true;
133:            }
134:
135:            public MidiEvent get(int index)
136:                    throws ArrayIndexOutOfBoundsException {
137:                if (index < 0 || index >= events.size()) {
138:                    // sound.02=Index: {0}, Size: {1}
139:                    throw new ArrayIndexOutOfBoundsException(Messages
140:                            .getString("sound.02", index, events.size())); //$NON-NLS-1$
141:                }
142:                return events.get(index);
143:            }
144:
145:            public boolean remove(MidiEvent event) {
146:                /*
147:                 * if I remove event that equals badEvent, I "delete" badEvent
148:                 */
149:                if (event == badEvent) {
150:                    badEvent = null;
151:                    return false;
152:                }
153:                /*
154:                 * method Track.ticks() always return the biggest value that ever has been
155:                 * in the Track; so only when Track is empty Track.ticks() return 0 
156:                 */
157:                if (events.remove(event)) {
158:                    if (events.size() == 0) {
159:                        tick = 0;
160:                    }
161:                    return true;
162:                }
163:                return false;
164:            }
165:
166:            public int size() {
167:                return events.size();
168:            }
169:
170:            public long ticks() {
171:                return tick;
172:            }
173:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.