Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 47b0887245fae9355b5c85d959b6d28909aad8e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*******************************************************************************
 * Copyright (c) 2008, 2013 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Patrick Chuong (Texas Instruments) - Checkbox support for Flexible Hierachy view (Bug 286310)
 *******************************************************************************/
package org.eclipse.debug.examples.ui.midi.adapters;

import javax.sound.midi.MidiEvent;
import javax.sound.midi.MidiMessage;
import javax.sound.midi.ShortMessage;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.internal.ui.model.elements.ElementLabelProvider;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.jface.viewers.TreePath;

/**
 * Provides labels for MIDI tracks.
 *
 * @since 1.0
 */
public class MidiEventLabelProvider extends ElementLabelProvider {

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.model.elements.ElementLabelProvider#getLabel(org.eclipse.jface.viewers.TreePath, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, java.lang.String)
	 */
	@Override
	protected String getLabel(TreePath elementPath, IPresentationContext presentationContext, String columnId) throws CoreException {
		MidiEvent event = (MidiEvent) elementPath.getLastSegment();
		MidiMessage message = event.getMessage();
		if (TrackColumnPresentation.COL_TICK.equals(columnId)) {
			return Long.toString(event.getTick());
		} else if (TrackColumnPresentation.COL_BYTES.equals(columnId)) {
			byte[] bytes = message.getMessage();
			StringBuilder buffer = new StringBuilder();
			for (int i = 0; i < message.getLength(); i++) {
				buffer.append(' ');
				appendByte(buffer, bytes[i]);
			}
			return buffer.toString();
		} else if (TrackColumnPresentation.COL_COMMAND.equals(columnId)) {
			if (message instanceof ShortMessage) {
				ShortMessage sm = (ShortMessage) message;
				StringBuilder buf = new StringBuilder();
				appendByte(buf, (byte)sm.getCommand());
				return buf.toString();
			}
		} else if (TrackColumnPresentation.COL_CHANNEL.equals(columnId)) {
			if (message instanceof ShortMessage) {
				return Integer.toString(((ShortMessage)message).getChannel());
			}
		}
		return ""; //$NON-NLS-1$
	}


	/*
	 * (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.model.elements.ElementLabelProvider#getChecked(org.eclipse.jface.viewers.TreePath, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext)
	 */
	@Override
	public boolean getChecked(TreePath path, IPresentationContext presentationContext) throws CoreException {
		Boolean result = MidiEventModelProxy.gChecked.get(path);
		return result == null ? false : result.booleanValue();
	}

	/**
	 * Appends a byte to the buffer with 2 hex characters.
	 *
	 * @param buffer
	 * @param b
	 */
	private void appendByte(StringBuilder buffer, byte b) {
		String hex = Integer.toHexString(b & 0xFF).toUpperCase();
		for (int i = hex.length(); i < 2; i++) {
			buffer.append('0');
		}
		buffer.append(hex);
	}

}

Back to the top