migration to gradle, splitted wiiusej, wiigee and itunescontroller into subprojects
This commit is contained in:
16
java/build.gradle
Normal file
16
java/build.gradle
Normal file
@@ -0,0 +1,16 @@
|
||||
subprojects {
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
}
|
||||
|
||||
version = '0.1'
|
||||
|
||||
jar {
|
||||
}
|
||||
}
|
||||
7
java/itunescontroller/.classpath
Normal file
7
java/itunescontroller/.classpath
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry exported="true" kind="con" path="org.springsource.ide.eclipse.gradle.classpathcontainer"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
18
java/itunescontroller/.project
Normal file
18
java/itunescontroller/.project
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>itunescontroller</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.springsource.ide.eclipse.gradle.core.nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
3
java/itunescontroller/build.gradle
Normal file
3
java/itunescontroller/build.gradle
Normal file
@@ -0,0 +1,3 @@
|
||||
dependencies {
|
||||
compile 'net.sf.jacob-project:jacob:1.+'
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents a artwork.
|
||||
*
|
||||
* Defines a single piece of artwork.
|
||||
*
|
||||
* Artwork is always associated with an individual track.
|
||||
* To add a piece of artwork to a track, use IITTrack::AddArtworkFromFile().
|
||||
* The IITTrack::Artwork property
|
||||
*
|
||||
* To get a collection of artwork associated with a track call
|
||||
* <code>ITTrack.getArtwork()</code>.
|
||||
*
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITArtwork extends ITObject {
|
||||
|
||||
public ITArtwork (Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete this object.
|
||||
*/
|
||||
public void delete() {
|
||||
Dispatch.call(object, "Delete");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kind of the object.
|
||||
* @return Returns the kind of the object.
|
||||
*/
|
||||
public ITArtworkFormat getFormat() {
|
||||
return ITArtworkFormat.values()[Dispatch.get(object, "Format").getInt()];
|
||||
}
|
||||
|
||||
// TODO: Comments
|
||||
|
||||
public boolean getIsDownloadedArtwork() {
|
||||
return Dispatch.get(object, "IsDownloadedArtwork").getBoolean();
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return Dispatch.get(object, "Description").getString();
|
||||
|
||||
}
|
||||
|
||||
public void SaveArtworkToFile(String filePath) {
|
||||
Dispatch.call(object, "SaveArtworkToFile",filePath);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents a collection of Artwork objects.
|
||||
*
|
||||
* Note that collection indices are always 1-based.
|
||||
*
|
||||
* You can retrieve all the Artworks defined for a source using
|
||||
* <code>ITSource.getArtwork()</code>.
|
||||
*
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITArtworkCollection {
|
||||
|
||||
protected Dispatch object;
|
||||
|
||||
public ITArtworkCollection(Dispatch d) {
|
||||
object = d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of playlists in the collection.
|
||||
* @return Returns the number of playlists in the collection.
|
||||
*/
|
||||
public int getCount() {
|
||||
return Dispatch.get(object, "Count").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ITArtwork object corresponding to the given index (1-based).
|
||||
* @param index Index of the playlist to retrieve, must be less than or
|
||||
* equal to <code>ITArtworkCollection.getCount()</code>.
|
||||
* @return Returns an ITArtwork object corresponding to the given index.
|
||||
* Will be set to NULL if no playlist could be retrieved.
|
||||
*/
|
||||
public ITArtwork getItem (int index) {
|
||||
Dispatch item = Dispatch.call(object, "Item", index).toDispatch();
|
||||
return new ITArtwork(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ITArtwork object with the specified persistent ID. See the
|
||||
* documentation on ITObject for more information on persistent IDs.
|
||||
* @param highID The high 32 bits of the 64-bit persistent ID.
|
||||
* @param lowID The low 32 bits of the 64-bit persistent ID.
|
||||
* @return Returns an ITArtwork object with the specified persistent ID.
|
||||
* Will be set to NULL if no playlist could be retrieved.
|
||||
*/
|
||||
public ITArtwork getItemByPersistentID (int highID, int lowID) {
|
||||
Dispatch item = Dispatch.call(object, "ItemByPersistentID", highID, lowID).toDispatch();
|
||||
return new ITArtwork(item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.dt.iTunesController;
|
||||
|
||||
/**
|
||||
* Specifies the Artwork kind.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public enum ITArtworkFormat {
|
||||
ITArtworkFormatUnknown,
|
||||
ITArtworkFormatJPEG,
|
||||
ITArtworkFormatPNG,
|
||||
ITArtworkFormatBMP;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents an audio CD playlist.
|
||||
*
|
||||
* An audio CD playlist is always associated with an IITSource of kind
|
||||
* ITSourceKindAudioCD.
|
||||
*
|
||||
* You can retrieve all the playlists defined for a source using
|
||||
* <code>ITSource.getPlaylists()</code>.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITAudioCDPlaylist extends ITPlaylist {
|
||||
|
||||
public ITAudioCDPlaylist(Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the audio CD's artist.
|
||||
* @return Returns the audio CD's artist.
|
||||
*/
|
||||
public String getArtist() {
|
||||
return Dispatch.get(object, "Artist").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this audio CD is a compilation album.
|
||||
* @return Returns true if this audio CD is a compilation album.
|
||||
*/
|
||||
public boolean isCompilation() {
|
||||
return Dispatch.get(object, "Compilation").getBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the audio CD's composer.
|
||||
* @return Returns the audio CD's composer.
|
||||
*/
|
||||
public String getComposer() {
|
||||
return Dispatch.get(object, "Composer").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total number of discs in this CD's album.
|
||||
* @return Returns the total number of discs in this CD's album.
|
||||
*/
|
||||
public long getDiscCount() {
|
||||
return Dispatch.get(object, "DiscCount").getLong();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the CD disc in the source album.
|
||||
* @return Returns the index of the CD disc in the source album.
|
||||
*/
|
||||
public long getDiscNumber() {
|
||||
return Dispatch.get(object, "DiscNumber").getLong();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the audio CD's genre.
|
||||
* @return Returns the audio CD's genre.
|
||||
*/
|
||||
public String getGenre() {
|
||||
return Dispatch.get(object, "Genre").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reveals the CD playlist in the main browser window.
|
||||
*/
|
||||
public void reveal() {
|
||||
Dispatch.call(object, "Reveal");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents the main browser window.
|
||||
*
|
||||
* You can retrieve the main browser window using
|
||||
* <code>iTunes.BrowserWindow()</code>.
|
||||
*
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
|
||||
public class ITBrowserWindow extends ITWindow {
|
||||
|
||||
public ITBrowserWindow (Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kind of the object.
|
||||
* @return Returns the kind of the object.
|
||||
*/
|
||||
public boolean getMiniPlayer() {
|
||||
return Dispatch.get(object, "MiniPlayer").getBoolean();
|
||||
}
|
||||
|
||||
// TODO: Comments
|
||||
|
||||
public ITTrackCollection getSelectedTracks() {
|
||||
Dispatch collection = Dispatch.call(object, "SelectedTracks").getDispatch();
|
||||
return new ITTrackCollection(collection);
|
||||
}
|
||||
|
||||
public ITPlaylist getSelectedPlaylist() {
|
||||
Dispatch playlist = Dispatch.get(object, "SelectedPlaylist").toDispatch();
|
||||
return new ITPlaylist(playlist);
|
||||
}
|
||||
|
||||
public void setSelectedPlaylist(ITPlaylist playlist) {
|
||||
Dispatch dispatchRef = playlist.fetchDispatch();
|
||||
Dispatch.put(object, "SelectedPlaylist", dispatchRef);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.dt.iTunesController;
|
||||
|
||||
/**
|
||||
* Specifies the reason the COM interface is being disabled.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public enum ITCOMDisabledReason {
|
||||
ITCOMDisabledReasonOther,
|
||||
ITCOMDisabledReasonDialog,
|
||||
ITCOMDisabledReasonQuitting;
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
package com.dt.iTunesController;
|
||||
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents an equalizer preset.
|
||||
* You can retrieve or set the currently selected EQ preset using the
|
||||
* <code>iTunes.getCurrentEQPreset()<code> method.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITEQPreset {
|
||||
|
||||
protected Dispatch object;
|
||||
|
||||
public ITEQPreset(Dispatch d) {
|
||||
object = d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the EQ Preset (e.g. "Acoustic").
|
||||
* @return Returns the name of the EQ Preset (e.g. "Acoustic").
|
||||
*/
|
||||
public String getName() {
|
||||
return Dispatch.get(object, "Name").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the EQ preset can be modified.
|
||||
* @return True if the EQ preset can be modified.
|
||||
*/
|
||||
public boolean getModifiable() {
|
||||
return Dispatch.get(object, "Modifiable").getBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the equalizer preamp level (-12.0 db to +12.0 db).
|
||||
* @param level The new equalizer preamp level (-12.0 db to +12.0 db).
|
||||
*/
|
||||
public void setPreamp(double level) {
|
||||
Dispatch.put(object, "Preamp", level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the equalizer preamp level (-12.0db to +12.0db).
|
||||
* @return Returns the equalizer preamp level (-12.0db to +12.0db).
|
||||
*/
|
||||
public double getPreamp() {
|
||||
return Dispatch.get(object, "Preamp").getDouble();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the equalizer 32Hz level (-12.0 db to +12.0 db).
|
||||
* @param level The new equalizer 32Hz level (-12.0 db to +12.0db).
|
||||
*/
|
||||
public void setBand1(double level) {
|
||||
Dispatch.put(object, "Band1", level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the equalizer 32Hz level (-12.0 db to +12.0 db).
|
||||
* @return Returns the equalizer 32Hz level (-12.0 db to +12.0 db).
|
||||
*/
|
||||
public double getBand1() {
|
||||
return Dispatch.get(object, "Band1").getDouble();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the equalizer 64Hz level (-12.0 db to +12.0 db).
|
||||
* @param level The new equalizer 64Hz level (-12.0 db to +12.0db).
|
||||
*/
|
||||
public void setBand2(double level) {
|
||||
Dispatch.put(object, "Band2", level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the equalizer 64Hz level (-12.0 db to +12.0 db).
|
||||
* @return Returns the equalizer 64Hz level (-12.0 db to +12.0 db).
|
||||
*/
|
||||
public double getBand2() {
|
||||
return Dispatch.get(object, "Band2").getDouble();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the equalizer 125Hz level (-12.0 db to +12.0 db).
|
||||
* @param level The new equalizer 125Hz level (-12.0 db to +12.0db).
|
||||
*/
|
||||
public void setBand3(double level) {
|
||||
Dispatch.put(object, "Band3", level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the equalizer 125Hz level (-12.0 db to +12.0 db).
|
||||
* @return Returns the equalizer 125Hz level (-12.0 db to +12.0 db).
|
||||
*/
|
||||
public double getBand3() {
|
||||
return Dispatch.get(object, "Band3").getDouble();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the equalizer 250Hz level (-12.0 db to +12.0 db).
|
||||
* @param level The new equalizer 250Hz level (-12.0 db to +12.0db).
|
||||
*/
|
||||
public void setBand4(double level) {
|
||||
Dispatch.put(object, "Band4", level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the equalizer 250Hz level (-12.0 db to +12.0 db).
|
||||
* @return Returns the equalizer 250Hz level (-12.0 db to +12.0 db).
|
||||
*/
|
||||
public double getBand4() {
|
||||
return Dispatch.get(object, "Band4").getDouble();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the equalizer 500Hz level (-12.0 db to +12.0 db).
|
||||
* @param level The new equalizer 500Hz level (-12.0 db to +12.0db).
|
||||
*/
|
||||
public void setBand5(double level) {
|
||||
Dispatch.put(object, "Band5", level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the equalizer 500Hz level (-12.0 db to +12.0 db).
|
||||
* @return Returns the equalizer 500Hz level (-12.0 db to +12.0 db).
|
||||
*/
|
||||
public double getBand5() {
|
||||
return Dispatch.get(object, "Band5").getDouble();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the equalizer 1KHz level (-12.0 db to +12.0 db).
|
||||
* @param level The new equalizer 1KHz level (-12.0 db to +12.0db).
|
||||
*/
|
||||
public void setBand6(double level) {
|
||||
Dispatch.put(object, "Band6", level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the equalizer 1KHz level (-12.0 db to +12.0 db).
|
||||
* @return Returns the equalizer 1KHz level (-12.0 db to +12.0 db).
|
||||
*/
|
||||
public double getBand6() {
|
||||
return Dispatch.get(object, "Band6").getDouble();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the equalizer 2KHz level (-12.0 db to +12.0 db).
|
||||
* @param level The new equalizer 2KHz level (-12.0 db to +12.0db).
|
||||
*/
|
||||
public void setBand7(double level) {
|
||||
Dispatch.put(object, "Band7", level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the equalizer 2KHz level (-12.0 db to +12.0 db).
|
||||
* @return Returns the equalizer 2KHz level (-12.0 db to +12.0 db).
|
||||
*/
|
||||
public double getBand7() {
|
||||
return Dispatch.get(object, "Band7").getDouble();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the equalizer 4KHz level (-12.0 db to +12.0 db).
|
||||
* @param level The new equalizer 4KHz level (-12.0 db to +12.0db).
|
||||
*/
|
||||
public void setBand8(double level) {
|
||||
Dispatch.put(object, "Band8", level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the equalizer 4KHz level (-12.0 db to +12.0 db).
|
||||
* @return Returns the equalizer 4KHz level (-12.0 db to +12.0 db).
|
||||
*/
|
||||
public double getBand8() {
|
||||
return Dispatch.get(object, "Band8").getDouble();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the equalizer 8KHz level (-12.0 db to +12.0 db).
|
||||
* @param level The new equalizer 8KHz level (-12.0 db to +12.0db).
|
||||
*/
|
||||
public void setBand9(double level) {
|
||||
Dispatch.put(object, "Band9", level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the equalizer 8KHz level (-12.0 db to +12.0 db).
|
||||
* @return Returns the equalizer 8KHz level (-12.0 db to +12.0 db).
|
||||
*/
|
||||
public double getBand9() {
|
||||
return Dispatch.get(object, "Band9").getDouble();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the equalizer 16KHz level (-12.0 db to +12.0 db).
|
||||
* @param level The new equalizer 16KHz level (-12.0 db to +12.0db).
|
||||
*/
|
||||
public void setBand10(double level) {
|
||||
Dispatch.put(object, "Band10", level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the equalizer 16KHz level (-12.0 db to +12.0 db).
|
||||
* @return Returns the equalizer 16KHz level (-12.0 db to +12.0 db).
|
||||
*/
|
||||
public double getBand10() {
|
||||
return Dispatch.get(object, "Band10").getDouble();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete this EQ Preset.
|
||||
* Any EQ preset can be deleted, including built-in presets, except for the
|
||||
* Manual preset.
|
||||
* @param updateAllTracks If true, any tracks that use this EQ preet will be
|
||||
* set to have no assigned EQ preset.
|
||||
*/
|
||||
public void delete(boolean updateAllTracks) {
|
||||
Dispatch.call(object, "Delete", updateAllTracks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename this EQ Preset.
|
||||
* The name of any EQ preset can be changed, including built-in presets,
|
||||
* except for the Manual preset.
|
||||
* EQ preset names cannot start with leading spaces. If you specify a name
|
||||
* that starts with leading spaces they will be stripped out.
|
||||
* @param updateAllTracks If true, any tracks that use this EQ preet will be
|
||||
* updated with the new preset name.
|
||||
*/
|
||||
public void rename(String newName, boolean updateAllTracks) {
|
||||
Dispatch.call(object, "Rename", newName, updateAllTracks);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents a file or CD track.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITFileOrCDTrack extends ITTrack {
|
||||
|
||||
public ITFileOrCDTrack (Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reveals the track in the main browser window.
|
||||
*/
|
||||
public void reveal() {
|
||||
Dispatch.call(object, "Reveal");
|
||||
}
|
||||
|
||||
public ITVideoKind getVideoKind() {
|
||||
return ITVideoKind.values()[Dispatch.get(object, "VideoKind").getInt()];
|
||||
}
|
||||
|
||||
public ITRatingKind getRatingKind() {
|
||||
return ITRatingKind.values()[Dispatch.get(object, "RatingKind").getInt()];
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return Dispatch.get(object, "Location").getString();
|
||||
}
|
||||
|
||||
public ITArtworkCollection getArtworks() {
|
||||
Dispatch artworks = Dispatch.get(object, "Artwork").toDispatch();
|
||||
return new ITArtworkCollection(artworks);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents a library playlist.
|
||||
*
|
||||
* A library playlist consists of all the tracks in a user's library.
|
||||
*
|
||||
* For convenience, you can retrieve the main library playlist using
|
||||
* <code>iTunes.getLibraryPlaylist()</code>.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITLibraryPlaylist extends ITPlaylist {
|
||||
|
||||
public ITLibraryPlaylist(Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Defines a source, playlist or track.
|
||||
*
|
||||
* An ITObject uniquely identifies a source, playlist, or track in iTunes using
|
||||
* four separate IDs. These are runtime IDs, they are only valid while the
|
||||
* current instance of iTunes is running.
|
||||
*
|
||||
* As of iTunes 7.7, you can also identify an ITObject using a 64-bit persistent
|
||||
* ID, which is valid across multiple invocations of iTunes.
|
||||
*
|
||||
* The main use of the ITObject interface is to allow clients to track iTunes
|
||||
* database changes using
|
||||
* <code>iTunesEventsInterface.onDatabaseChangedEvent()</code>.
|
||||
*
|
||||
* You can retrieve an ITObject with a specified runtime ID using
|
||||
* <code>iTunes.getITObjectByID()</code>.
|
||||
*
|
||||
* An ITObject will always have a valid, non-zero source ID.
|
||||
*
|
||||
* An ITObject corresponding to a playlist or track will always have a valid
|
||||
* playlist ID. The playlist ID will be zero for a source.
|
||||
*
|
||||
* An ITObject corresponding to a track will always have a valid track and
|
||||
* track database ID. These IDs will be zero for a source or playlist.
|
||||
*
|
||||
* A track ID is unique within the track's playlist. A track database ID is
|
||||
* unique across all playlists. For example, if the same music file is in two
|
||||
* different playlists, each of the tracks could have different track IDs, but
|
||||
* they will have the same track database ID.
|
||||
*
|
||||
* An ITObject also has a 64-bit persistent ID which can be used to identify
|
||||
* the ITObject across multiple invocations of iTunes.
|
||||
*
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITObject {
|
||||
|
||||
protected Dispatch object;
|
||||
|
||||
public ITObject(Dispatch d) {
|
||||
object = d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the JACOB Dispatch object for this object.
|
||||
* @return Returns the JACOB Dispatch object for this object.
|
||||
*/
|
||||
public Dispatch fetchDispatch() {
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the object.
|
||||
* @param name The new name of the object.
|
||||
*/
|
||||
public void setName (String name) {
|
||||
Dispatch.put(object, "Name", name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the object.
|
||||
* @return Returns the name of the object.
|
||||
*/
|
||||
public String getName() {
|
||||
return Dispatch.get(object, "Name").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the object in internal application order.
|
||||
* @return The index of the object in internal application order.
|
||||
*/
|
||||
public int getIndex() {
|
||||
return Dispatch.get(object, "Index").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID that identifies the source.
|
||||
* @return Returns the ID that identifies the source.
|
||||
*/
|
||||
public int getSourceID() {
|
||||
return Dispatch.get(object, "SourceID").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID that identifies the playlist.
|
||||
* @return Returns the ID that identifies the playlist.
|
||||
*/
|
||||
public int getPlaylistID() {
|
||||
return Dispatch.get(object, "PlaylistID").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID that identifies the track within the playlist.
|
||||
* @return Returns the ID that identifies the track within the playlist.
|
||||
*/
|
||||
public int getTrackID() {
|
||||
return Dispatch.get(object, "TrackID").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID that identifies the track, independent of its playlist.
|
||||
* @return Returns the ID that identifies the track, independent of its playlist.
|
||||
*/
|
||||
public int getTrackDatabaseID() {
|
||||
return Dispatch.get(object, "TrackDatabaseID").getInt();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.dt.iTunesController;
|
||||
|
||||
/**
|
||||
* Simple utility wrapper class to represent the persistent object identity
|
||||
* ID numbers. Use the getHigh() and getLow() methods individually to get
|
||||
* each ID, or the combined hex string through toString().
|
||||
*
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITObjectPersistentID {
|
||||
|
||||
private long High;
|
||||
private long Low;
|
||||
private String hexString;
|
||||
|
||||
/**
|
||||
* Create the ITObjectPersistentID. This class is not intended to be created
|
||||
* manually, and this function should only be used by classes implementing
|
||||
* this utility.
|
||||
* @param high The High Persistent ID
|
||||
* @param low The Low Persistent ID
|
||||
*/
|
||||
public ITObjectPersistentID(long high, long low) {
|
||||
this.High=high;
|
||||
this.Low=low;
|
||||
this.hexString = String.format("%8s%8s",Long.toHexString(this.High),Long.toHexString(this.Low)).toUpperCase().replace(' ','0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the high persistent ID.
|
||||
* @return The high persistent ID.
|
||||
*/
|
||||
public long getHigh() {
|
||||
return this.High;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the low persistent ID.
|
||||
* @return The low persistent ID.
|
||||
*/
|
||||
public long getLow() {
|
||||
return this.Low;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation (in hex) of the persistent IDs.
|
||||
* @return String representation of the persistent IDs.
|
||||
*/
|
||||
public String toString() {
|
||||
return this.hexString;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents the status of an asynchronous add or convert operation.
|
||||
*
|
||||
* When a track is added using TLibraryPlaylist.addFile(),
|
||||
* ITLibraryPlaylist.AddFiles(), IITUserPlaylist.addFile(), or
|
||||
* ITUserPlaylist.addFiles(), the add may not complete immediately if iTunes
|
||||
* needs to make a copy of the file.
|
||||
*
|
||||
* Similarly, when converting or importing a file or track using
|
||||
* <code>iTunes.convertFile()</code>, <code>iTunes.convertFiles()</code>,
|
||||
* <code>iTunes.convertTrack()</code> or <code>iTunes.convertTracks()</code>,
|
||||
* the conversion will never complete immediately.
|
||||
*
|
||||
* These methods return an <code>ITOperationStatus</code> object, which can be
|
||||
* polled todetermine when the operation is done. This object will also return
|
||||
* the collection of newly added or converted tracks.
|
||||
*
|
||||
* As of version 1.1 of the iTunes type library, you should use
|
||||
* <code>iTunes.convertFile2()</code>, <code>iTunes.convertFiles2()</code>,
|
||||
* <code>iTunes.convertTrack2()</code> or <code>iTunes.convertTracks2()</code>
|
||||
* instead of the original convert methods. These new methods return an
|
||||
* <code>ITConvertOperationStatus</code> object to allow clients to retrieve
|
||||
* additional conversion progress information.
|
||||
*
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITOperationStatus {
|
||||
|
||||
protected Dispatch object;
|
||||
|
||||
public ITOperationStatus(Dispatch d) {
|
||||
object = d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the operation is still in progress.
|
||||
* You cannot retrieve the <code>ITOperationStatus.getTracks()</code>
|
||||
* property until the operation completes.
|
||||
* @return Returns true if the operation is still in progress.
|
||||
*/
|
||||
public boolean getInProgress() {
|
||||
return Dispatch.get(object, "InProgress").getBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection containing the tracks that were generated by the
|
||||
* operation.
|
||||
* You cannot retrieve this property until
|
||||
* <code>ITOperationStatus.getInProgress()</code> returns false
|
||||
* @return Returns a collection containing the tracks that were generated by
|
||||
* the operation.
|
||||
*/
|
||||
public ITTrackCollection getTracks() {
|
||||
Dispatch tracks = Dispatch.get(object, "Tracks").toDispatch();
|
||||
return new ITTrackCollection(tracks);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.dt.iTunesController;
|
||||
|
||||
/**
|
||||
* Specifies the state of the player.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public enum ITPlayerState {
|
||||
ITPlayerStateStopped,
|
||||
ITPlayerStatePlaying,
|
||||
ITPlayerStateFastForward,
|
||||
ITPlayerStateRewind;
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents a playlist.
|
||||
*
|
||||
* A playlist is always associated with an ITSource.
|
||||
*
|
||||
* You can retrieve all the playlists defined for a source using
|
||||
* <code>ITSource.getPlaylists()</code>.
|
||||
*
|
||||
* For convenience, you can retrieve the main library playlist using
|
||||
* <code>iTunes.getLibraryPlaylist()</code>.
|
||||
*
|
||||
* You can create a new playlist using <code>iTunes.createPlaylist()</code>.
|
||||
*
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITPlaylist extends ITObject {
|
||||
|
||||
public ITPlaylist (Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete this object.
|
||||
*/
|
||||
public void delete() {
|
||||
Dispatch.call(object, "Delete");
|
||||
}
|
||||
|
||||
/**
|
||||
* Start playing the first track in this object.
|
||||
*/
|
||||
public void playFirstTrack() {
|
||||
Dispatch.call(object, "PlayFirstTrack");
|
||||
}
|
||||
|
||||
/**
|
||||
* Print this object.
|
||||
* @param showPrintDialog If true, display the print dialog.
|
||||
* @param printKind The printout kind.
|
||||
* @param theme The name of the theme to use. This corresponds to the name
|
||||
* of a Theme combo box item in the print dialog for the specified printKind
|
||||
* (e.g. "Track length"). This string cannot be longer than 255 characters,
|
||||
* but it may be empty.
|
||||
*/
|
||||
public void print(boolean showPrintDialog, ITPlaylistPrintKind printKind, String theme) {
|
||||
Dispatch.call(object, "Print", showPrintDialog, printKind.ordinal(), theme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection containing the tracks with the specified text.
|
||||
* @param searchText The text to search for. This string cannot be longer
|
||||
* than 255 chracters.
|
||||
* @param searchFields Specifies which fields of each track should be
|
||||
* searched for searchText.
|
||||
* @return Collection of IITTrack objects. This will be NULL if no tracks
|
||||
* meet the search criteria.
|
||||
*/
|
||||
public ITTrackCollection search (String searchText, ITPlaylistSearchField searchFields) {
|
||||
Dispatch collection = Dispatch.call(object, "Search", searchText, searchFields.ordinal()).getDispatch();
|
||||
return new ITTrackCollection(collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kind of the object.
|
||||
* @return Returns the kind of the object.
|
||||
*/
|
||||
public ITPlaylistKind getKind() {
|
||||
return ITPlaylistKind.values()[Dispatch.get(object, "Kind").getInt()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ITSource object corresponding to the source that contains the
|
||||
* object.
|
||||
* @return Returns an ITSource object corresponding to the source that
|
||||
* contains the object.
|
||||
*/
|
||||
public ITSource getSource() {
|
||||
Dispatch source = Dispatch.get(object, "Source").toDispatch();
|
||||
return new ITSource(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total length of all songs in the object (in seconds).
|
||||
* @return Returns the total length of all songs in the object (in
|
||||
* seconds).
|
||||
*/
|
||||
public int getDuration() {
|
||||
return Dispatch.get(object, "Duration").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether songs in the object should be played in random order.
|
||||
* @param shouldShuffle True if songs in the object should be played in
|
||||
* random order.
|
||||
*/
|
||||
public void setShuffle(boolean shouldShuffle) {
|
||||
Dispatch.put(object, "Shuffle", shouldShuffle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total size of all songs in the object (in bytes).
|
||||
* @return Returns the total size of all songs in the object (in bytes).
|
||||
*/
|
||||
public double getSize() {
|
||||
return Dispatch.get(object, "Size").getDouble();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the playback repeat mode.
|
||||
* @param repeatMode The new playback repeat mode.
|
||||
*/
|
||||
public void setSongRepeat(ITPlaylistRepeatMode repeatMode) {
|
||||
Dispatch.put(object, "SongRepeat", repeatMode.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Cycle repeat modes.
|
||||
*/
|
||||
public void cycleSongRepeat() {
|
||||
int repeat = Dispatch.get(object, "SongRepeat").getInt();
|
||||
Dispatch.put(object, "SongRepeat", (repeat + 1) % 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the playback repeat mode.
|
||||
* @return Returns the playback repeat mode.
|
||||
*/
|
||||
public ITPlaylistRepeatMode getSongRepeat() {
|
||||
return ITPlaylistRepeatMode.values()[Dispatch.get(object, "SongRepeat").getInt()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total length of all songs in the object (in MM:SS format).
|
||||
* @return Returns the total length of all songs in the object (in
|
||||
* MM:SS format).
|
||||
*/
|
||||
public String getTime() {
|
||||
return Dispatch.get(object, "Time").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the object is visible in the sources list.
|
||||
* @return True if the object is visible in the sources list.
|
||||
*/
|
||||
public boolean getVisible() {
|
||||
return Dispatch.get(object, "Visible").getBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection containing the tracks in this object.
|
||||
* @return Collection of ITTrack objects.
|
||||
*/
|
||||
public ITTrackCollection getTracks() {
|
||||
Dispatch tracks = Dispatch.get(object, "Tracks").toDispatch();
|
||||
return new ITTrackCollection(tracks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shuffle state.
|
||||
* @return true if current state is shuffle.
|
||||
*/
|
||||
public boolean getShuffle() {
|
||||
return Dispatch.get(object, "Shuffle").getBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the shuffle state.
|
||||
*/
|
||||
public void toggleShuffle() {
|
||||
setShuffle(!getShuffle());
|
||||
}
|
||||
|
||||
public boolean containsTrack(ITTrack track) {
|
||||
return getTracks().containsTrack(track);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents a collection of playlist objects.
|
||||
*
|
||||
* Note that collection indices are always 1-based.
|
||||
*
|
||||
* You can retrieve all the playlists defined for a source using
|
||||
* <code>ITSource.getPlaylists()</code>.
|
||||
*
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITPlaylistCollection {
|
||||
|
||||
protected Dispatch object;
|
||||
|
||||
public ITPlaylistCollection(Dispatch d) {
|
||||
object = d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of playlists in the collection.
|
||||
* @return Returns the number of playlists in the collection.
|
||||
*/
|
||||
public int getCount() {
|
||||
return Dispatch.get(object, "Count").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ITPlaylist object corresponding to the given index (1-based).
|
||||
* @param index Index of the playlist to retrieve, must be less than or
|
||||
* equal to <code>ITPlaylistCollection.getCount()</code>.
|
||||
* @return Returns an ITPlaylist object corresponding to the given index.
|
||||
* Will be set to NULL if no playlist could be retrieved.
|
||||
*/
|
||||
public ITPlaylist getItem (int index) {
|
||||
Dispatch item = Dispatch.call(object, "Item", index).toDispatch();
|
||||
return new ITPlaylist(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ITPlaylist object withthe specified name.
|
||||
* @param name The name of the playlist to retrieve.
|
||||
* @return Returns an ITPlaylist object corresponding to the given index.
|
||||
* Will be set to NULL if no playlist could be retrieved.
|
||||
*/
|
||||
public ITPlaylist ItemByName (String name) {
|
||||
Dispatch item = Dispatch.call(object, "ItemByName", name).toDispatch();
|
||||
return new ITPlaylist(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ITPlaylist object with the specified persistent ID. See the
|
||||
* documentation on ITObject for more information on persistent IDs.
|
||||
* @param highID The high 32 bits of the 64-bit persistent ID.
|
||||
* @param lowID The low 32 bits of the 64-bit persistent ID.
|
||||
* @return Returns an ITPlaylist object with the specified persistent ID.
|
||||
* Will be set to NULL if no playlist could be retrieved.
|
||||
*/
|
||||
public ITPlaylist getItemByPersistentID (int highID, int lowID) {
|
||||
Dispatch item = Dispatch.call(object, "ItemByPersistentID", highID, lowID).toDispatch();
|
||||
return new ITPlaylist(item);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.dt.iTunesController;
|
||||
|
||||
/**
|
||||
* Specifies the playlist kind.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public enum ITPlaylistKind {
|
||||
ITPlaylistKindUnknown,
|
||||
ITPlaylistKindLibrary,
|
||||
ITPlaylistKindUser,
|
||||
ITPlaylistKindCD,
|
||||
ITPlaylistKindDevice,
|
||||
ITPlaylistKindRadioTuner;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.dt.iTunesController;
|
||||
|
||||
/**
|
||||
* Specifies the kind of playlist printout.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public enum ITPlaylistPrintKind {
|
||||
|
||||
ITPlaylistPrintKindPlaylist,
|
||||
ITPlaylistPrintKindAlbumlist,
|
||||
ITPlaylistPrintKindInsert;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.dt.iTunesController;
|
||||
|
||||
/**
|
||||
* Specifies the playlist playback repeat mode.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public enum ITPlaylistRepeatMode {
|
||||
|
||||
ITPlaylistRepeatModeOff,
|
||||
ITPlaylistRepeatModeOne,
|
||||
ITPlaylistRepeatModeAll;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.dt.iTunesController;
|
||||
|
||||
/**
|
||||
* Specifies the fields in each track that will be searched by
|
||||
* <code>ITPlaylist.search()</code>.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public enum ITPlaylistSearchField {
|
||||
ITPlaylistSearchFieldAll,
|
||||
ITPlaylistSearchFieldVisible,
|
||||
ITPlaylistSearchFieldArtists,
|
||||
ITPlaylistSearchFieldAlbums,
|
||||
ITPlaylistSearchFieldComposers,
|
||||
ITPlaylistSearchFieldSongNames;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.dt.iTunesController;
|
||||
|
||||
/**
|
||||
* Specifies the rating kind.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public enum ITRatingKind {
|
||||
ITRatingKindUser,
|
||||
ITRatingKindComputed;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents an entry in the Source list (music library, CD, device, etc.).
|
||||
* You can retrieve all the sources using <code>iTunes.getSources()</code>.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITSource extends ITObject {
|
||||
|
||||
public ITSource(Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kind of the source.
|
||||
* @return Returns the kind of the source.
|
||||
*/
|
||||
public ITSourceKind getKind() {
|
||||
return ITSourceKind.values()[Dispatch.get(object, "Kind").getInt()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total size of the source, if it has a fixed size.
|
||||
* @return Returns the total size of the source, if it has a fixed size.
|
||||
*/
|
||||
public double getCapacity() {
|
||||
return Dispatch.get(object, "Capacity").getDouble();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the free space on the source, if it has a fixed size.
|
||||
* @return Returns the free space on the source, if it has a fixed size.
|
||||
*/
|
||||
public double getFreespace() {
|
||||
return Dispatch.get(object, "Freespace").getDouble();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection containing the playlists in this source.
|
||||
* The source's primary playlist is always the first playlist in the
|
||||
* collection.
|
||||
* @return Collection of IITPlaylist objects.
|
||||
*/
|
||||
public ITPlaylistCollection getPlaylists() {
|
||||
Dispatch playlists = Dispatch.get(object, "Playlists").toDispatch();
|
||||
return new ITPlaylistCollection(playlists);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents a collection of source objects.
|
||||
*
|
||||
* Note that collection indices are always 1-based.
|
||||
*
|
||||
* You can retrieve all the sources using <code>ITSource.getSources()</code>.
|
||||
*
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITSourceCollection {
|
||||
|
||||
protected Dispatch object;
|
||||
|
||||
public ITSourceCollection(Dispatch d) {
|
||||
object = d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of sources in the collection.
|
||||
* @return Returns the number of sources in the collection.
|
||||
*/
|
||||
public int getCount() {
|
||||
return Dispatch.get(object, "Count").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ITSource object corresponding to the given index (1-based).
|
||||
* @param index Index of the source to retrieve, must be less than or
|
||||
* equal to <code>ITSourceCollection.getCount()</code>.
|
||||
* @return Returns an ITSource object corresponding to the given index.
|
||||
* Will be set to NULL if no source could be retrieved.
|
||||
*/
|
||||
public ITSource getItem (int index) {
|
||||
Dispatch item = Dispatch.call(object, "Item", index).toDispatch();
|
||||
return new ITSource(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ITSource object withthe specified name.
|
||||
* @param name The name of the source to retrieve.
|
||||
* @return Returns an ITSource object corresponding to the given index.
|
||||
* Will be set to NULL if no source could be retrieved.
|
||||
*/
|
||||
public ITSource getItemByName (String name) {
|
||||
Dispatch item = Dispatch.call(object, "ItemByName", name).toDispatch();
|
||||
return new ITSource(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ITSource object with the specified persistent ID. See the
|
||||
* documentation on ITObject for more information on persistent IDs.
|
||||
* @param highID The high 32 bits of the 64-bit persistent ID.
|
||||
* @param lowID The low 32 bits of the 64-bit persistent ID.
|
||||
* @return Returns an ITSource object with the specified persistent ID.
|
||||
* Will be set to NULL if no source could be retrieved.
|
||||
*/
|
||||
public ITSource getItemByPersistentID (int highID, int lowID) {
|
||||
Dispatch item = Dispatch.call(object, "ItemByPersistentID", highID, lowID).toDispatch();
|
||||
return new ITSource(item);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.dt.iTunesController;
|
||||
|
||||
/**
|
||||
* Specifies the source kind.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public enum ITSourceKind {
|
||||
ITSourceKindUnknown,
|
||||
ITSourceKindLibrary,
|
||||
ITSourceKindIPod,
|
||||
ITSourceKindAudioCD,
|
||||
ITSourceKindMP3CD,
|
||||
ITSourceKindDevice,
|
||||
ITSourceKindRadioTuner,
|
||||
ITSourceKindSharedLibrary;
|
||||
}
|
||||
@@ -0,0 +1,493 @@
|
||||
package com.dt.iTunesController;
|
||||
import java.util.Date;
|
||||
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents a track.
|
||||
*
|
||||
* A track represents a song in a single playlist. A song may be in more than
|
||||
* one playlist, in which case it would be represented by multiple tracks.
|
||||
*
|
||||
* You can retrieve the currently targeted (playing) track using
|
||||
* <code>iTunes.getCurrentTrack()</code>.
|
||||
*
|
||||
* Typically, an ITrack is accessed through an ITTrackCollection.
|
||||
*
|
||||
* You can retrieve all the tracks defined for a playlist using
|
||||
* <code>ITPlaylist.getTracks()</code>.
|
||||
*
|
||||
* You can retrieve the currently selected track or tracks using
|
||||
* <code>iTunes.getSelectedTracks()</code>.
|
||||
*
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITTrack extends ITObject {
|
||||
|
||||
public ITTrack (Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete this object.
|
||||
*/
|
||||
public void delete() {
|
||||
Dispatch.call(object, "Delete");
|
||||
}
|
||||
|
||||
/**
|
||||
* Start playing this object.
|
||||
*/
|
||||
public void play() {
|
||||
Dispatch.call(object, "Play");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the album containing the object.;
|
||||
* @param album The new name of the album containing the object.
|
||||
*/
|
||||
public void setAlbum(String album) {
|
||||
Dispatch.put(object, "Album", album);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the album containing the object.
|
||||
* @return Returns the name of the album containing the object.
|
||||
*/
|
||||
public String getAlbum() {
|
||||
return Dispatch.get(object, "Album").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the artist/source of the object.
|
||||
* @param artist The new artist/source of the object.
|
||||
*/
|
||||
public void setArtist(String artist) {
|
||||
Dispatch.put(object, "Artist", artist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the artist/source of the object.
|
||||
* @return Returns the name of the artist/source of the object.
|
||||
*/
|
||||
public String getArtist() {
|
||||
return Dispatch.get(object, "Artist").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bit rate of the object (in kbps).
|
||||
* @return Returns the bit rate of the object (in kbps).
|
||||
*/
|
||||
public int getBitRate() {
|
||||
return Dispatch.get(object, "BitRate").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the tempo of the object (in beats per minute).
|
||||
* @param beatsPerMinute The new tempo of the object (in beats per minute).
|
||||
*/
|
||||
public void setBPM(int beatsPerMinute) {
|
||||
Dispatch.put(object, "BPM", beatsPerMinute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tempo of the object (in beats per minute).
|
||||
* @return Returns the tempo of the object (in beats per minute).
|
||||
*/
|
||||
public int getBPM() {
|
||||
return Dispatch.get(object, "BPM").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set freeform notes about the object.
|
||||
* @param comment The new freeform notes about the object.
|
||||
*/
|
||||
public void setComment(String comment) {
|
||||
Dispatch.put(object, "Comment", comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns freeform notes about the object.
|
||||
* @return Returns freeform notes about the object.
|
||||
*/
|
||||
public String getComment() {
|
||||
return Dispatch.get(object, "Comment").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this object is from a compilation album.
|
||||
* @param isCompilation True if this object should be from a compilation album.
|
||||
*/
|
||||
public void setCompilation(boolean isCompilation) {
|
||||
Dispatch.put(object, "Compilation", isCompilation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this object is from a compilation album.
|
||||
* @return Returns true if this object is from a compilation album.
|
||||
*/
|
||||
public boolean getCompilation() {
|
||||
return Dispatch.get(object, "Compilation").getBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the composer of the object.
|
||||
* @param composer The new composer of the object.
|
||||
*/
|
||||
public void setComposer (String composer) {
|
||||
Dispatch.put(object, "Composer", composer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the composer of the object.
|
||||
* @return Returns the composer of the object.
|
||||
*/
|
||||
public String getComposer() {
|
||||
return Dispatch.get(object, "Composer").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date the object was added to the playlist.
|
||||
* @return Returns the date the object was added to the playlist.
|
||||
*/
|
||||
public Date getDateAdded() {
|
||||
return Dispatch.get(object, "DateAdded").getJavaDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the total number of discs in the source album.
|
||||
* @param discCount The new total number of discs in the source album.
|
||||
*/
|
||||
public void setDiscCount (int discCount) {
|
||||
Dispatch.put(object, "DiscCount", discCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total number of discs in the source album.
|
||||
* @return Returns the total number of discs in the source album.
|
||||
*/
|
||||
public int getDiscCount() {
|
||||
return Dispatch.get(object, "DiscCount").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the index of the disc containing the object on the source album.
|
||||
* @param discNumber The new index of the disc containing the object on the
|
||||
* source album.
|
||||
*/
|
||||
public void setDiscNumber (int discNumber) {
|
||||
Dispatch.put(object, "DiscNumber", discNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the disc containing the object on the source album.
|
||||
* @return Returns the index of the disc containing the object on the source
|
||||
* album.
|
||||
*/
|
||||
public int getDiscNumber() {
|
||||
return Dispatch.get(object, "DiscNumber").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the object (in seconds).
|
||||
* @return Returns the length of the object (in seconds).
|
||||
*/
|
||||
public int getDuration() {
|
||||
return Dispatch.get(object, "Duration").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this object is checked for playback.
|
||||
* @param shouldBeEnabled True if the object should be checked for playback.
|
||||
*/
|
||||
public void setEnabled (boolean shouldBeEnabled) {
|
||||
Dispatch.put(object, "Enabled", shouldBeEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the object is checked for playback.
|
||||
* @return Returns true if the object is checked for playback.
|
||||
*/
|
||||
public boolean getEnabled() {
|
||||
return Dispatch.get(object, "Enabled").getBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the EQ preset of the object.
|
||||
* @param eq The new name of the EQ preset of the object.
|
||||
*/
|
||||
public void setEQ (String eq) {
|
||||
Dispatch.put(object, "EQ", eq);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the EQ preset of the object.
|
||||
* @return Returns the name of the EQ preset of the object.
|
||||
*/
|
||||
public String getEQ() {
|
||||
return Dispatch.get(object, "EQ").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the stop time of the object (in seconds).
|
||||
* @param finish The new stop time of the object (in seconds).
|
||||
*/
|
||||
public void setFinish(int finish) {
|
||||
Dispatch.put(object, "Finish", finish);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the stop time of the object (in seconds).
|
||||
* @return Returns the stop time of the object (in seconds).
|
||||
*/
|
||||
public int getFinish() {
|
||||
return Dispatch.get(object, "Finish").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the music/audio genre (category) of the object.
|
||||
* @param genre Returns the music/audio genre (category) of the object.
|
||||
*/
|
||||
public void setGenre(String genre) {
|
||||
Dispatch.put(object, "Genre", genre);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the music/audio genre (category) of the object.
|
||||
* @return The new music/audio genre (category) of the object.
|
||||
*/
|
||||
public String getGenre() {
|
||||
return Dispatch.get(object, "Genre").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the grouping (piece) of the object.
|
||||
* Generally used to denote movements within classical work.
|
||||
* @param grouping The new grouping (piece) of the object.
|
||||
*/
|
||||
public void setGrouping (String grouping) {
|
||||
Dispatch.put(object, "Grouping", grouping);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the grouping (piece) of the object.
|
||||
* Generally used to denote movements within classical work.
|
||||
* @return Returns the grouping (piece) of the object.
|
||||
*/
|
||||
public String getGrouping() {
|
||||
return Dispatch.get(object, "Grouping").getString();
|
||||
}
|
||||
|
||||
public ITTrackKind getKind() {
|
||||
return ITTrackKind.values()[Dispatch.get(object, "Kind").getInt()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the text description of the object (e.g. "AAC audio file").
|
||||
* @return Returns the text description of the object (e.g. "AAC audio file").
|
||||
*/
|
||||
public String getKindAsString() {
|
||||
return Dispatch.get(object, "KindAsString").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the modification date of the content of the object.
|
||||
* @return Returns the modification date of the content of the object.
|
||||
*/
|
||||
public Date getModificationDate() {
|
||||
return Dispatch.get(object, "ModificationDate").getJavaDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of times the object has been played. This property cannot
|
||||
* be set if the object is not playable (e.g. a PDF file).
|
||||
* @param playedCount The new number of times the object has been played.
|
||||
*/
|
||||
public void setPlayedCount (int playedCount) {
|
||||
Dispatch.put(object, "PlayedCount", playedCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of times the object has been played.
|
||||
* @return Returns the number of times the object has been played.
|
||||
*/
|
||||
public int getPlayedCount() {
|
||||
return Dispatch.get(object, "PlayedCount").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the date and time the object was last played. This property cannot be
|
||||
* set if the object is not playable (e.g. a PDF file).
|
||||
* A value of zero means no played date.
|
||||
* @param playedDate The new date and time the object was last played.
|
||||
*/
|
||||
public void setPlayedDate (Date playedDate) {
|
||||
Dispatch.put(object, "PlayedDate", playedDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date and time the object was last played.
|
||||
* A value of zero means no played date.
|
||||
* @return Returns the date and time the object was last played.
|
||||
*/
|
||||
public Date getPlayedDate() {
|
||||
return Dispatch.get(object, "PlayedDate").getJavaDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ITPlaylist object corresponding to the playlist that contains
|
||||
* the object. Use ITFileOrCDTrack::Playlists() or IITURLTrack::Playlists()
|
||||
* to get the collection of all playlists that contain the song this object
|
||||
* represents.
|
||||
* @return Returns an ITPlaylist object corresponding to the playlist that
|
||||
* contains the object.
|
||||
*/
|
||||
public ITPlaylist getPlaylist() {
|
||||
Dispatch playlist = Dispatch.get(object, "Playlist").toDispatch();
|
||||
return new ITPlaylist(playlist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the play order index of the object in the owner playlist
|
||||
* (1-based).
|
||||
* You can pass this index to IITTrackCollection::ItemByPlayOrder() for the
|
||||
* collection returned by ITPlaylist::Tracks() to retrieve an ITTrack
|
||||
* object corresponding to this object.
|
||||
* @return Returns the play order index of the object in the owner playlist.
|
||||
*/
|
||||
public int getPlayOrderIndex() {
|
||||
return Dispatch.get(object, "PlayOrderIndex").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rating of the object (0 to 100). If the object rating is set to 0,
|
||||
* it will be computed based on the album rating.
|
||||
* @param rating The new rating of the object (0 to 100).
|
||||
*/
|
||||
public void setRating (int rating) {
|
||||
Dispatch.put(object, "Rating", rating);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the rating of the object (0 to 100). If the object rating has never
|
||||
* been set, or has been set to 0, it will be computed based on the album
|
||||
* rating.
|
||||
* @return Returns the rating of the object (0 to 100).
|
||||
*/
|
||||
public int getRating() {
|
||||
return Dispatch.get(object, "Rating").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sample rate of the object (in Hz).
|
||||
* @return Returns the sample rate of the object (in Hz).
|
||||
*/
|
||||
public int getSampleRate() {
|
||||
return Dispatch.get(object, "SampleRate").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the object (in bytes).
|
||||
* @return Returns the size of the object (in bytes).
|
||||
*/
|
||||
public int getSize() {
|
||||
return Dispatch.get(object, "Size").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the start time of the object (in seconds).
|
||||
* @param start The new start time of the object (in seconds).
|
||||
*/
|
||||
public void setStart (int start) {
|
||||
Dispatch.put(object, "Start", start);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the start time of the object (in seconds).
|
||||
* @return Returns the start time of the object (in seconds).
|
||||
*/
|
||||
public int getStart() {
|
||||
return Dispatch.get(object, "Start").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the object (in MM:SS format).
|
||||
* @return Returns the length of the object (in MM:SS format).
|
||||
*/
|
||||
public String getTime() {
|
||||
return Dispatch.get(object, "Time").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the total number of tracks on the source album.
|
||||
* @param trackCount The new total number of tracks on the source album.
|
||||
*/
|
||||
public void setTrackCount (int trackCount) {
|
||||
Dispatch.put(object, "TrackCount", trackCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total number of tracks on the source album.
|
||||
* @return Returns the total number of tracks on the source album.
|
||||
*/
|
||||
public int getTrackCount() {
|
||||
return Dispatch.get(object, "TrackCount").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the index of the object on the source album.
|
||||
* @param trackNumber The new index of the object on the source album.
|
||||
*/
|
||||
public void setTrackNumber (int trackNumber) {
|
||||
Dispatch.put(object, "TrackNumber", trackNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the object on the source album.
|
||||
* @return Returns the index of the object on the source album.
|
||||
*/
|
||||
public int getTrackNumber() {
|
||||
return Dispatch.get(object, "TrackNumebr").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the relative volume adjustment of the object (-100% to 100%).
|
||||
* @param volumeAdjustment Set the relative volume adjustment of the object
|
||||
* (-100% to 100%).
|
||||
*/
|
||||
public void setVolumeAdjustment (int volumeAdjustment) {
|
||||
Dispatch.put(object, "VolumeAdjustment", volumeAdjustment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the relative volume adjustment of the object (-100% to 100%).
|
||||
* @return Returns the relative volume adjustment of the object (-100% to 100%).
|
||||
*/
|
||||
public int getVolumeAdjustment() {
|
||||
return Dispatch.get(object, "VolumeAdjustment").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the year the object was recorded/released.
|
||||
* @param year The new year the object was recorded/released.
|
||||
*/
|
||||
public void setYear (int year) {
|
||||
Dispatch.put(object, "Year", year);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the year the object was recorded/released.
|
||||
* @return Returns the year the object was recorded/released.
|
||||
*/
|
||||
public int getYear() {
|
||||
return Dispatch.get(object, "Year").getInt();
|
||||
}
|
||||
|
||||
public ITArtworkCollection getArtwork() {
|
||||
Dispatch art = Dispatch.get(object, "Artwork").toDispatch();
|
||||
return new ITArtworkCollection(art);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents a collection of track objects.
|
||||
*
|
||||
* Note that collection indices are always 1-based.
|
||||
*
|
||||
* You can retrieve all the tracks defined for a playlist using
|
||||
* <code>ITPlaylist.getTracks()</code>.
|
||||
*
|
||||
* You can retrieve the currently selected track or tracks using
|
||||
* <code>iTunes.getSelectedTracks()</code>.
|
||||
*
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITTrackCollection {
|
||||
|
||||
protected Dispatch object;
|
||||
|
||||
public ITTrackCollection(Dispatch d) {
|
||||
object = d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of tracks in the collection.
|
||||
* @return Returns the number of tracks in the collection.
|
||||
*/
|
||||
public int getCount() {
|
||||
return Dispatch.get(object, "Count").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ITTrack object corresponding to the given index (1-based).
|
||||
* @param index Index of the track to retrieve, must be less than or
|
||||
* equal to <code>ITTrackCollection.getCount()</code>.
|
||||
* @return Returns an ITTrack object corresponding to the given index.
|
||||
* Will be set to NULL if no track could be retrieved.
|
||||
*/
|
||||
public ITTrack getItem (int index) {
|
||||
Dispatch item = Dispatch.call(object, "Item", index).toDispatch();
|
||||
ITTrack track = new ITTrack(item);
|
||||
if (track.getKind()==ITTrackKind.ITTrackKindFile) {
|
||||
return new ITFileOrCDTrack(item);
|
||||
} else if (track.getKind()==ITTrackKind.ITTrackKindCD) {
|
||||
return new ITFileOrCDTrack(item);
|
||||
} else if (track.getKind()==ITTrackKind.ITTrackKindURL ) {
|
||||
return new ITURLTrack(item);
|
||||
} else {
|
||||
return track;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ITTrack object corresponding to the given index (1-based).
|
||||
* @param index Index of the track to retrieve, must be less than or
|
||||
* equal to <code>ITTrackCollection.getCount()</code>.
|
||||
* @return Returns an ITTrack object corresponding to the given index.
|
||||
* Will be set to NULL if no track could be retrieved.
|
||||
*/
|
||||
public ITTrack getItemByPlayOrder(int index) {
|
||||
Dispatch item = Dispatch.call(object, "ItemByPlayOrder", index).toDispatch();
|
||||
return new ITTrack(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ITTrack object withthe specified name.
|
||||
* @param name The name of the track to retrieve.
|
||||
* @return Returns an ITTrack object corresponding to the given index.
|
||||
* Will be set to NULL if no track could be retrieved.
|
||||
*/
|
||||
public ITTrack ItemByName (String name) {
|
||||
Dispatch item = Dispatch.call(object, "ItemByName", name).toDispatch();
|
||||
return new ITTrack(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ITTrack object with the specified persistent ID. See the
|
||||
* documentation on ITObject for more information on persistent IDs.
|
||||
* @param highID The high 32 bits of the 64-bit persistent ID.
|
||||
* @param lowID The low 32 bits of the 64-bit persistent ID.
|
||||
* @return Returns an ITTrack object with the specified persistent ID.
|
||||
* Will be set to NULL if no track could be retrieved.
|
||||
*/
|
||||
public ITTrack getItemByPersistentID (int highID, int lowID) {
|
||||
Dispatch item = Dispatch.call(object, "ItemByPersistentID", highID, lowID).toDispatch();
|
||||
return new ITTrack(item);
|
||||
}
|
||||
|
||||
public boolean containsTrack(ITTrack track) {
|
||||
String name = track.getName();
|
||||
try {
|
||||
return ItemByName(name).getName().equals(name);
|
||||
} catch (IllegalStateException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.dt.iTunesController;
|
||||
|
||||
/**
|
||||
* Specifies the track kind.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public enum ITTrackKind {
|
||||
ITTrackKindUnknown,
|
||||
ITTrackKindFile,
|
||||
ITTrackKindCD,
|
||||
ITTrackKindURL,
|
||||
ITTrackKindDevice,
|
||||
ITTrackKindSharedLibrary;
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents a URL track.
|
||||
*
|
||||
* A URL track references a network audio stream.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITURLTrack extends ITTrack {
|
||||
|
||||
public ITURLTrack (Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL of the stream represented by this track.
|
||||
* @return The URL of the stream represented by this track.
|
||||
*/
|
||||
public String getURL () {
|
||||
return Dispatch.get(object, "URL").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the URL of the stream represented by this track.
|
||||
* @param url The URL of the stream represented by this track.
|
||||
*/
|
||||
public void setURL (String url) {
|
||||
Dispatch.call(object, "URL", url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this track is a podcast track. If a podcast track is an
|
||||
* <code>IITURLTrack</code>, the podcast episode has not been downloaded.
|
||||
* @return Returns true if this track is a podcast track.
|
||||
*/
|
||||
public boolean isPodcast () {
|
||||
return Dispatch.get(object, "Podcast").getBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the category for the track.
|
||||
* @return Returns the category for the track.
|
||||
*/
|
||||
public String getCategory () {
|
||||
return Dispatch.get(object, "Category").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the category for the track.
|
||||
* @param category Sets the category for the track.
|
||||
*/
|
||||
public void setCategory (String category) {
|
||||
Dispatch.call(object, "Category", category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description for the track.
|
||||
* @return Returns the description for the track.
|
||||
*/
|
||||
public String getDescription () {
|
||||
return Dispatch.get(object, "Description").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the description for the track.
|
||||
* @param description The new description for the track.
|
||||
*/
|
||||
public void setDescription (String description) {
|
||||
Dispatch.call(object, "Description", description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the long description for the track.
|
||||
* @return Returns the description for the track.
|
||||
*/
|
||||
public String getLongDescription () {
|
||||
return Dispatch.get(object, "LongDescription").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the long description for the track.
|
||||
* @param longDescription The new long description for the track.
|
||||
*/
|
||||
public void setLongDescription (String longDescription) {
|
||||
Dispatch.call(object, "LongDescription", longDescription);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user or computed rating of the album that this track belongs
|
||||
* to (0 to 100). If the album rating has never been set, or has been set to
|
||||
* 0, it will be computed based on the ratings of tracks in the album.
|
||||
* @return Returns the album rating of the album that this track belongs to (0 to 100).
|
||||
*/
|
||||
public long getAlbumRating () {
|
||||
return Dispatch.get(object, "AlbumRating").getLong();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the album rating of the album that this track belongs to (0 to 100).
|
||||
* If the album rating is set to 0, it will be computed based on the ratings
|
||||
* of tracks in the album.
|
||||
* @param albumRating The new album rating of the album that this track
|
||||
* belongs to (0 to 100). If rating is outside this range, it will be
|
||||
* pinned.
|
||||
*/
|
||||
public void setAlbumRating (long albumRating) {
|
||||
Dispatch.call(object, "AlbumRating", albumRating);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the album rating kind. If the album rating has never been set, or
|
||||
* has been set to 0, the kind is ITRatingKindComputed. Otherwise, the kind
|
||||
* is ITRatingKindUser.
|
||||
* @return Returns the album rating kind.
|
||||
*/
|
||||
public ITRatingKind getAlbumRatingKind () {
|
||||
return ITRatingKind.values()[Dispatch.get(object, "AlbumRatingKind").getInt()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the track rating kind. If the track rating has never been set, or
|
||||
* has been set to 0, the kind is ITRatingKindComputed. Otherwise, the kind
|
||||
* is ITRatingKindUser.
|
||||
* @return Returns the track rating kind.
|
||||
*/
|
||||
public ITRatingKind getRatingKind () {
|
||||
return ITRatingKind.values()[Dispatch.get(object, "RatingKind").getInt()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of playlists that contain the song that this track
|
||||
* represents.
|
||||
*
|
||||
* This is the same collection of playlists that are shown in the "Show in
|
||||
* Playlist" contextual menu for a track, plus the specific playlist that
|
||||
* contains this track.
|
||||
*
|
||||
* A track represents a song in a single playlist, use
|
||||
* <code>ITTrack.getPlaylist()</code> to get the specific playlist that
|
||||
* contains this track.
|
||||
* @return Collection of ITPlaylist objects.
|
||||
*/
|
||||
public ITPlaylistCollection getPlaylists () {
|
||||
Dispatch playlists = Dispatch.get(object, "Playlists").toDispatch();
|
||||
return new ITPlaylistCollection(playlists);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the podcast feed for this track. This is equivalent to the user
|
||||
* choosing Update Podcast from the contextual menu for the podcast feed
|
||||
* that contains this track.
|
||||
*/
|
||||
public void updatePodcastFeed () {
|
||||
Dispatch.call(object, "UpdatePodcastFeed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Start downloading the podcast episode that corresponds to this track.
|
||||
* This is equivalent to the user clicking the Get button next to this
|
||||
* track.
|
||||
*/
|
||||
public void downloadPodcastEpisode () {
|
||||
Dispatch.call(object, "DownloadPodcastEpisode");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reveals the track in the main browser window.
|
||||
*/
|
||||
public void reveal() {
|
||||
Dispatch.call(object, "Reveal");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents a user-defined playlist.
|
||||
*
|
||||
* A user playlist includes both smart and manual user-defined playlists.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITUserPlaylist extends ITPlaylist {
|
||||
|
||||
public ITUserPlaylist(Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a file or files inside a folder to the playlist.
|
||||
* You cannot use this method to add a file that requires conversion to be
|
||||
* added (e.g. a CD track), use <code>iTunes.convertFile()</code> or
|
||||
* <code>iTunes.convertFile2()</code> instead. If you add a folder that
|
||||
* contains files that require conversion, they will be skipped.
|
||||
* @param filePath The full path to the file or folder to add.
|
||||
* @return Returns an ITOperationStatus object corresponding to the
|
||||
* asynchronous operation. If an error occurs, or no files were added, this
|
||||
* will be set to <code>NULL</code>.
|
||||
*/
|
||||
public ITOperationStatus addFile (String filePath) {
|
||||
Dispatch status = Dispatch.call(object, "AddFile", filePath).toDispatch();
|
||||
return new ITOperationStatus(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a streaming audio URL to the playlist.
|
||||
* @param url The URL to add. The length of the URL can be 255 characters or
|
||||
* less.
|
||||
* @return Returns an ITURLTrack object corresponding to the new track.
|
||||
*/
|
||||
public ITURLTrack addURL (String url) {
|
||||
Dispatch URLTrack = Dispatch.call(object, "AddURL", url).toDispatch();
|
||||
return new ITURLTrack(URLTrack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an existing track to the playlist.
|
||||
* You cannot use this method to add a CD track (ITTrackKindCD) to another
|
||||
* playlist, use <code>iTunes.convertTrack()</code> or
|
||||
* <code>iTunes.convertTrack2()</code> instead.
|
||||
* You cannot add a shared library track (ITTrackKindSharedLibrary) to
|
||||
* another playlist.
|
||||
* @param track The track to add.
|
||||
* @return Returns an IITTrack object corresponding to the new track.
|
||||
*/
|
||||
public ITTrack addTrack (ITTrack track) {
|
||||
Dispatch trackToAdd = track.fetchDispatch();
|
||||
Dispatch addedTrack = Dispatch.call(object, "AddTrack", trackToAdd).toDispatch();
|
||||
return new ITTrack(addedTrack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.dt.iTunesController;
|
||||
|
||||
/**
|
||||
* Specifies the Video kind.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public enum ITVideoKind {
|
||||
ITVideoKindNone,
|
||||
ITVideoKindMovie,
|
||||
ITVideoKindMusicVideo,
|
||||
ITVideoKindTVShow;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents an iTunes window.
|
||||
*/
|
||||
|
||||
public class ITWindow {
|
||||
|
||||
protected Dispatch object;
|
||||
|
||||
public ITWindow(Dispatch d) {
|
||||
object = d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the JACOB Dispatch object for this object.
|
||||
* @return Returns the JACOB Dispatch object for this object.
|
||||
*/
|
||||
public Dispatch fetchDispatch() {
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the object.
|
||||
* @return Returns the name of the object.
|
||||
*/
|
||||
public String getName() {
|
||||
return Dispatch.get(object, "Name").getString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
|
||||
/**
|
||||
* Represents a collection of window objects.
|
||||
*
|
||||
* Note that collection indices are always 1-based.
|
||||
*
|
||||
* You can retrieve all the windows using
|
||||
* <code>iTunes.getWindows()</code>.
|
||||
*
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class ITWindowCollection {
|
||||
|
||||
protected Dispatch object;
|
||||
|
||||
public ITWindowCollection(Dispatch d) {
|
||||
object = d;
|
||||
}
|
||||
|
||||
// TODO: iTunes.getWindows()
|
||||
|
||||
/**
|
||||
* Returns the number of playlists in the collection.
|
||||
* @return Returns the number of playlists in the collection.
|
||||
*/
|
||||
public int getCount() {
|
||||
return Dispatch.get(object, "Count").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ITWindow object corresponding to the given index (1-based).
|
||||
* @param index Index of the playlist to retrieve, must be less than or
|
||||
* equal to <code>ITWindowCollection.getCount()</code>.
|
||||
* @return Returns an ITWindow object corresponding to the given index.
|
||||
* Will be set to NULL if no playlist could be retrieved.
|
||||
*/
|
||||
public ITWindow getItem (int index) {
|
||||
Dispatch item = Dispatch.call(object, "Item", index).toDispatch();
|
||||
return new ITWindow(item);
|
||||
}
|
||||
/**
|
||||
* Returns an ITWindow object with the specified name.
|
||||
* @param name The name of the window to retrieve.
|
||||
* @return Returns an ITWindow object corresponding to the given index.
|
||||
* Will be set to NULL if no ITWindow could be retrieved.
|
||||
*/
|
||||
public ITWindow ItemByName (String name) {
|
||||
Dispatch item = Dispatch.call(object, "ItemByName", name).toDispatch();
|
||||
return new ITWindow(item);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,539 @@
|
||||
package com.dt.iTunesController;
|
||||
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.ComThread;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.DispatchEvents;
|
||||
|
||||
/**
|
||||
* Defines the top-level iTunes application object.
|
||||
*
|
||||
* This interface defines the top-level iTunes application object. All other
|
||||
* iTunes interfaces are accessed through this object.
|
||||
*
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class iTunes {
|
||||
ActiveXComponent iTunes;
|
||||
iTunesEvents iTunesEvents;
|
||||
DispatchEvents dispatchEvents;
|
||||
|
||||
/**
|
||||
* Initiate iTunes Controller.
|
||||
* @return
|
||||
*/
|
||||
public void connect() {
|
||||
iTunes = new ActiveXComponent("iTunes.Application");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event handler to the iTunes controller.
|
||||
* @param itef The class that will handle the iTunes events.
|
||||
*/
|
||||
public void addEventHandler(iTunesEventsInterface itef) {
|
||||
iTunesEvents = new iTunesEvents(itef);
|
||||
dispatchEvents = new DispatchEvents(iTunes, iTunesEvents);
|
||||
//System.out.println("New event handler added.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reposition to the beginning of the current track or go to the previous
|
||||
* track if already at start of current track.
|
||||
*/
|
||||
public void backTrack() {
|
||||
iTunes.invoke("BackTrack");
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip forward in a playing track.
|
||||
*/
|
||||
public void fastForward() {
|
||||
iTunes.invoke("FastForward");
|
||||
}
|
||||
|
||||
/**
|
||||
* Advance to the next track in the current playlist.
|
||||
*/
|
||||
public void nextTrack() {
|
||||
iTunes.invoke("NextTrack");
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause playback.
|
||||
*/
|
||||
public void pause() {
|
||||
iTunes.invoke("Pause");
|
||||
}
|
||||
|
||||
/**
|
||||
* Play the currently targeted track.
|
||||
*/
|
||||
public void play() {
|
||||
iTunes.invoke("ASDSDPlay");
|
||||
}
|
||||
|
||||
/**
|
||||
* Play the specified file path, adding it to the library if not already
|
||||
* present.
|
||||
*/
|
||||
public void playFile(String filePath) {
|
||||
iTunes.invoke("PlayFile", filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the playing/paused state of the current track.
|
||||
*/
|
||||
public void playPause() {
|
||||
iTunes.invoke("PlayPause");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return to the previous track in the current playlist.
|
||||
*/
|
||||
public void previousTrack() {
|
||||
iTunes.invoke("PreviousTrack");
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable fast forward/rewind and resume playback, if playing.
|
||||
*/
|
||||
public void resume() {
|
||||
iTunes.invoke("Resume");
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip backwards in a playing track.
|
||||
*/
|
||||
public void rewind() {
|
||||
iTunes.invoke("Rewind");
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop playback.
|
||||
*/
|
||||
public void stop() {
|
||||
iTunes.invoke("Stop");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current state of the player buttons in the window
|
||||
* containing the currently targeted track. If there is no currently
|
||||
* targeted track, returns the current state of the player buttons
|
||||
* in the main browser window.
|
||||
*/
|
||||
public void getPlayerButtonsState(boolean previousEnabled,
|
||||
String playPause, boolean nextEnabled) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this version of the iTunes type library is compatible
|
||||
* with the specified version.
|
||||
* @param majorVersion Major version of iTunes interface.
|
||||
* @param minorVersion Minor version of iTunes interface.
|
||||
* @return Returns true if this version is compatible with the indicated
|
||||
* interface version.
|
||||
*/
|
||||
public boolean getCheckVersion (int majorVersion, int minorVersion) {
|
||||
return iTunes.invoke("CheckVersion", majorVersion, minorVersion).getBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an IITObject corresponding to the specified IDs.
|
||||
* The object may be a source, playlist, or track.
|
||||
* @param sourceID The ID that identifies the source. Valid for a source,
|
||||
* playlist, or track.
|
||||
* @param playlistID The ID that identifies the playlist. Valid for a
|
||||
* playlist or track. Must be zero for a source.
|
||||
* @param trackID The ID that identifies the track within the playlist.
|
||||
* Valid for a track. Must be zero for a source or playlist.
|
||||
* @param databaseID The ID that identifies the track, independent of its
|
||||
* playlist. Valid for a track. Must be zero for a source or playlist.
|
||||
* @return Returns an IITObject object corresponding to the specified IDs.
|
||||
* Will be set to NULL if no object could be retrieved.
|
||||
*/
|
||||
public ITObject getITObjectByID(int sourceID, int playlistID, int trackID, int databaseID) {
|
||||
Dispatch object = Dispatch.call(iTunes, "GetITObjectByID", sourceID, playlistID, trackID, databaseID).toDispatch();
|
||||
return new ITObject(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new playlist in the main library.
|
||||
* @param playlistName The name of the new playlist (may be empty).
|
||||
* @return Returns an ITPlaylist object corresponding to the new playlist.
|
||||
*/
|
||||
public ITPlaylist createPlaylist(String playlistName) {
|
||||
Dispatch cplaylist = Dispatch.call(iTunes, "CreatePlaylist", playlistName).toDispatch();
|
||||
ITPlaylist playlist = new ITPlaylist(cplaylist);
|
||||
ITPlaylistKind playlistKind = playlist.getKind();
|
||||
if (playlistKind == ITPlaylistKind.ITPlaylistKindCD)
|
||||
return new ITAudioCDPlaylist(cplaylist);
|
||||
else if (playlist.getKind() == ITPlaylistKind.ITPlaylistKindLibrary)
|
||||
return new ITLibraryPlaylist(cplaylist);
|
||||
else if (playlist.getKind() == ITPlaylistKind.ITPlaylistKindUser)
|
||||
return new ITUserPlaylist(cplaylist);
|
||||
else
|
||||
return playlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the specified iTunes Store or streaming audio URL.
|
||||
* @param url The URL to open. The length of the URL cannot exceed 512
|
||||
* characters. iTunes Store URLs start with itms:// or itmss://. Streaming
|
||||
* audio URLs start with http://.
|
||||
*/
|
||||
public void openURL (String url) {
|
||||
iTunes.invoke("OpenURL", url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Go to the iTunes Store home page.
|
||||
*/
|
||||
public void gotoMusicStoreHomePage() {
|
||||
iTunes.invoke("GoToMusicStoreHomePage");
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the contents of the iPod.
|
||||
*/
|
||||
public void updateIPod() {
|
||||
iTunes.invoke("UpdateIPod");
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the iTunes application.
|
||||
*/
|
||||
public void quit() {
|
||||
iTunes.invoke("Quit");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new EQ preset.
|
||||
* The EQ preset will be created "flat", i.e. the preamp and all band levels
|
||||
* will be set to 0.
|
||||
* EQ preset names cannot start with leading spaces. If you specify a name
|
||||
* that starts with leading spaces they will be stripped out.
|
||||
* If <code>eqPresetName</code> is empty, the EQ preset will be created with
|
||||
* a default name.
|
||||
* @param eqPresetName The name of the new EQ Preset (may be empty)
|
||||
* @return Returns an ITEQPreset object corresponding to the new EQ Preset.
|
||||
*/
|
||||
public ITEQPreset createEQPreset(String eqPresetName) {
|
||||
Dispatch eqPreset = Dispatch.call(iTunes, "CreateEQPreset", eqPresetName).toDispatch();
|
||||
return new ITEQPreset(eqPreset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new playlist in an existing source.
|
||||
* You may not be able to create a playlist in every source. For example,
|
||||
* you cannot create a playlist in an audio CD source, or in an iPod source
|
||||
* if it is in auto update mode.
|
||||
* If <code>playlistName</code> is empty, the playlist will be created with
|
||||
* a default name.
|
||||
* @param playlistName The name of the new playlist (may be empty).
|
||||
* @param source The source that will contain the new playlist.
|
||||
* @return Returns an ITPlaylist object corresponding to the new playlist.
|
||||
*/
|
||||
public ITPlaylist createPlaylistInSource(String playlistName, ITSource source) {
|
||||
Dispatch cplaylist = Dispatch.call(iTunes, "CreatePlaylistInSource", playlistName, source.fetchDispatch()).toDispatch();
|
||||
ITPlaylist playlist = new ITPlaylist(cplaylist);
|
||||
ITPlaylistKind playlistKind = playlist.getKind();
|
||||
if (playlistKind == ITPlaylistKind.ITPlaylistKindCD)
|
||||
return new ITAudioCDPlaylist(cplaylist);
|
||||
else if (playlist.getKind() == ITPlaylistKind.ITPlaylistKindLibrary)
|
||||
return new ITLibraryPlaylist(cplaylist);
|
||||
else if (playlist.getKind() == ITPlaylistKind.ITPlaylistKindUser)
|
||||
return new ITUserPlaylist(cplaylist);
|
||||
else
|
||||
return playlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribes to the specified podcast feed URL. Any "unsafe" characters in
|
||||
* the URL should already be converted into their corresponding escape
|
||||
* sequences, iTunes will not do this.
|
||||
* @param url The URL to subscribe to.
|
||||
*/
|
||||
public void subscribeToPodcast(String url) {
|
||||
iTunes.invoke("SubscribeToPodcast", url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates all podcast feeds. This is equivalent to the user pressing the
|
||||
* Update button when Podcasts is selected in the Source list.
|
||||
*/
|
||||
public void updatePodcastFeeds() {
|
||||
iTunes.invoke("UpdatePodcastFeeds");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new folder in the main library.
|
||||
* If <code>folderName</code> is empty, the folder will be created with a
|
||||
* default name.
|
||||
* @param folderName The name of the new folder (may be empty).
|
||||
* @return Returns an ITPlaylist object corresponding to the new folder.
|
||||
*/
|
||||
public ITUserPlaylist createFolder(String folderName) {
|
||||
Dispatch folder = Dispatch.call(iTunes, "CreateFolder", folderName).toDispatch();
|
||||
return new ITUserPlaylist(folder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new folder in an existing source.
|
||||
* You may not be able to create a folder in every source. For example, you
|
||||
* cannot create a folder in an audio CD source, or in an iPod source if it
|
||||
* is in auto update mode.
|
||||
* If <code>folderName</code> is empty, the folder will be created with a
|
||||
* default name.
|
||||
* @param folderName The name of the new folder (may be empty)
|
||||
* @param iSource The source that will contain the new folder.
|
||||
* @return Returns an ITPlaylist object corresponding to the new folder.
|
||||
*/
|
||||
public ITUserPlaylist createFolderInSource(String folderName, ITSource iSource) {
|
||||
Dispatch folder = Dispatch.call(iTunes, "CreateFolderInSource", folderName, iSource.fetchDispatch()).toDispatch();
|
||||
return new ITUserPlaylist(folder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of music sources (music library, CD, device, etc.).
|
||||
* @return Collection of ITSource objects.
|
||||
*/
|
||||
public ITSourceCollection getSources() {
|
||||
Dispatch sources = Dispatch.call(iTunes, "Sources").toDispatch();
|
||||
return new ITSourceCollection(sources);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sound output volume (0=minimum, 100=maximum).
|
||||
* @param volume New sound output volume
|
||||
*/
|
||||
public void setSoundVolume(int volume) {
|
||||
iTunes.setProperty("SoundVolume", volume);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sound output volume (0=minimum, 100=maximum).
|
||||
* @return Current sound output volume
|
||||
*/
|
||||
public int getSoundVolume() {
|
||||
return iTunes.getPropertyAsInt("SoundVolume");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets sound output mute state.
|
||||
* @param shouldMute If true, sound output will be muted.
|
||||
*/
|
||||
public void setMute(boolean shouldMute) {
|
||||
iTunes.setProperty("Mute", shouldMute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the sound output is muted.
|
||||
* @return True if sound output is muted.
|
||||
*/
|
||||
public boolean getMute() {
|
||||
return iTunes.getPropertyAsBoolean("Mute");
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the mute state.
|
||||
*/
|
||||
public void toggleMute() {
|
||||
setMute(!getMute());
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the shuffle state.
|
||||
*/
|
||||
public void toggleShuffle() {
|
||||
getCurrentPlaylist().toggleShuffle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current player state.
|
||||
* @return Returns the current player state.
|
||||
*/
|
||||
public ITPlayerState getPlayerState() {
|
||||
return ITPlayerState.values()[Dispatch.get(iTunes, "PlayerState").getInt()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the player's position within the currently playing track in
|
||||
* seconds.
|
||||
* If playerPos specifies a position before the beginning of the track,
|
||||
* the position will be set to the beginning. If playerPos specifies a
|
||||
* position after the end of the track, the position will be set to the
|
||||
* end.
|
||||
* @param playerPos The player's position within the currently playing
|
||||
* track in seconds.
|
||||
*/
|
||||
public void setPlayerPosition(int playerPos) {
|
||||
iTunes.setProperty("playerPosition", playerPos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the player's position within the currently playing track in
|
||||
* seconds.
|
||||
* @return The player's position within the currently playing track in
|
||||
* seconds.
|
||||
*/
|
||||
public int getPlayerPosition() {
|
||||
return iTunes.getPropertyAsInt("playerPosition");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the source that represents the main library.
|
||||
* You can also find the main library source by iterating over
|
||||
* <code>iTunes.getSources()</code> and looking for an <code>ITSource</code>
|
||||
* of kind <code>ITSourceKindLibrary</code>.
|
||||
* @return Returns the source that represents the main library.
|
||||
*/
|
||||
public ITSource getLibrarySource() {
|
||||
Dispatch lsource = iTunes.getProperty("LibrarySource").toDispatch();
|
||||
return new ITSource(lsource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the main library playlist in the main library source.
|
||||
* @return An IITLibraryPlaylist object corresponding to the main library
|
||||
* playlist.
|
||||
*/
|
||||
public ITLibraryPlaylist getLibraryPlaylist() {
|
||||
Dispatch lplaylist = iTunes.getProperty("LibraryPlaylist").toDispatch();
|
||||
return new ITLibraryPlaylist(lplaylist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently targetd track.
|
||||
* @return An ITTrack object corresponding to the currently targeted track.
|
||||
* Will be set to NULL if there is no currently targeted track.
|
||||
*/
|
||||
public ITTrack getCurrentTrack() {
|
||||
Dispatch item = iTunes.getProperty("CurrentTrack").toDispatch();
|
||||
ITTrack track = new ITTrack(item);
|
||||
if (track.getKind()==ITTrackKind.ITTrackKindFile) {
|
||||
return new ITFileOrCDTrack(item);
|
||||
} else if (track.getKind()==ITTrackKind.ITTrackKindCD) {
|
||||
return new ITFileOrCDTrack(item);
|
||||
} else if (track.getKind()==ITTrackKind.ITTrackKindURL ) {
|
||||
return new ITURLTrack(item);
|
||||
} else {
|
||||
return track;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the playlist containing the currently targeted track.
|
||||
* @return An ITPlaylist object corresponding to the playlist containing the
|
||||
* currently targeted track.
|
||||
* Will be set to NULL if there is no currently targeted playlist.
|
||||
*/
|
||||
public ITPlaylist getCurrentPlaylist() {
|
||||
Dispatch cplaylist = iTunes.getProperty("CurrentPlaylist").toDispatch();
|
||||
ITPlaylist playlist = new ITPlaylist(cplaylist);
|
||||
ITPlaylistKind playlistKind = playlist.getKind();
|
||||
if (playlistKind == ITPlaylistKind.ITPlaylistKindCD)
|
||||
return new ITAudioCDPlaylist(cplaylist);
|
||||
else if (playlist.getKind() == ITPlaylistKind.ITPlaylistKindLibrary)
|
||||
return new ITLibraryPlaylist(cplaylist);
|
||||
else if (playlist.getKind() == ITPlaylistKind.ITPlaylistKindUser)
|
||||
return new ITUserPlaylist(cplaylist);
|
||||
else
|
||||
return playlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection containing the currently selected track or tracks.
|
||||
* The frontmost visible window in iTunes must be a browser or playlist
|
||||
* window. If there is no frontmost visible window (e.g. iTunes is minimized
|
||||
* to the system tray), the main browser window is used.
|
||||
* @return Collection of ITrack objects.
|
||||
* Will be set to NULL if there is no current selection.
|
||||
*/
|
||||
public ITTrackCollection getSelectedTracks() {
|
||||
Dispatch stracks = iTunes.getProperty("SelectedTracks").toDispatch();
|
||||
return new ITTrackCollection(stracks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version of the iTunes application.
|
||||
* @return
|
||||
*/
|
||||
public String getVersion() {
|
||||
return iTunes.getPropertyAsString("Version");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the high 32 bits of the persistent ID of the specified IITObject.
|
||||
* See the documentation on IITObject for more information on persistent
|
||||
* IDs.
|
||||
*
|
||||
* The object may be a source, playlist, or track.
|
||||
* @param iObject The object to fetch the High Persistent ID.
|
||||
* @return The high 32 bits of the 64-bit persistent ID.
|
||||
*/
|
||||
public long getITObjectPersistentIDHigh (ITObject iObject) {
|
||||
Dispatch object = iObject.fetchDispatch();
|
||||
return Dispatch.call(object, "GetObjectPersistentIDHigh", object).getLong();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the low 32 bits of the persistent ID of the specified IITObject.
|
||||
* See the documentation on IITObject for more information on persistent
|
||||
* IDs.
|
||||
*
|
||||
* The object may be a source, playlist, or track.
|
||||
* @param iObject The object to fetch the Low Persistent ID.
|
||||
* @return The low 32 bits of the 64-bit persistent ID.
|
||||
*/
|
||||
public long getITObjectPersistentIDLow (ITObject iObject) {
|
||||
Dispatch object = iObject.fetchDispatch();
|
||||
return Dispatch.call(object, "GetObjectPersistentIDLow", object).getLong();
|
||||
}
|
||||
|
||||
public ITObjectPersistentID getObjectPersistentIDs(ITObject iObject){
|
||||
return new ITObjectPersistentID(getITObjectPersistentIDHigh(iObject),getITObjectPersistentIDLow(iObject));
|
||||
}
|
||||
|
||||
public ITBrowserWindow getBrowserWindow(){
|
||||
Dispatch window = iTunes.getProperty("BrowserWindow").toDispatch();
|
||||
return new ITBrowserWindow(window);
|
||||
}
|
||||
|
||||
public void cycleSongRepeat() {
|
||||
getCurrentPlaylist().cycleSongRepeat();
|
||||
}
|
||||
|
||||
public ITPlaylist getPlaylist(String name) {
|
||||
ITPlaylistCollection playlistCollection = getLibrarySource().getPlaylists();
|
||||
ITPlaylist playlist = playlistCollection.ItemByName(name);
|
||||
try {
|
||||
playlist.getName();
|
||||
} catch (IllegalStateException e) {
|
||||
playlist = createPlaylist(name);
|
||||
}
|
||||
return playlist;
|
||||
}
|
||||
|
||||
public ITUserPlaylist getUserPlaylist(String name) {
|
||||
ITPlaylist playlist = getPlaylist(name);
|
||||
ITUserPlaylist userPlaylist = new ITUserPlaylist(playlist.fetchDispatch());
|
||||
return userPlaylist;
|
||||
}
|
||||
|
||||
public void playlistAddTrack(String name, ITTrack track) {
|
||||
ITUserPlaylist userPlaylist = getUserPlaylist(name);
|
||||
if (!userPlaylist.containsTrack(track)) {
|
||||
userPlaylist.addTrack(track);
|
||||
}
|
||||
}
|
||||
|
||||
public void playlistAddCurrentTrack(String name) {
|
||||
playlistAddTrack(name, getCurrentTrack());
|
||||
}
|
||||
|
||||
public void release() {
|
||||
ComThread.Release();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.dt.iTunesController;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
/**
|
||||
* This class is used to forward all iTunes COM Events to a class that
|
||||
* implements <code>iTunesEventsInterface</code>. To receive events, create
|
||||
* a class that implements the interface, and then use
|
||||
* <code>iTunes.addEventHandler()</code>.
|
||||
*
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public class iTunesEvents {
|
||||
|
||||
private iTunesEventsInterface eventHandler;
|
||||
|
||||
public iTunesEvents (iTunesEventsInterface itef) {
|
||||
eventHandler = itef;
|
||||
}
|
||||
|
||||
public void OnDatabaseChangedEvent(Variant[] args) {
|
||||
// Not currently implemented
|
||||
}
|
||||
|
||||
public void OnPlayerPlayEvent(Variant[] args) {
|
||||
ITTrack itt = new ITTrack((Dispatch)args[0].getDispatch());
|
||||
eventHandler.onPlayerPlayEvent(itt);
|
||||
}
|
||||
|
||||
public void OnPlayerStopEvent(Variant[] args) {
|
||||
ITTrack itt = new ITTrack((Dispatch)args[0].getDispatch());
|
||||
eventHandler.onPlayerStopEvent(itt);
|
||||
}
|
||||
|
||||
public void OnPlayerPlayingTrackChangedEvent(Variant[] args) {
|
||||
ITTrack itt = new ITTrack((Dispatch)args[0].getDispatch());
|
||||
eventHandler.onPlayerPlayingTrackChangedEvent(itt);
|
||||
}
|
||||
|
||||
public void OnCOMCallsDisabledEvent(Variant[] args) {
|
||||
ITCOMDisabledReason reason = ITCOMDisabledReason.values()[args[0].getInt()];
|
||||
eventHandler.onCOMCallsDisabledEvent(reason);
|
||||
}
|
||||
|
||||
public void OnCOMCallsEnabledEvent(Variant[] args) {
|
||||
eventHandler.onCOMCallsEnabledEvent();
|
||||
}
|
||||
|
||||
public void OnQuittingEvent(Variant[] args) {
|
||||
eventHandler.onQuittingEvent();
|
||||
}
|
||||
|
||||
public void OnAboutToPromptUserToQuitEvent(Variant[] args) {
|
||||
eventHandler.onAboutToPromptUserToQuitEvent();
|
||||
}
|
||||
|
||||
public void OnSoundVolumeChangedEvent(Variant[] args) {
|
||||
eventHandler.onSoundVolumeChangedEvent(args[0].getInt());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package com.dt.iTunesController;
|
||||
|
||||
/**
|
||||
* Interface for receiving iTunes events.
|
||||
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
|
||||
* @version 0.2
|
||||
*/
|
||||
public interface iTunesEventsInterface {
|
||||
|
||||
/**
|
||||
* <strong>Not currently implemented</strong>.
|
||||
*
|
||||
* The ITEventDatabaseChanged event is fired when the iTunes database is
|
||||
* changed.
|
||||
*
|
||||
* Each parameter is a two-dimensional array of integers. The first
|
||||
* dimension is the number of objects. The second dimension is always 4 and
|
||||
* specifies each of the 4 ITObject IDs, where index 0 is the source ID,
|
||||
* index 1 is the playlist ID, index 2 is the track ID, and index 3 is the
|
||||
* track database ID. For more information on object IDs, see
|
||||
* <code>ITObject</code>.
|
||||
*
|
||||
* Note that you can use <code>iTunes.getITObjectByID()</code> to retrieve
|
||||
* changed ITObject, but not for deleted objects (since they no longer
|
||||
* exist).
|
||||
*
|
||||
* @param deletedObjectIDs
|
||||
* @param changedObjectIDs
|
||||
*/
|
||||
public void onDatabaseChangedEvent(int[][] deletedObjectIDs, int[][] changedObjectIDs);
|
||||
|
||||
/**
|
||||
* The ITEventPlayerPlay event is fired when a track begins playing.
|
||||
* @param iTrack An ITTrack object corresponding to the track that has
|
||||
* started playing.
|
||||
*/
|
||||
public void onPlayerPlayEvent (ITTrack iTrack);
|
||||
|
||||
/**
|
||||
* The ITEventPlayerStop event is fired when a track stops playing.
|
||||
* @param iTrack An ITTrack object corresponding to the track that has
|
||||
* stopped playing.
|
||||
*/
|
||||
public void onPlayerStopEvent (ITTrack iTrack);
|
||||
|
||||
/**
|
||||
* The ITEventPlayerPlayingTrackChanged event is fired when information
|
||||
* about the currently playing track has changed.
|
||||
* This event is fired when the user changes information about the currently
|
||||
* playing track (e.g. the name of the track).
|
||||
* This event is also fired when iTunes plays the next joined CD track in a
|
||||
* CD playlist, since joined CD tracks are treated as a single track.
|
||||
* @param iTrack An ITTrack object corresponding to the track that is now
|
||||
* playing.
|
||||
*/
|
||||
public void onPlayerPlayingTrackChangedEvent(ITTrack iTrack);
|
||||
|
||||
/**
|
||||
* The ITEventCOMCallsDisabled event is fired when calls to the iTunes COM
|
||||
* interface will be deferred.
|
||||
* Typically, iTunes will defer COM calls when any modal dialog is being
|
||||
* displayed. When the user dismisses the last modal dialog, COM calls will
|
||||
* be enabled again, and any deferred COM calls will be executed. You can
|
||||
* use this event to avoid making a COM call which will be deferred.
|
||||
* @param reason The reason the COM interface is being disabled. This is
|
||||
* typically <code>ITCOMDisabledReasonDialog</code>.
|
||||
*/
|
||||
public void onCOMCallsDisabledEvent(ITCOMDisabledReason reason);
|
||||
|
||||
/**
|
||||
* The ITEventCOMCallsEnabled event is fired when calls to the iTunes COM
|
||||
* interface will no longer be deferred.
|
||||
* Typically, iTunes will defer COM calls when any modal dialog is being
|
||||
* displayed. When the user dismisses the last modal dialog, COM calls will
|
||||
* be enabled again, and any deferred COM calls will be executed.
|
||||
*/
|
||||
public void onCOMCallsEnabledEvent();
|
||||
|
||||
/**
|
||||
* The ITEventQuitting event is fired when iTunes is about to quit.
|
||||
* If the user attempts to quit iTunes while a client still has outstanding
|
||||
* iTunes COM objects instantiated, iTunes will display a warning dialog.
|
||||
* The user can still choose to quit iTunes anyway, in which case this event
|
||||
* will be fired. After this event is fired, any existing iTunes COM objects
|
||||
* will no longer be valid.
|
||||
* This event is only used to notify clients that iTunes is quitting,
|
||||
* clients cannot prevent this from happening.
|
||||
*/
|
||||
public void onQuittingEvent();
|
||||
|
||||
/**
|
||||
* The ITEventAboutToPromptUserToQuit event is fired when iTunes is about
|
||||
* prompt the user to quit.
|
||||
* This event gives clients the opportunity to prevent the warning dialog
|
||||
* prompt from occurring.
|
||||
* If the user attempts to quit iTunes while a client still has outstanding
|
||||
* iTunes COM objects instantiated, iTunes will display a warning dialog.
|
||||
* This event is fired just before the warning dialog is shown. iTunes will
|
||||
* then wait up to 5 seconds for clients to release any outstanding iTunes
|
||||
* COM objects. If all objects are released during this time, the warning
|
||||
* dialog will not be shown and iTunes will quit immediately.
|
||||
* Otherwise, the warning dialog will be shown. If the user chooses to quit
|
||||
* iTunes anyway, the ITEventQuitting event is fired. See
|
||||
* <code>iTunesEventsInterface.onQuittingEvent()</code> for more details.
|
||||
*/
|
||||
public void onAboutToPromptUserToQuitEvent();
|
||||
|
||||
/**
|
||||
* The ITEventSoundVolumeChanged event is fired when the sound output volume
|
||||
* has changed.
|
||||
* @param newVolume The new sound output volume (0 = minimum, 100 = maximum).
|
||||
*/
|
||||
public void onSoundVolumeChangedEvent(int newVolume);
|
||||
|
||||
}
|
||||
11
java/mimis/.classpath
Normal file
11
java/mimis/.classpath
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
<classpathentry kind="src" path="src/main/resources"/>
|
||||
<classpathentry exported="true" kind="src" path="/itunescontroller"/>
|
||||
<classpathentry exported="true" kind="src" path="/wiigee"/>
|
||||
<classpathentry exported="true" kind="src" path="/wiiusej"/>
|
||||
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry exported="true" kind="con" path="org.springsource.ide.eclipse.gradle.classpathcontainer"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
18
java/mimis/.project
Normal file
18
java/mimis/.project
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>mimis</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.springsource.ide.eclipse.gradle.core.nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
BIN
java/mimis/DelcomDLL.dll
Normal file
BIN
java/mimis/DelcomDLL.dll
Normal file
Binary file not shown.
BIN
java/mimis/WiiPair.exe
Normal file
BIN
java/mimis/WiiPair.exe
Normal file
Binary file not shown.
35
java/mimis/build.gradle
Normal file
35
java/mimis/build.gradle
Normal file
@@ -0,0 +1,35 @@
|
||||
import java.util.jar.JarEntry;
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'cpp-lib'
|
||||
|
||||
version = '0.1'
|
||||
|
||||
sourceCompatibility = 1.6
|
||||
targetCompatibility = 1.6
|
||||
|
||||
def mainClass = 'mimis.Main'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':itunescontroller')
|
||||
compile project(':wiiusej')
|
||||
compile project(':wiigee')
|
||||
|
||||
compile 'commons-collections:commons-collections:3.+'
|
||||
compile 'commons-logging:commons-logging:1.+'
|
||||
compile 'log4j:log4j:1.2.17'
|
||||
compile 'com.melloware:jintellitype:1.3.7'
|
||||
|
||||
compile fileTree(dir: 'lib', include: '*.jar')
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes 'Main-Class': mainClass
|
||||
}
|
||||
}
|
||||
61
java/mimis/build.xml
Normal file
61
java/mimis/build.xml
Normal file
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<project default="jar" name="Build file for Project Mimis">
|
||||
<!-- All -->
|
||||
<target name="all" depends="javadoc, jar, launch4j"></target>
|
||||
|
||||
<!-- Javadoc -->
|
||||
<target name="javadoc">
|
||||
<javadoc access="private" author="true" classpath="cfg;resource;lib/log4j-1.2.16.jar;lib/jxinput.jar;lib/commons-logging-1.1.1.jar;lib/jacob-1.15-M3.jar" destdir="doc" nodeprecated="false" nodeprecatedlist="false" noindex="false" nonavbar="false" notree="false" packagenames="mimis.exception.macro,mimis.device.network,wiiusej,mimis.application.itunes,mimis.exception.util,mimis.device.javainput,wiiusej.wiiusejevents,wiiusej.wiiusejevents.utils,mimis.util.swing,mimis.exception.worker,mimis.application.lirc,mimis.application.cmd.windows.winamp,wiiusej.values,mimis.exception.event,mimis.device.lirc.remote,mimis.device.panel,mimis.exception.device,mimis.exception.button,mimis.application.robot,mimis.application.lirc.ipod,mimis.exception.task.action,mimis.exception.application,wiiusej.wiiusejevents.wiiuseapievents,mimis.application.cmd.windows.gomplayer,mimis.application.mpc,org.wiigee.logic,mimis.device.lirc,mimis.sequence,mimis.manager,org.wiigee.util,mimis.event,mimis.application.cmd.windows.wmp,mimis.value,mimis.device.javainput.extreme3d,mimis.event.router,mimis.application.cmd,mimis.worker,org.wiigee.event,mimis.device.wiimote,mimis.device.wiimote.gesture.event,wiiusej.wiiusejevents.physicalevents,mimis.util.multiplexer,mimis,org.wiigee.control,mimis.exception.device.javainput,mimis.util,mimis.application.cmd.windows,com.dt.iTunesController,org.wiigee.device,mimis.application.vlc,mimis.device.wiimote.gesture,mimis.device.jintellitype,mimis.event.feedback,mimis.device,org.wiigee.filter,mimis.exception.application.windows,mimis.application,mimis.sequence.state,mimis.device.javainput.rumblepad,com.melloware.jintellitype,mimis.exception.event.router,mimis.exception.task,mimis.exception" source="1.6" sourcepath="src" splitindex="true" use="true" version="true" />
|
||||
</target>
|
||||
|
||||
<!-- Jar -->
|
||||
<target name="jar">
|
||||
<property name="jar.dir" value="." />
|
||||
<jar destfile="${jar.dir}/main.jar" filesetmanifest="mergewithoutmain">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="mimis.Main" />
|
||||
<attribute name="Class-Path" value="." />
|
||||
</manifest>
|
||||
<fileset dir="bin" />
|
||||
<fileset dir="resource" />
|
||||
<zipfileset excludes="META-INF/*.SF" src="lib/commons-logging-1.1.1.jar" />
|
||||
<zipfileset excludes="META-INF/*.SF" src="lib/log4j-1.2.16.jar" />
|
||||
<zipfileset excludes="META-INF/*.SF" src="lib/jacob-1.15-M3.jar" />
|
||||
<zipfileset excludes="META-INF/*.SF" src="lib/jxinput.jar" />
|
||||
<fileset dir="cfg" />
|
||||
</jar>
|
||||
<jar destfile="${jar.dir}/client.jar" filesetmanifest="mergewithoutmain">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="mimis.Client" />
|
||||
<attribute name="Class-Path" value="." />
|
||||
</manifest>
|
||||
<fileset dir="bin" />
|
||||
<fileset dir="resource" />
|
||||
<zipfileset excludes="META-INF/*.SF" src="lib/commons-logging-1.1.1.jar" />
|
||||
<zipfileset excludes="META-INF/*.SF" src="lib/log4j-1.2.16.jar" />
|
||||
<zipfileset excludes="META-INF/*.SF" src="lib/jacob-1.15-M3.jar" />
|
||||
<zipfileset excludes="META-INF/*.SF" src="lib/jxinput.jar" />
|
||||
<fileset dir="cfg" />
|
||||
</jar>
|
||||
<copy todir="${jar.dir}">
|
||||
<fileset dir=".">
|
||||
<include name="*.dll" />
|
||||
<include name="*.exe" />
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<!-- Launch4j -->
|
||||
<target name="launch4j" depends="jar">
|
||||
<property name="launch4j.dir" location="C:\Program Files (x86)\Launch4j" />
|
||||
<path id="launch4j">
|
||||
<pathelement location="${launch4j.dir}/launch4j.jar" />
|
||||
<pathelement location="${launch4j.dir}/lib/xstream.jar" />
|
||||
</path>
|
||||
<taskdef name="launch4j" classname="net.sf.launch4j.ant.Launch4jTask">
|
||||
<classpath refid="launch4j" />
|
||||
</taskdef>
|
||||
<launch4j configFile="launch4j.xml" />
|
||||
<delete file="launch4j.log" />
|
||||
</target>
|
||||
</project>
|
||||
BIN
java/mimis/client.jar
Normal file
BIN
java/mimis/client.jar
Normal file
Binary file not shown.
BIN
java/mimis/irtoy.exe
Normal file
BIN
java/mimis/irtoy.exe
Normal file
Binary file not shown.
BIN
java/mimis/jacob-1.15-M3-x86.dll
Normal file
BIN
java/mimis/jacob-1.15-M3-x86.dll
Normal file
Binary file not shown.
BIN
java/mimis/jintellitype.dll
Normal file
BIN
java/mimis/jintellitype.dll
Normal file
Binary file not shown.
BIN
java/mimis/jxinput.dll
Normal file
BIN
java/mimis/jxinput.dll
Normal file
Binary file not shown.
22
java/mimis/launch4j.xml
Normal file
22
java/mimis/launch4j.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<launch4jConfig>
|
||||
<dontWrapJar>false</dontWrapJar>
|
||||
<headerType>gui</headerType>
|
||||
<jar>main.jar</jar>
|
||||
<outfile>mimis.exe</outfile>
|
||||
<errTitle>Mimis</errTitle>
|
||||
<cmdLine></cmdLine>
|
||||
<chdir></chdir>
|
||||
<priority>normal</priority>
|
||||
<downloadUrl>http://java.com/download</downloadUrl>
|
||||
<supportUrl></supportUrl>
|
||||
<customProcName>true</customProcName>
|
||||
<stayAlive>false</stayAlive>
|
||||
<manifest></manifest>
|
||||
<icon>resource\M.ico</icon>
|
||||
<jre>
|
||||
<path></path>
|
||||
<minVersion>1.6.0</minVersion>
|
||||
<maxVersion></maxVersion>
|
||||
<jdkPreference>preferJre</jdkPreference>
|
||||
</jre>
|
||||
</launch4jConfig>
|
||||
BIN
java/mimis/lib/jxinput.jar
Normal file
BIN
java/mimis/lib/jxinput.jar
Normal file
Binary file not shown.
BIN
java/mimis/main.jar
Normal file
BIN
java/mimis/main.jar
Normal file
Binary file not shown.
BIN
java/mimis/mimis.dll
Normal file
BIN
java/mimis/mimis.dll
Normal file
Binary file not shown.
BIN
java/mimis/mimis.exe
Normal file
BIN
java/mimis/mimis.exe
Normal file
Binary file not shown.
25
java/mimis/src/main/java/mimis/Client.java
Normal file
25
java/mimis/src/main/java/mimis/Client.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package mimis;
|
||||
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.router.GlobalRouter;
|
||||
import mimis.util.swing.Dialog;
|
||||
|
||||
public class Client extends Main {
|
||||
public static final String IP = "127.0.0.1";
|
||||
public static final int PORT = 6789;
|
||||
|
||||
public Client(String ip, int port) {
|
||||
super();
|
||||
router = new GlobalRouter(ip, port);
|
||||
}
|
||||
|
||||
public void activate() throws ActivateException {
|
||||
super.activate();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String ip = Dialog.question("Server IP:", IP);
|
||||
int port = Integer.valueOf(Dialog.question("Server Port:", PORT));
|
||||
new Client(ip, port).start();
|
||||
}
|
||||
}
|
||||
98
java/mimis/src/main/java/mimis/Gui.java
Normal file
98
java/mimis/src/main/java/mimis/Gui.java
Normal file
@@ -0,0 +1,98 @@
|
||||
package mimis;
|
||||
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.TextArea;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.input.Feedback;
|
||||
import mimis.input.Input;
|
||||
import mimis.manager.ButtonManager;
|
||||
import mimis.util.Swing;
|
||||
import mimis.worker.Component;
|
||||
|
||||
public class Gui extends Component {
|
||||
public static final String ICON = "M.png";
|
||||
public static final String TITLE = "MIMIS Manager";
|
||||
|
||||
protected JFrame frame;
|
||||
protected Component component;
|
||||
protected TextArea textArea;
|
||||
|
||||
public Gui(final Component component, ButtonManager... buttonManagerArray) {
|
||||
frame = new JFrame(TITLE) {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
protected void processWindowEvent(WindowEvent event) {
|
||||
if (event.getID() == WindowEvent.WINDOW_CLOSING) {
|
||||
log.debug("Window closing");
|
||||
component.exit();
|
||||
}
|
||||
}
|
||||
};
|
||||
this.component = component;
|
||||
frame.setIconImage(Swing.getImage(ICON));
|
||||
createFrame(buttonManagerArray);
|
||||
}
|
||||
|
||||
protected void activate() throws ActivateException {
|
||||
listen(Feedback.class);
|
||||
super.activate();
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
super.exit();
|
||||
frame.dispose();
|
||||
}
|
||||
|
||||
protected void createFrame(ButtonManager... buttonManagerArray) {
|
||||
frame.setLayout(new GridLayout(0, 1));
|
||||
JPanel controlPanel = createControlPanel(buttonManagerArray);
|
||||
frame.add(controlPanel);
|
||||
JPanel feedbackPanel = createTextPanel();
|
||||
frame.add(feedbackPanel);
|
||||
frame.setResizable(false);
|
||||
frame.setVisible(true);
|
||||
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||
frame.pack();
|
||||
}
|
||||
|
||||
protected JPanel createControlPanel(ButtonManager... buttonManagerArray) {
|
||||
JPanel controlPanel = new JPanel(new GridLayout(1, 0));
|
||||
for (ButtonManager buttonManager : buttonManagerArray) {
|
||||
if (buttonManager.count() > 0) {
|
||||
controlPanel.add(buttonManager.createPanel());
|
||||
}
|
||||
}
|
||||
return controlPanel;
|
||||
}
|
||||
|
||||
protected JPanel createTextPanel() {
|
||||
JPanel textPanel = new JPanel();
|
||||
textArea = new TextArea();
|
||||
textArea.setEditable(false);
|
||||
textPanel.add(textArea);
|
||||
return textPanel;
|
||||
}
|
||||
|
||||
public void input(Input input) {
|
||||
if (input instanceof Feedback) {
|
||||
writeLine(((Feedback) input).getText());
|
||||
}
|
||||
}
|
||||
|
||||
public void write(String string) {
|
||||
textArea.append(string);
|
||||
}
|
||||
|
||||
public void writeLine(String string) {
|
||||
write(string + "\n");
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
textArea.setText(null);
|
||||
}
|
||||
}
|
||||
102
java/mimis/src/main/java/mimis/Main.java
Normal file
102
java/mimis/src/main/java/mimis/Main.java
Normal file
@@ -0,0 +1,102 @@
|
||||
package mimis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.input.Task;
|
||||
import mimis.manager.ButtonManager;
|
||||
import mimis.manager.CurrentButtonManager;
|
||||
import mimis.value.Action;
|
||||
import mimis.worker.Component;
|
||||
|
||||
public class Main extends Mimis {
|
||||
protected CurrentButtonManager applicationManager;
|
||||
protected ButtonManager deviceManager;
|
||||
protected Gui gui;
|
||||
|
||||
static {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (Exception e) {}
|
||||
|
||||
}
|
||||
|
||||
public static Component[] getApplications() {
|
||||
return getComponents(mimis.application.Application.class);
|
||||
}
|
||||
|
||||
public static Component[] getDevices() {
|
||||
return getComponents(mimis.device.Device.class);
|
||||
}
|
||||
|
||||
public static Component[] getComponents(Class<?> clazz) {
|
||||
ArrayList<Component> componentList = new ArrayList<Component>();
|
||||
for (Object object : ServiceLoader.load(clazz)) {
|
||||
if (object instanceof Component) {
|
||||
componentList.add((Component) object);
|
||||
}
|
||||
}
|
||||
return componentList.toArray(new Component[]{});
|
||||
}
|
||||
|
||||
public Main() {
|
||||
super(getApplications());
|
||||
|
||||
/* Create gui from application and device managers */
|
||||
applicationManager = new CurrentButtonManager(router, componentCycle, "Applications", currentArray);
|
||||
deviceManager = new ButtonManager("Devices", initialize(false, getDevices()));
|
||||
gui = new Gui(this, applicationManager, deviceManager);
|
||||
manager.add(initialize(false, gui));
|
||||
}
|
||||
|
||||
public void activate() throws ActivateException {
|
||||
super.activate();
|
||||
listen(Task.class);
|
||||
|
||||
/* Start managers */
|
||||
applicationManager.start();
|
||||
deviceManager.start();
|
||||
|
||||
/* Force display of current component when gui started */
|
||||
gui.start();
|
||||
while (!gui.active());
|
||||
end(Action.CURRENT);
|
||||
}
|
||||
|
||||
protected void deactivate() throws DeactivateException {
|
||||
super.deactivate();
|
||||
|
||||
log.debug("Stop managers");
|
||||
applicationManager.stop();
|
||||
deviceManager.stop();
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
super.exit();
|
||||
|
||||
log.debug("Exit managers");
|
||||
applicationManager.exit();
|
||||
deviceManager.exit();
|
||||
}
|
||||
|
||||
public void end(Action action) {
|
||||
super.end(action);
|
||||
switch (action) {
|
||||
case CURRENT:
|
||||
case NEXT:
|
||||
case PREVIOUS:
|
||||
applicationManager.currentChanged();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Main().start(false);
|
||||
}
|
||||
}
|
||||
81
java/mimis/src/main/java/mimis/Mimis.java
Normal file
81
java/mimis/src/main/java/mimis/Mimis.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package mimis;
|
||||
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.input.Feedback;
|
||||
import mimis.input.Task;
|
||||
import mimis.manager.Manager;
|
||||
import mimis.parser.Parser;
|
||||
import mimis.router.Router;
|
||||
import mimis.util.ArrayCycle;
|
||||
import mimis.value.Action;
|
||||
import mimis.value.Target;
|
||||
import mimis.worker.Component;
|
||||
|
||||
public abstract class Mimis extends Component {
|
||||
protected Component[] currentArray;
|
||||
protected Manager manager;
|
||||
|
||||
protected ArrayCycle<Component> componentCycle;
|
||||
|
||||
public Mimis(Component... currentArray) {
|
||||
this.currentArray = initialize(false, currentArray);
|
||||
componentCycle = new ArrayCycle<Component>(currentArray);
|
||||
router = new Router();
|
||||
manager = new Manager(initialize(true, router, new Parser()));
|
||||
}
|
||||
|
||||
public void activate() throws ActivateException {
|
||||
manager.start();
|
||||
super.activate();
|
||||
}
|
||||
|
||||
protected void deactivate() throws DeactivateException {
|
||||
super.deactivate();
|
||||
manager.stop();
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
super.exit();
|
||||
manager.exit();
|
||||
}
|
||||
|
||||
public Component[] initialize(boolean start, Component... componentArray) {
|
||||
for (Component component : componentArray) {
|
||||
component.setRouter(router);
|
||||
if (start) {
|
||||
component.start();
|
||||
}
|
||||
}
|
||||
return componentArray;
|
||||
}
|
||||
|
||||
public void task(Task task) {
|
||||
if (task.getTarget().equals(Target.CURRENT)) {
|
||||
componentCycle.current().add(task);
|
||||
} else {
|
||||
super.task(task);
|
||||
}
|
||||
}
|
||||
|
||||
public void end(Action action) {
|
||||
switch (action) {
|
||||
case CURRENT:
|
||||
route(new Feedback("Current component: " + componentCycle.current().getTitle()));
|
||||
break;
|
||||
case NEXT:
|
||||
log.debug("Next component");
|
||||
route(new Feedback("Next component: " + componentCycle.next().getTitle()));
|
||||
break;
|
||||
case PREVIOUS:
|
||||
log.debug("Previous component");
|
||||
route(new Feedback("Previous component: " + componentCycle.previous().getTitle()));
|
||||
break;
|
||||
case EXIT:
|
||||
exit();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package mimis.application;
|
||||
|
||||
|
||||
public interface Application {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package mimis.application.cmd;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import mimis.application.Application;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.util.Native;
|
||||
import mimis.value.Registry;
|
||||
import mimis.worker.Component;
|
||||
|
||||
public abstract class CMDApplication extends Component implements Application {
|
||||
protected final static Registry REGISTRY = Registry.LOCAL_MACHINE;
|
||||
protected final static String KEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths";
|
||||
|
||||
protected String program;
|
||||
protected String title;
|
||||
protected Process process;
|
||||
protected boolean detect, running;
|
||||
|
||||
public CMDApplication(String program, String title) {
|
||||
super(title);
|
||||
this.program = program;
|
||||
this.title = title;
|
||||
detect = true;
|
||||
}
|
||||
|
||||
protected void activate() throws ActivateException {
|
||||
detect = true;
|
||||
if (!running) {
|
||||
String path = getPath();
|
||||
if (path == null) {
|
||||
throw new ActivateException();
|
||||
}
|
||||
try {
|
||||
String command = path.startsWith("\"") ? path : String.format("\"%s\"", path);
|
||||
command = replaceVariables(command);
|
||||
process = Runtime.getRuntime().exec(command);
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
throw new ActivateException();
|
||||
}
|
||||
}
|
||||
super.activate();
|
||||
}
|
||||
|
||||
public boolean active() {
|
||||
if (detect) {
|
||||
running = Native.isRunning(program);
|
||||
if (!active && running) {
|
||||
active = true;
|
||||
start();
|
||||
}
|
||||
}
|
||||
return active;
|
||||
}
|
||||
|
||||
protected synchronized void deactivate() throws DeactivateException {
|
||||
detect = false;
|
||||
super.deactivate();
|
||||
if (process != null) {
|
||||
process.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
String key = String.format("%s\\%s", KEY, program);
|
||||
System.out.println(Native.getValue(REGISTRY, key));
|
||||
return Native.getValue(REGISTRY, key);
|
||||
}
|
||||
|
||||
public static String replaceVariables(String string) {
|
||||
Map<String, String> env = System.getenv();
|
||||
for (String key : env.keySet()) {
|
||||
string = string.replace(String.format("%%%s%%", key), env.get(key));
|
||||
}
|
||||
return string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package mimis.application.cmd.windows;
|
||||
|
||||
import mimis.application.cmd.CMDApplication;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.util.Native;
|
||||
import mimis.value.Command;
|
||||
import mimis.value.Key;
|
||||
import mimis.value.Type;
|
||||
import mimis.value.Windows;
|
||||
|
||||
public abstract class WindowsApplication extends CMDApplication {
|
||||
protected final static int TERMINATE_SLEEP = 500;
|
||||
protected final static int START_SLEEP = 500;
|
||||
|
||||
protected String window;
|
||||
protected int handle;
|
||||
|
||||
public WindowsApplication(String title, String window) {
|
||||
this(null, title, window);
|
||||
}
|
||||
|
||||
public WindowsApplication(String program, String title, String window) {
|
||||
super(program, title);
|
||||
this.window = window;
|
||||
handle = 0;
|
||||
}
|
||||
|
||||
protected void activate() throws ActivateException {
|
||||
if (program != null) {
|
||||
super.activate();
|
||||
}
|
||||
handle = Native.getHandle(window);
|
||||
if (handle < 1) {
|
||||
sleep(START_SLEEP);
|
||||
handle = Native.getHandle(window);
|
||||
}
|
||||
active = handle > 0;
|
||||
if (!active) {
|
||||
throw new ActivateException();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean active() {
|
||||
if (!active || program == null) {
|
||||
handle = Native.getHandle(window);
|
||||
if (handle > 0 && program == null) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
return program == null ? handle > 0 : super.active();
|
||||
}
|
||||
|
||||
protected void deactivate() throws DeactivateException {
|
||||
if (process == null) {
|
||||
active = false;
|
||||
} else {
|
||||
super.deactivate();
|
||||
}
|
||||
close();
|
||||
}
|
||||
|
||||
protected void close() {
|
||||
Native.sendMessage(handle, Windows.WM_CLOSE, 0, 0);
|
||||
}
|
||||
|
||||
protected void command(Command command) {
|
||||
Native.sendMessage(handle, Windows.WM_APPCOMMAND, handle, command.getCode() << 16);
|
||||
}
|
||||
|
||||
protected void command(int command) {
|
||||
Native.sendMessage(handle, Windows.WM_COMMAND, command, 0);
|
||||
}
|
||||
|
||||
protected int user(int wParam, int lParam) {
|
||||
return Native.sendMessage(handle, Windows.WM_USER, wParam, lParam);
|
||||
}
|
||||
|
||||
protected void system(Command.System system) {
|
||||
system(system, 0);
|
||||
}
|
||||
|
||||
protected void system(Command.System system, int lParam) {
|
||||
Native.sendMessage(handle, Windows.WM_SYSCOMMAND, system.getCode(), lParam);
|
||||
}
|
||||
|
||||
protected void key(Type type, int code) {
|
||||
int scanCode = Native.mapVirtualKey(code, Windows.MAPVK_VK_TO_VSC);
|
||||
Native.postMessage(handle, type.getCode(), code, 1 | (scanCode << 16) | 1 << 30);
|
||||
sleep(200);
|
||||
}
|
||||
|
||||
protected void key(Type type, char character) {
|
||||
key(type, (int) Character.toUpperCase(character));
|
||||
}
|
||||
|
||||
protected void key(Type key, Key virtualKey) {
|
||||
key(key, virtualKey.getCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package mimis.application.cmd.windows.gomplayer;
|
||||
|
||||
import mimis.application.cmd.windows.WindowsApplication;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.value.Action;
|
||||
import mimis.value.Amount;
|
||||
import mimis.worker.Worker;
|
||||
|
||||
public class GomPlayerApplication extends WindowsApplication {
|
||||
protected final static String PROGRAM = "GOM.exe";
|
||||
protected final static String TITLE = "GOM Player";
|
||||
protected final static String WINDOW = "GomPlayer1.x";
|
||||
|
||||
protected static final int VOLUME_SLEEP = 100;
|
||||
protected static final int SEEK_SLEEP = 100;
|
||||
|
||||
protected VolumeWorker volumeWorker;
|
||||
protected SeekWorker seekWorker;
|
||||
|
||||
public GomPlayerApplication() {
|
||||
super(PROGRAM, TITLE, WINDOW);
|
||||
volumeWorker = new VolumeWorker();
|
||||
seekWorker = new SeekWorker();
|
||||
}
|
||||
|
||||
protected void deactivate() throws DeactivateException {
|
||||
super.deactivate();
|
||||
volumeWorker.stop();
|
||||
seekWorker.stop();
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
super.exit();
|
||||
volumeWorker.exit();
|
||||
seekWorker.exit();
|
||||
}
|
||||
|
||||
public void begin(Action action) {
|
||||
log.trace("GomPlayerApplication begin: " + action);
|
||||
switch (action) {
|
||||
case VOLUME_UP:
|
||||
volumeWorker.start();
|
||||
break;
|
||||
case VOLUME_DOWN:
|
||||
volumeWorker.start();
|
||||
break;
|
||||
case FORWARD:
|
||||
seekWorker.start(Amount.SMALL, 1);
|
||||
break;
|
||||
case REWIND:
|
||||
seekWorker.start(Amount.SMALL, -1);
|
||||
break;
|
||||
case NEXT:
|
||||
seekWorker.start(Amount.MEDIUM, 1);
|
||||
break;
|
||||
case PREVIOUS:
|
||||
seekWorker.start(Amount.MEDIUM, -1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void end(Action action) {
|
||||
log.trace("GomPlayerApplication end: " + action);
|
||||
switch (action) {
|
||||
case PLAY:
|
||||
command(0x800C);
|
||||
break;
|
||||
case MUTE:
|
||||
command(0x8016);
|
||||
break;
|
||||
case FORWARD:
|
||||
case REWIND:
|
||||
case NEXT:
|
||||
case PREVIOUS:
|
||||
seekWorker.stop();
|
||||
break;
|
||||
case VOLUME_UP:
|
||||
case VOLUME_DOWN:
|
||||
volumeWorker.stop();
|
||||
break;
|
||||
case FULLSCREEN:
|
||||
command(0x8154);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected class VolumeWorker extends Worker {
|
||||
protected int volumeChangeSign;
|
||||
|
||||
public void start(int volumeChangeSign) throws ActivateException {
|
||||
super.start();
|
||||
this.volumeChangeSign = volumeChangeSign;
|
||||
}
|
||||
|
||||
public void work() {
|
||||
command(volumeChangeSign > 0 ? 0x8014 : 0x8013);
|
||||
sleep(VOLUME_SLEEP);
|
||||
}
|
||||
};
|
||||
|
||||
protected class SeekWorker extends Worker {
|
||||
protected Amount amount;
|
||||
protected int seekDirection;
|
||||
|
||||
public void start(Amount amount, int seekDirection) {
|
||||
super.start();
|
||||
this.amount = amount;
|
||||
this.seekDirection = seekDirection;
|
||||
}
|
||||
|
||||
public void work() {
|
||||
switch (amount) {
|
||||
case SMALL:
|
||||
command(seekDirection > 0 ? 0x8009 : 0x8008);
|
||||
break;
|
||||
case MEDIUM:
|
||||
command(seekDirection > 0 ? 0x800B : 0x800A);
|
||||
break;
|
||||
case LARGE:
|
||||
command(seekDirection > 0 ? 0x8012 : 0x8011);
|
||||
break;
|
||||
}
|
||||
sleep(SEEK_SLEEP);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package mimis.application.cmd.windows.photoviewer;
|
||||
|
||||
import mimis.application.cmd.windows.WindowsApplication;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.value.Action;
|
||||
import mimis.value.Key;
|
||||
import mimis.value.Type;
|
||||
import mimis.worker.Worker;
|
||||
|
||||
public class PhotoViewerApplication extends WindowsApplication {
|
||||
protected final static String TITLE = "Photo Viewer";
|
||||
protected final static String WINDOW = "Photo_Lightweight_Viewer";
|
||||
|
||||
protected static final int ZOOM_SLEEP = 100;
|
||||
protected static final int DELETE_SLEEP = 2000;
|
||||
|
||||
protected ZoomWorker zoomWorker;
|
||||
protected boolean fullscreen;
|
||||
|
||||
public PhotoViewerApplication() {
|
||||
super(TITLE, WINDOW);
|
||||
zoomWorker = new ZoomWorker();
|
||||
fullscreen = false;
|
||||
}
|
||||
|
||||
protected void deactivate() throws DeactivateException {
|
||||
super.deactivate();
|
||||
zoomWorker.stop();
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
super.exit();
|
||||
zoomWorker.exit();
|
||||
}
|
||||
|
||||
public void begin(Action action) {
|
||||
switch (action) {
|
||||
case VOLUME_UP:
|
||||
zoomWorker.start(1);
|
||||
break;
|
||||
case VOLUME_DOWN:
|
||||
zoomWorker.start(-1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void end(Action action) {
|
||||
log.trace("PhotoViewerApplication end: " + action);
|
||||
switch (action) {
|
||||
case VOLUME_UP:
|
||||
case VOLUME_DOWN:
|
||||
zoomWorker.stop();
|
||||
break;
|
||||
case NEXT:
|
||||
key(Type.DOWN, Key.RIGHT);
|
||||
break;
|
||||
case PREVIOUS:
|
||||
key(Type.DOWN, Key.LEFT);
|
||||
break;
|
||||
case FORWARD:
|
||||
key(Type.DOWN, Key.CONTROL);
|
||||
//key(Type.DOWN, '.');
|
||||
//key(Type.DOWN, Key.DECIMAL);
|
||||
key(Type.DOWN, Key.OEM_PERIOD);
|
||||
//key(Type.UP, Key.OEM_PERIOD);
|
||||
//key(Type.UP, Key.CONTROL);
|
||||
break;
|
||||
case MUTE:
|
||||
key(Type.DOWN, Key.CONTROL);
|
||||
key(Type.DOWN, Key.NUMPAD0);
|
||||
//press(Key.CONTROL);
|
||||
//press(Key.NUMPAD0);
|
||||
//release(Key.CONTROL);
|
||||
break;
|
||||
case FULLSCREEN:
|
||||
key(Type.DOWN, fullscreen ? Key.ESCAPE : Key.F11);
|
||||
fullscreen = !fullscreen;
|
||||
break;
|
||||
case DISLIKE:
|
||||
/*boolean restore = false;
|
||||
if (fullscreen) {
|
||||
end(Action.FULLSCREEN);
|
||||
sleep(DELETE_SLEEP);
|
||||
restore = true;
|
||||
}
|
||||
key(Type.DOWN, Key.F16);
|
||||
key(Type.DOWN, 'Y');
|
||||
if (restore) {
|
||||
sleep(DELETE_SLEEP);
|
||||
end(Action.FULLSCREEN);
|
||||
}*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected class ZoomWorker extends Worker {
|
||||
protected int zoomDirection;
|
||||
|
||||
public void start(int zoomDirection) {
|
||||
super.start();
|
||||
this.zoomDirection = zoomDirection;
|
||||
}
|
||||
|
||||
public void work() {
|
||||
Key key = zoomDirection > 0 ? Key.ADD : Key.SUBTRACT;
|
||||
key(Type.DOWN, key);
|
||||
sleep(ZOOM_SLEEP);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package mimis.application.cmd.windows.winamp;
|
||||
|
||||
import mimis.application.cmd.windows.WindowsApplication;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.value.Action;
|
||||
import mimis.value.Command;
|
||||
import mimis.worker.Worker;
|
||||
|
||||
public class WinampApplication extends WindowsApplication {
|
||||
protected final static String PROGRAM = "winamp.exe";
|
||||
protected final static String TITLE = "Winamp";
|
||||
protected final static String WINDOW = "Winamp v1.x";
|
||||
|
||||
protected final static int STATUS_PLAYING = 1;
|
||||
protected final static int STATUS_PAUSED = 3;
|
||||
protected final static int STATUS_STOPPED = 0;
|
||||
|
||||
protected final static int IPC_ISPLAYING = 104;
|
||||
protected final static int IPC_GETOUTPUTTIME = 105;
|
||||
protected final static int IPC_SETVOLUME = 122;
|
||||
|
||||
protected final static int WINAMP_FILE_QUIT = 40001;
|
||||
protected final static int WINAMP_FILE_REPEAT = 40022;
|
||||
protected final static int WINAMP_FILE_SHUFFLE = 40023;
|
||||
protected final static int WINAMP_BUTTON1 = 40044;
|
||||
protected final static int WINAMP_BUTTON2 = 40045;
|
||||
protected final static int WINAMP_BUTTON3 = 40046;
|
||||
protected final static int WINAMP_BUTTON5 = 40048;
|
||||
protected final static int WINAMP_VOLUMEUP = 40058;
|
||||
protected final static int WINAMP_VOLUMEDOWN = 40059;
|
||||
protected final static int WINAMP_FFWD5S = 40060;
|
||||
protected final static int WINAMP_REW5S = 40061;
|
||||
protected final static int WINAMP_BUTTON4_SHIFT = 40147;
|
||||
protected final static int WINAMP_VISPLUGIN = 40192;
|
||||
|
||||
protected static final int VOLUME_SLEEP = 50;
|
||||
protected static final int SEEK_SLEEP = 100;
|
||||
|
||||
protected VolumeWorker volumeWorker;
|
||||
protected SeekWorker seekWorker;
|
||||
protected double volume;
|
||||
protected boolean muted;
|
||||
|
||||
public WinampApplication() {
|
||||
super(PROGRAM, TITLE, WINDOW);
|
||||
volume = getVolume();
|
||||
muted = volume == 0;
|
||||
volumeWorker = new VolumeWorker();
|
||||
seekWorker = new SeekWorker();
|
||||
}
|
||||
|
||||
public void deactivate() throws DeactivateException {
|
||||
super.deactivate();
|
||||
volumeWorker.stop();
|
||||
seekWorker.stop();
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
super.exit();
|
||||
volumeWorker.exit();
|
||||
seekWorker.exit();
|
||||
}
|
||||
|
||||
public void begin(Action action) {
|
||||
log.trace("WinampApplication begin: " + action);
|
||||
switch (action) {
|
||||
case VOLUME_UP:
|
||||
volumeWorker.start(1);
|
||||
break;
|
||||
case VOLUME_DOWN:
|
||||
volumeWorker.start(-1);
|
||||
break;
|
||||
case FORWARD:
|
||||
seekWorker.start(1);
|
||||
break;
|
||||
case REWIND:
|
||||
seekWorker.start(-1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void end(Action action) {
|
||||
log.trace("WinampApplication end: " + action);
|
||||
switch (action) {
|
||||
case PLAY:
|
||||
log.debug("play");
|
||||
switch (user(0, IPC_ISPLAYING)) {
|
||||
case STATUS_STOPPED:
|
||||
command(WINAMP_BUTTON2);
|
||||
break;
|
||||
default:
|
||||
command(WINAMP_BUTTON3);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case NEXT:
|
||||
command(WINAMP_BUTTON5);
|
||||
break;
|
||||
case PREVIOUS:
|
||||
command(WINAMP_BUTTON1);
|
||||
break;
|
||||
case FORWARD:
|
||||
case REWIND:
|
||||
seekWorker.stop();
|
||||
break;
|
||||
case MUTE:
|
||||
if (muted) {
|
||||
setVolume(volume);
|
||||
} else {
|
||||
volume = getVolume();
|
||||
setVolume(0);
|
||||
}
|
||||
muted = !muted;
|
||||
break;
|
||||
case VOLUME_UP:
|
||||
case VOLUME_DOWN:
|
||||
volumeWorker.stop();
|
||||
break;
|
||||
case SHUFFLE:
|
||||
command(WINAMP_FILE_SHUFFLE);
|
||||
break;
|
||||
case REPEAT:
|
||||
command(WINAMP_FILE_REPEAT);
|
||||
break;
|
||||
case FADEOUT:
|
||||
command(WINAMP_BUTTON4_SHIFT);
|
||||
break;
|
||||
case QUIT:
|
||||
command(WINAMP_FILE_QUIT);
|
||||
break;
|
||||
case VISUALISER:
|
||||
system(Command.System.MAXIMIZE);
|
||||
command(WINAMP_VISPLUGIN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public double getVolume() {
|
||||
return user(-666, IPC_SETVOLUME) / 255f;
|
||||
}
|
||||
|
||||
public void setVolume(double volume) {
|
||||
user((int) Math.ceil(volume * 255), IPC_SETVOLUME);
|
||||
}
|
||||
|
||||
public int getDuration() {
|
||||
return user(1, IPC_GETOUTPUTTIME);
|
||||
}
|
||||
|
||||
public int getElapsed() {
|
||||
return user(0, IPC_GETOUTPUTTIME) / 1000;
|
||||
}
|
||||
|
||||
protected class VolumeWorker extends Worker {
|
||||
protected int volumeChangeSign;
|
||||
|
||||
public void start(int volumeChangeSign) {
|
||||
super.start();
|
||||
this.volumeChangeSign = volumeChangeSign;
|
||||
}
|
||||
|
||||
public void work() {
|
||||
command(volumeChangeSign > 0 ? WINAMP_VOLUMEUP : WINAMP_VOLUMEDOWN);
|
||||
sleep(VOLUME_SLEEP);
|
||||
}
|
||||
};
|
||||
|
||||
protected class SeekWorker extends Worker {
|
||||
protected int seekDirection;
|
||||
|
||||
public void start(int seekDirection) {
|
||||
super.start();
|
||||
this.seekDirection = seekDirection;
|
||||
}
|
||||
|
||||
public void work() {
|
||||
command(seekDirection > 0 ? WINAMP_FFWD5S : WINAMP_REW5S);
|
||||
sleep(SEEK_SLEEP);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package mimis.application.cmd.windows.wmp;
|
||||
|
||||
import mimis.application.cmd.windows.WindowsApplication;
|
||||
import mimis.value.Action;
|
||||
import mimis.worker.Worker;
|
||||
|
||||
public class WMPApplication extends WindowsApplication {
|
||||
protected final static String PROGRAM = "wmplayer.exe";
|
||||
protected final static String TITLE = "Windows Media Player";
|
||||
protected final static String WINDOW = "WMPlayerApp";
|
||||
|
||||
protected static final int VOLUME_SLEEP = 120;
|
||||
|
||||
protected VolumeWorker volumeWorker;
|
||||
|
||||
public WMPApplication() {
|
||||
super(PROGRAM, TITLE, WINDOW);
|
||||
volumeWorker = new VolumeWorker();
|
||||
}
|
||||
|
||||
public void begin(Action action) {
|
||||
log.trace("WMPApplication begin: " + action);
|
||||
switch (action) {
|
||||
case PLAY:
|
||||
command(18808);
|
||||
break;
|
||||
case NEXT:
|
||||
command(18811);
|
||||
break;
|
||||
case PREVIOUS:
|
||||
command(18810);
|
||||
break;
|
||||
case FORWARD:
|
||||
command(18813);
|
||||
break;
|
||||
case REWIND:
|
||||
command(18812);
|
||||
break;
|
||||
case MUTE:
|
||||
command(18817);
|
||||
break;
|
||||
case VOLUME_UP:
|
||||
volumeWorker.start(1);
|
||||
break;
|
||||
case VOLUME_DOWN:
|
||||
volumeWorker.start(-1);
|
||||
break;
|
||||
case SHUFFLE:
|
||||
command(18842);
|
||||
break;
|
||||
case REPEAT:
|
||||
command(18843);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void end(Action action) {
|
||||
log.trace("WMPApplication end: " + action);
|
||||
switch (action) {
|
||||
case FORWARD:
|
||||
command(18813);
|
||||
break;
|
||||
case REWIND:
|
||||
command(18812);
|
||||
break;
|
||||
case VOLUME_UP:
|
||||
case VOLUME_DOWN:
|
||||
volumeWorker.stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected class VolumeWorker extends Worker {
|
||||
protected int volumeChangeSign;
|
||||
|
||||
public void start(int volumeChangeSign) {
|
||||
super.start();
|
||||
this.volumeChangeSign = volumeChangeSign;
|
||||
}
|
||||
|
||||
public void work() {
|
||||
command (volumeChangeSign > 0 ? 18815 : 18816);
|
||||
sleep(VOLUME_SLEEP);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
package mimis.application.itunes;
|
||||
|
||||
import mimis.application.Application;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.value.Action;
|
||||
import mimis.worker.Component;
|
||||
import mimis.worker.Worker;
|
||||
|
||||
import com.dt.iTunesController.ITCOMDisabledReason;
|
||||
import com.dt.iTunesController.ITTrack;
|
||||
import com.dt.iTunesController.iTunes;
|
||||
import com.dt.iTunesController.iTunesEventsInterface;
|
||||
|
||||
public class iTunesApplication extends Component implements Application, iTunesEventsInterface {
|
||||
protected static final String TITLE = "iTunes";
|
||||
protected static final boolean EVENTS = false;
|
||||
|
||||
protected static final int VOLUME_CHANGE_RATE = 5;
|
||||
protected static final int VOLUME_SLEEP = 100;
|
||||
protected static final String PLAYLIST_LIKE = "Like";
|
||||
protected static final String PLAYLIST_DISLIKE = "Dislike";
|
||||
|
||||
protected iTunes iTunes;
|
||||
protected VolumeWorker volumeWorker;
|
||||
protected boolean events;
|
||||
|
||||
public iTunesApplication() {
|
||||
this(EVENTS);
|
||||
}
|
||||
|
||||
public iTunesApplication(boolean events) {
|
||||
super(TITLE);
|
||||
this.events = events;
|
||||
volumeWorker = new VolumeWorker();
|
||||
}
|
||||
|
||||
protected synchronized void activate() throws ActivateException {
|
||||
iTunes = new iTunes();
|
||||
iTunes.connect();
|
||||
if (events) {
|
||||
iTunes.addEventHandler(this);
|
||||
}
|
||||
super.activate();
|
||||
}
|
||||
|
||||
public synchronized boolean active() {
|
||||
try {
|
||||
iTunes.getMute();
|
||||
active = true;
|
||||
} catch (Exception e) {
|
||||
active = false;
|
||||
}
|
||||
return active;
|
||||
}
|
||||
|
||||
protected synchronized void deactivate() throws DeactivateException {
|
||||
if (events) {
|
||||
exit();
|
||||
} else {
|
||||
super.deactivate();
|
||||
volumeWorker.stop();
|
||||
try {
|
||||
iTunes.release();
|
||||
} catch (Exception e) {
|
||||
log.error(e);
|
||||
throw new DeactivateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void exit() {
|
||||
try {
|
||||
iTunes.quit();
|
||||
} catch (Exception e) {}
|
||||
volumeWorker.exit();
|
||||
super.exit();
|
||||
}
|
||||
|
||||
protected void begin(Action action) {
|
||||
log.trace("iTunesApplication begin: " + action);
|
||||
if (!active) return;
|
||||
switch (action) {
|
||||
case FORWARD:
|
||||
iTunes.fastForward();
|
||||
break;
|
||||
case REWIND:
|
||||
iTunes.rewind();
|
||||
break;
|
||||
case VOLUME_UP:
|
||||
volumeWorker.start(VOLUME_CHANGE_RATE);
|
||||
break;
|
||||
case VOLUME_DOWN:
|
||||
volumeWorker.start(-VOLUME_CHANGE_RATE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void end(Action action) {
|
||||
log.trace("iTunesApplication end: " + action);
|
||||
if (!active) return;
|
||||
switch (action) {
|
||||
case PLAY:
|
||||
iTunes.playPause();
|
||||
break;
|
||||
case NEXT:
|
||||
iTunes.nextTrack();
|
||||
break;
|
||||
case PREVIOUS:
|
||||
iTunes.previousTrack();
|
||||
break;
|
||||
case FORWARD:
|
||||
iTunes.resume();
|
||||
break;
|
||||
case REWIND:
|
||||
iTunes.resume();
|
||||
break;
|
||||
case MUTE:
|
||||
iTunes.toggleMute();
|
||||
break;
|
||||
case VOLUME_UP:
|
||||
case VOLUME_DOWN:
|
||||
volumeWorker.stop();
|
||||
break;
|
||||
case SHUFFLE:
|
||||
iTunes.toggleShuffle();
|
||||
break;
|
||||
case REPEAT:
|
||||
iTunes.cycleSongRepeat();
|
||||
break;
|
||||
case LIKE:
|
||||
iTunes.playlistAddCurrentTrack(PLAYLIST_LIKE);
|
||||
break;
|
||||
case DISLIKE:
|
||||
iTunes.playlistAddCurrentTrack(PLAYLIST_DISLIKE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected int getVolume() {
|
||||
return iTunes.getSoundVolume();
|
||||
}
|
||||
|
||||
public void onDatabaseChangedEvent(int[][] deletedObjectIDs, int[][] changedObjectIDs) {}
|
||||
public void onPlayerPlayEvent(ITTrack iTrack) {
|
||||
if (active) {
|
||||
log.trace("iTunesEvent: play");
|
||||
}
|
||||
}
|
||||
|
||||
public void onPlayerStopEvent(ITTrack iTrack) {
|
||||
if (active) {
|
||||
log.trace("iTunesEvent: stop");
|
||||
}
|
||||
}
|
||||
|
||||
public void onPlayerPlayingTrackChangedEvent(ITTrack iTrack) {}
|
||||
public void onCOMCallsDisabledEvent(ITCOMDisabledReason reason) {}
|
||||
public void onCOMCallsEnabledEvent() {}
|
||||
public void onQuittingEvent() {}
|
||||
public void onAboutToPromptUserToQuitEvent() {}
|
||||
public void onSoundVolumeChangedEvent(int newVolume) {}
|
||||
|
||||
protected class VolumeWorker extends Worker {
|
||||
protected int volumeChangeRate;
|
||||
|
||||
public void start(int volumeChangeRate) {
|
||||
super.start();
|
||||
this.volumeChangeRate = volumeChangeRate;
|
||||
}
|
||||
|
||||
public void work() {
|
||||
iTunes.setSoundVolume(getVolume() + volumeChangeRate);
|
||||
sleep(VOLUME_SLEEP);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package mimis.application.lirc;
|
||||
|
||||
import mimis.application.Application;
|
||||
import mimis.device.lirc.LircButton;
|
||||
import mimis.device.lirc.LircService;
|
||||
import mimis.device.lirc.remote.WC02IPOButton;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.worker.Component;
|
||||
|
||||
public class LircApplication extends Component implements Application {
|
||||
protected LircService lircService;
|
||||
|
||||
public LircApplication(String title) {
|
||||
super(title);
|
||||
lircService = new LircService();
|
||||
lircService.put(WC02IPOButton.NAME, WC02IPOButton.values());
|
||||
}
|
||||
|
||||
public void activate() throws ActivateException {
|
||||
lircService.activate();
|
||||
super.activate();
|
||||
}
|
||||
|
||||
public boolean active() {
|
||||
return active = lircService.active();
|
||||
}
|
||||
|
||||
protected void deactivate() throws DeactivateException {
|
||||
super.deactivate();
|
||||
lircService.stop();
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
super.exit();
|
||||
lircService.exit();
|
||||
}
|
||||
|
||||
public void send(LircButton button) {
|
||||
lircService.send(button);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package mimis.application.lirc.ipod;
|
||||
|
||||
import mimis.application.lirc.LircApplication;
|
||||
import mimis.device.lirc.remote.WC02IPOButton;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.value.Action;
|
||||
import mimis.worker.Worker;
|
||||
|
||||
public class iPodApplication extends LircApplication {
|
||||
protected static final String TITLE = "iPod";
|
||||
protected static final int VOLUME_SLEEP = 100;
|
||||
|
||||
protected VolumeWorker volumeWorker;
|
||||
|
||||
public iPodApplication() {
|
||||
super(TITLE);
|
||||
volumeWorker = new VolumeWorker();
|
||||
}
|
||||
|
||||
protected void deactivate() throws DeactivateException {
|
||||
super.deactivate();
|
||||
volumeWorker.stop();
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
super.exit();
|
||||
volumeWorker.exit();
|
||||
}
|
||||
|
||||
protected void begin(Action action) {
|
||||
log.trace("iPodApplication begin: " + action);
|
||||
if (!active) return;
|
||||
switch (action) {
|
||||
case VOLUME_UP:
|
||||
try {
|
||||
volumeWorker.activate(1);
|
||||
} catch (ActivateException e) {
|
||||
log.error(e);
|
||||
}
|
||||
break;
|
||||
case VOLUME_DOWN:
|
||||
try {
|
||||
volumeWorker.activate(-1);
|
||||
} catch (ActivateException e) {
|
||||
log.error(e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void end(Action action) {
|
||||
log.trace("iPodApplication end: " + action);
|
||||
if (!active) return;
|
||||
switch (action) {
|
||||
case PLAY:
|
||||
send(WC02IPOButton.PLAY);
|
||||
break;
|
||||
case NEXT:
|
||||
send(WC02IPOButton.NEXT);
|
||||
break;
|
||||
case PREVIOUS:
|
||||
send(WC02IPOButton.PREVIOUS);
|
||||
break;
|
||||
case VOLUME_UP:
|
||||
case VOLUME_DOWN:
|
||||
volumeWorker.stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected class VolumeWorker extends Worker {
|
||||
protected int volumeChangeRate;
|
||||
|
||||
public void activate(int volumeChangeRate) throws ActivateException {
|
||||
super.activate();
|
||||
this.volumeChangeRate = volumeChangeRate;
|
||||
send(volumeChangeRate > 0 ? WC02IPOButton.PLUS : WC02IPOButton.MINUS);
|
||||
}
|
||||
|
||||
public void work() {
|
||||
lircService.send(WC02IPOButton.HOLD);
|
||||
sleep(VOLUME_SLEEP);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package mimis.application.mpc;
|
||||
|
||||
import mimis.application.cmd.windows.WindowsApplication;
|
||||
import mimis.value.Action;
|
||||
import mimis.worker.Worker;
|
||||
|
||||
public class MPCApplication extends WindowsApplication {
|
||||
protected final static String PROGRAM = "mpc-hc.exe";
|
||||
protected final static String TITLE = "Media Player Classic";
|
||||
protected final static String WINDOW = "MediaPlayerClassicW";
|
||||
|
||||
protected static final int VOLUME_SLEEP = 50;
|
||||
protected static final int SEEK_SLEEP = 50;
|
||||
|
||||
protected VolumeWorker volumeWorker;
|
||||
protected SeekWorker seekWorker;
|
||||
|
||||
public MPCApplication() {
|
||||
super(PROGRAM, TITLE, WINDOW);
|
||||
volumeWorker = new VolumeWorker();
|
||||
seekWorker = new SeekWorker();
|
||||
}
|
||||
|
||||
public void begin(Action action) {
|
||||
log.trace("MPCApplication: " + action);
|
||||
switch (action) {
|
||||
case FORWARD:
|
||||
seekWorker.start(1);
|
||||
break;
|
||||
case REWIND:
|
||||
seekWorker.start(-1);
|
||||
break;
|
||||
case VOLUME_UP:
|
||||
volumeWorker.start(1);
|
||||
break;
|
||||
case VOLUME_DOWN:
|
||||
volumeWorker.start(-1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void end(Action action) {
|
||||
log.trace("MPCApplication: " + action);
|
||||
switch (action) {
|
||||
case PLAY:
|
||||
command(889);
|
||||
break;
|
||||
case NEXT:
|
||||
command(921);
|
||||
break;
|
||||
case PREVIOUS:
|
||||
command(920);
|
||||
break;
|
||||
case FORWARD:
|
||||
case REWIND:
|
||||
seekWorker.stop();
|
||||
break;
|
||||
case MUTE:
|
||||
command(909);
|
||||
break;
|
||||
case VOLUME_UP:
|
||||
case VOLUME_DOWN:
|
||||
volumeWorker.stop();
|
||||
break;
|
||||
case FULLSCREEN:
|
||||
command(830);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return TITLE;
|
||||
}
|
||||
|
||||
protected class VolumeWorker extends Worker {
|
||||
protected int volumeChangeSign;
|
||||
|
||||
public void start(int volumeChangeSign) {
|
||||
super.start();
|
||||
this.volumeChangeSign = volumeChangeSign;
|
||||
}
|
||||
|
||||
public void work() {
|
||||
command(volumeChangeSign > 0 ? 907 : 908);
|
||||
sleep(VOLUME_SLEEP);
|
||||
}
|
||||
};
|
||||
|
||||
protected class SeekWorker extends Worker {
|
||||
protected int seekDirection;
|
||||
|
||||
public void start(int seekDirection) {
|
||||
super.start();
|
||||
this.seekDirection = seekDirection;
|
||||
}
|
||||
|
||||
public void work() {
|
||||
command(seekDirection > 0 ? 900 : 889);
|
||||
sleep(SEEK_SLEEP);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package mimis.application.robot;
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Robot;
|
||||
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.value.Key;
|
||||
import mimis.worker.Component;
|
||||
|
||||
public class RobotApplication extends Component {
|
||||
protected Robot robot;
|
||||
|
||||
public void activate() throws ActivateException {
|
||||
try {
|
||||
robot = new Robot();
|
||||
robot.setAutoWaitForIdle(true);
|
||||
} catch (AWTException e) {
|
||||
log.error(e);
|
||||
throw new ActivateException();
|
||||
}
|
||||
super.activate();
|
||||
}
|
||||
|
||||
public void press(Key key) {
|
||||
robot.keyPress(key.getCode());
|
||||
}
|
||||
|
||||
public void press(char key) {
|
||||
robot.keyPress(key);
|
||||
}
|
||||
|
||||
public void release(Key key) {
|
||||
robot.keyRelease(key.getCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
package mimis.application.vlc;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import mimis.application.cmd.CMDApplication;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.util.Native;
|
||||
import mimis.value.Action;
|
||||
import mimis.value.Amount;
|
||||
import mimis.value.Registry;
|
||||
import mimis.worker.Worker;
|
||||
|
||||
public class VLCApplication extends CMDApplication {
|
||||
protected final static Registry REGISTRY = Registry.CLASSES_ROOT;
|
||||
protected final static String KEY = "Applications\\vlc.exe\\shell\\Open\\command";
|
||||
protected final static String PROGRAM = "vlc.exe";
|
||||
protected final static String TITLE = "VLC media player";
|
||||
|
||||
protected static final int POSTION_CHANGE_RATE = 1;
|
||||
protected static final int VOLUME_CHANGE_RATE = 20;
|
||||
|
||||
protected static final String HOST = "localhost";
|
||||
protected static final int PORT = 8080;
|
||||
|
||||
protected static final int VOLUME_SLEEP = 100;
|
||||
protected static final int SEEK_SLEEP = 100;
|
||||
|
||||
protected VolumeWorker volumeWorker;
|
||||
protected SeekWorker seekWorker;
|
||||
|
||||
protected int volume = 255;
|
||||
protected boolean muted = false;
|
||||
|
||||
public VLCApplication() {
|
||||
super(PROGRAM, TITLE);
|
||||
volumeWorker = new VolumeWorker();
|
||||
seekWorker = new SeekWorker();
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
Pattern pattern = Pattern.compile("\"([^\"]+)\"");
|
||||
Matcher matcher = pattern.matcher(Native.getValue(REGISTRY, KEY));
|
||||
return matcher.find() ? matcher.group(1) : null;
|
||||
}
|
||||
|
||||
public void command(String command) {
|
||||
String request = String.format("http://%s:%d/requests/status.xml?command=%s", HOST, PORT, command);
|
||||
try {
|
||||
URL url = new URL(request);
|
||||
HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection();
|
||||
int response = httpUrlConnection.getResponseCode();
|
||||
log.trace("Response: " + response);
|
||||
} catch (MalformedURLException e) {
|
||||
log.error(e);
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void deactivate() throws DeactivateException {
|
||||
super.deactivate();
|
||||
volumeWorker.stop();
|
||||
seekWorker.stop();
|
||||
Native.terminate(program);
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
super.exit();
|
||||
volumeWorker.exit();
|
||||
seekWorker.exit();
|
||||
}
|
||||
|
||||
public void begin(Action action) {
|
||||
log.trace("VLCApplication begin: " + action);
|
||||
try {
|
||||
switch (action) {
|
||||
case VOLUME_UP:
|
||||
volumeWorker.activate("+");
|
||||
break;
|
||||
case VOLUME_DOWN:
|
||||
volumeWorker.activate("-");
|
||||
break;
|
||||
case FORWARD:
|
||||
seekWorker.start(Amount.SMALL, "+");
|
||||
break;
|
||||
case REWIND:
|
||||
seekWorker.start(Amount.SMALL, "-");
|
||||
break;
|
||||
}
|
||||
} catch (ActivateException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void end(Action action) {
|
||||
log.trace("VLCApplication end: " + action);
|
||||
switch (action) {
|
||||
case PLAY:
|
||||
command("pl_pause");
|
||||
break;
|
||||
case PAUSE:
|
||||
command("pl_pause");
|
||||
break;
|
||||
case NEXT:
|
||||
command("pl_next");
|
||||
break;
|
||||
case PREVIOUS:
|
||||
command("pl_previous");
|
||||
break;
|
||||
case FORWARD:
|
||||
case REWIND:
|
||||
seekWorker.stop();
|
||||
break;
|
||||
case MUTE:
|
||||
command("volume&val=" + toggleMute());
|
||||
break;
|
||||
case VOLUME_UP:
|
||||
case VOLUME_DOWN:
|
||||
volumeWorker.stop();
|
||||
break;
|
||||
case SHUFFLE:
|
||||
command("command=pl_random");
|
||||
break;
|
||||
case REPEAT:
|
||||
command("command=pl_repeat");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void volumeUp() {
|
||||
if (!muted) {
|
||||
volume += VOLUME_CHANGE_RATE;
|
||||
command("volume&val=+" + VOLUME_CHANGE_RATE);
|
||||
}
|
||||
}
|
||||
|
||||
protected void volumeDown() {
|
||||
if (!muted) {
|
||||
volume -= VOLUME_CHANGE_RATE;
|
||||
command("volume&val=-" + VOLUME_CHANGE_RATE);
|
||||
}
|
||||
}
|
||||
|
||||
protected int toggleMute() {
|
||||
return (muted = !muted) ? 0 : volume;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return TITLE;
|
||||
}
|
||||
|
||||
protected class VolumeWorker extends Worker {
|
||||
protected String volumeChangeSign;
|
||||
|
||||
public void activate(String volumeChangeSign) throws ActivateException {
|
||||
super.activate();
|
||||
this.volumeChangeSign = volumeChangeSign;
|
||||
}
|
||||
|
||||
public void work() {
|
||||
volume += VOLUME_CHANGE_RATE;
|
||||
command("volume&val=" + volumeChangeSign + VOLUME_CHANGE_RATE);
|
||||
sleep(VOLUME_SLEEP);
|
||||
}
|
||||
};
|
||||
|
||||
protected class SeekWorker extends Worker {
|
||||
protected Amount amount;
|
||||
protected String seekDirection;
|
||||
|
||||
public void start(Amount amount, String seekDirection) {
|
||||
super.start();
|
||||
this.amount = amount;
|
||||
this.seekDirection = seekDirection;
|
||||
}
|
||||
|
||||
public void work() {
|
||||
switch (amount) {
|
||||
case SMALL:
|
||||
command("command=seek&val=" + seekDirection + POSTION_CHANGE_RATE);
|
||||
break;
|
||||
case MEDIUM:
|
||||
command("command=seek&val=" + seekDirection + POSTION_CHANGE_RATE * 2);
|
||||
break;
|
||||
case LARGE:
|
||||
command("command=seek&val=" + seekDirection + POSTION_CHANGE_RATE * 3);
|
||||
break;
|
||||
}
|
||||
sleep(SEEK_SLEEP);
|
||||
}
|
||||
};
|
||||
}
|
||||
5
java/mimis/src/main/java/mimis/device/Device.java
Normal file
5
java/mimis/src/main/java/mimis/device/Device.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package mimis.device;
|
||||
|
||||
public interface Device {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package mimis.device.javainput;
|
||||
|
||||
import mimis.input.Button;
|
||||
import mimis.exception.button.UnknownDirectionException;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
public enum DirectionButton implements Button {
|
||||
NORTH (0),
|
||||
NORTHEAST (45),
|
||||
EAST (90),
|
||||
SOUTHEAST (135),
|
||||
SOUTH (180),
|
||||
SOUTHWEST (225),
|
||||
WEST (270),
|
||||
NORTHWEST (315);
|
||||
|
||||
protected int code;
|
||||
|
||||
private DirectionButton(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static DirectionButton create(int angle) throws UnknownDirectionException {
|
||||
for (DirectionButton button : DirectionButton.values()) {
|
||||
if (button.getCode() == angle) {
|
||||
return button;
|
||||
}
|
||||
}
|
||||
throw new UnknownDirectionException();
|
||||
}
|
||||
|
||||
public static DirectionButton create(JXInputDirectionalEvent event) throws UnknownDirectionException {
|
||||
return create(event.getDirectional().getDirection() / 100);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package mimis.device.javainput;
|
||||
|
||||
import mimis.device.Device;
|
||||
import mimis.exception.ButtonException;
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
import mimis.exception.button.UnknownDirectionException;
|
||||
import mimis.exception.device.DeviceNotFoundException;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.input.Button;
|
||||
import mimis.input.state.Press;
|
||||
import mimis.input.state.Release;
|
||||
import mimis.worker.Component;
|
||||
import de.hardcode.jxinput.JXInputDevice;
|
||||
import de.hardcode.jxinput.JXInputManager;
|
||||
import de.hardcode.jxinput.event.JXInputAxisEvent;
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
public abstract class JavaInputDevice extends Component implements Device {
|
||||
protected String name;
|
||||
|
||||
public JavaInputDevice(String title, String name) {
|
||||
super(title);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
protected JavaInputListener javaInputListener;
|
||||
protected Button previousDirectionalButton;
|
||||
|
||||
protected void activate() throws ActivateException {
|
||||
super.activate();
|
||||
try {
|
||||
JXInputDevice jxinputDevice = getDevice(name);
|
||||
log.debug(jxinputDevice);
|
||||
javaInputListener = new JavaInputListener(this, jxinputDevice);
|
||||
} catch (DeviceNotFoundException e) {
|
||||
active = false;
|
||||
throw new ActivateException();
|
||||
}
|
||||
javaInputListener.start();
|
||||
}
|
||||
|
||||
protected void deactivate() throws DeactivateException {
|
||||
super.deactivate();
|
||||
javaInputListener.stop();
|
||||
}
|
||||
|
||||
public void processEvent(JXInputAxisEvent event) {}
|
||||
|
||||
public void processEvent(JXInputButtonEvent event) throws ButtonException {
|
||||
Button button = getButton(event);
|
||||
if (event.getButton().getState()) {
|
||||
route(new Press(button));
|
||||
} else {
|
||||
route(new Release(button));
|
||||
}
|
||||
}
|
||||
|
||||
public void processEvent(JXInputDirectionalEvent event) throws UnknownDirectionException {
|
||||
Button button = getButton(event);
|
||||
if (event.getDirectional().isCentered()) {
|
||||
if (previousDirectionalButton != null) {
|
||||
route(new Release(previousDirectionalButton));
|
||||
}
|
||||
} else {
|
||||
route(new Press(button));
|
||||
previousDirectionalButton = button;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Button getButton(JXInputButtonEvent event) throws UnknownButtonException;
|
||||
protected abstract Button getButton(JXInputDirectionalEvent event) throws UnknownDirectionException;
|
||||
|
||||
public static JXInputDevice getDevice(String name) throws DeviceNotFoundException {
|
||||
int numberOfDevices = JXInputManager.getNumberOfDevices();
|
||||
for (int i = 0; i < numberOfDevices; ++i) {
|
||||
JXInputDevice device = JXInputManager.getJXInputDevice(i);
|
||||
if (device.getName().startsWith(name)) {
|
||||
return device;
|
||||
}
|
||||
}
|
||||
throw new DeviceNotFoundException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package mimis.device.javainput;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
import mimis.exception.ButtonException;
|
||||
import mimis.worker.Worker;
|
||||
import de.hardcode.jxinput.Button;
|
||||
import de.hardcode.jxinput.Directional;
|
||||
import de.hardcode.jxinput.JXInputDevice;
|
||||
import de.hardcode.jxinput.JXInputManager;
|
||||
import de.hardcode.jxinput.event.JXInputAxisEvent;
|
||||
import de.hardcode.jxinput.event.JXInputAxisEventListener;
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import de.hardcode.jxinput.event.JXInputButtonEventListener;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEventListener;
|
||||
import de.hardcode.jxinput.event.JXInputEventManager;
|
||||
|
||||
public class JavaInputListener extends Worker implements Runnable, JXInputAxisEventListener, JXInputButtonEventListener, JXInputDirectionalEventListener {
|
||||
protected JavaInputDevice javaInputDevice;
|
||||
protected JXInputDevice jxinputDevice;
|
||||
protected Queue<JXInputAxisEvent> axisEventQueue;
|
||||
protected Queue<JXInputButtonEvent> buttonEventQueue;
|
||||
protected Queue<JXInputDirectionalEvent> directionalEventQueue;
|
||||
|
||||
public JavaInputListener(JavaInputDevice javaInputDevice, JXInputDevice jxinputDevice) {
|
||||
this.javaInputDevice = javaInputDevice;
|
||||
this.jxinputDevice = jxinputDevice;
|
||||
axisEventQueue = new LinkedList<JXInputAxisEvent>();
|
||||
buttonEventQueue = new LinkedList<JXInputButtonEvent>();
|
||||
directionalEventQueue = new LinkedList<JXInputDirectionalEvent>();
|
||||
addListeners();
|
||||
}
|
||||
|
||||
protected void addListeners() {
|
||||
/*for (int i = 0; i < jxinputDevice.getMaxNumberOfAxes(); ++i) {
|
||||
Axis axis = jxinputDevice.getAxis(i);
|
||||
if (axis != null) {
|
||||
JXInputEventManager.addListener(this, axis);
|
||||
}
|
||||
}*/
|
||||
for (int i = 0; i < jxinputDevice.getMaxNumberOfButtons(); ++i) {
|
||||
Button button = jxinputDevice.getButton(i);
|
||||
if (button != null) {
|
||||
JXInputEventManager.addListener(this, button);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < jxinputDevice.getMaxNumberOfDirectionals(); ++i) {
|
||||
Directional directional = jxinputDevice.getDirectional(i);
|
||||
if (directional != null) {
|
||||
JXInputEventManager.addListener(this, directional);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void changed(JXInputAxisEvent event) {
|
||||
axisEventQueue.add(event);
|
||||
}
|
||||
|
||||
public void changed(JXInputButtonEvent event) {
|
||||
buttonEventQueue.add(event);
|
||||
}
|
||||
|
||||
public void changed(JXInputDirectionalEvent event) {
|
||||
directionalEventQueue.add(event);
|
||||
}
|
||||
|
||||
public void work() {
|
||||
JXInputManager.updateFeatures();
|
||||
if (!axisEventQueue.isEmpty()) {
|
||||
javaInputDevice.processEvent(axisEventQueue.poll());
|
||||
} else if (!buttonEventQueue.isEmpty()) {
|
||||
try {
|
||||
javaInputDevice.processEvent(buttonEventQueue.poll());
|
||||
} catch (ButtonException e) {}
|
||||
} else if (!directionalEventQueue.isEmpty()) {
|
||||
try {
|
||||
javaInputDevice.processEvent(directionalEventQueue.poll());
|
||||
} catch (ButtonException e) {}
|
||||
} else {
|
||||
sleep();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package mimis.device.javainput.extreme3d;
|
||||
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
import mimis.input.Button;
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
|
||||
public enum Extreme3DButton implements Button {
|
||||
ONE ("Button 0"),
|
||||
TWO ("Button 1"),
|
||||
THREE ("Button 2"),
|
||||
FOUR ("Button 3"),
|
||||
FIVE ("Button 4"),
|
||||
SIX ("Button 5"),
|
||||
SEVEN ("Button 6"),
|
||||
EIGHT ("Button 7"),
|
||||
NINE ("Button 8"),
|
||||
TEN ("Button 9"),
|
||||
ELEVEN ("Button 10"),
|
||||
TWELVE ("Button 11");
|
||||
|
||||
protected String code;
|
||||
|
||||
private Extreme3DButton(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static Extreme3DButton create(String code) throws UnknownButtonException {
|
||||
for (Extreme3DButton button : Extreme3DButton.values()) {
|
||||
if (button.getCode().equals(code)) {
|
||||
return button;
|
||||
}
|
||||
}
|
||||
throw new UnknownButtonException();
|
||||
}
|
||||
|
||||
public static Extreme3DButton create(JXInputButtonEvent event) throws UnknownButtonException {
|
||||
return create(event.getButton().getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package mimis.device.javainput.extreme3d;
|
||||
|
||||
import mimis.device.javainput.DirectionButton;
|
||||
import mimis.device.javainput.JavaInputDevice;
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
import mimis.exception.button.UnknownDirectionException;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.input.Button;
|
||||
import mimis.value.Action;
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
public class Extreme3DDevice extends JavaInputDevice {
|
||||
protected static final String TITLE = "Extreme 3D";
|
||||
protected static final String NAME = "Logitech Extreme 3D";
|
||||
|
||||
protected static Extreme3DTaskMapCycle taskMapCycle;
|
||||
|
||||
public Extreme3DDevice() {
|
||||
super(TITLE, NAME);
|
||||
taskMapCycle = new Extreme3DTaskMapCycle();
|
||||
}
|
||||
|
||||
protected void activate() throws ActivateException {
|
||||
super.activate();
|
||||
parser(Action.ADD, taskMapCycle.mimis);
|
||||
parser(Action.ADD, taskMapCycle.player);
|
||||
parser(Action.ADD, taskMapCycle.like);
|
||||
}
|
||||
|
||||
protected Button getButton(JXInputButtonEvent event) throws UnknownButtonException {
|
||||
return Extreme3DButton.create(event);
|
||||
}
|
||||
|
||||
protected Button getButton(JXInputDirectionalEvent event) throws UnknownDirectionException {
|
||||
return DirectionButton.create(event);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package mimis.device.javainput.extreme3d;
|
||||
|
||||
import mimis.device.javainput.DirectionButton;
|
||||
import mimis.input.Task;
|
||||
import mimis.input.state.Press;
|
||||
import mimis.state.TaskMap;
|
||||
import mimis.state.TaskMapCycle;
|
||||
import mimis.value.Action;
|
||||
import mimis.value.Target;
|
||||
|
||||
public class Extreme3DTaskMapCycle extends TaskMapCycle {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
public TaskMap mimis, player, like;
|
||||
|
||||
public Extreme3DTaskMapCycle() {
|
||||
/* Mimis */
|
||||
mimis = new TaskMap();
|
||||
mimis.add(
|
||||
new Press(Extreme3DButton.SEVEN),
|
||||
new Task(Action.PREVIOUS, Target.MAIN));
|
||||
mimis.add(
|
||||
new Press(Extreme3DButton.EIGHT),
|
||||
new Task(Action.NEXT, Target.MAIN));
|
||||
add(mimis);
|
||||
|
||||
/* Player */
|
||||
player = new TaskMap();
|
||||
player.add(
|
||||
new Press(Extreme3DButton.ONE),
|
||||
new Task(Action.PLAY, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(Extreme3DButton.TWO),
|
||||
new Task(Action.MUTE, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(Extreme3DButton.NINE),
|
||||
new Task(Action.SHUFFLE, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(Extreme3DButton.TEN),
|
||||
new Task(Action.REPEAT, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(Extreme3DButton.SIX),
|
||||
new Task(Action.NEXT, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(Extreme3DButton.FOUR),
|
||||
new Task(Action.PREVIOUS, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(Extreme3DButton.FIVE),
|
||||
new Task(Action.FORWARD, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(Extreme3DButton.THREE),
|
||||
new Task(Action.REWIND, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(DirectionButton.SOUTH),
|
||||
new Task(Action.VOLUME_DOWN, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(DirectionButton.NORTH),
|
||||
new Task(Action.VOLUME_UP, Target.CURRENT));
|
||||
add(player);
|
||||
|
||||
like = new TaskMap();
|
||||
like.add(
|
||||
new Press(Extreme3DButton.ELEVEN),
|
||||
new Task(Action.LIKE, Target.CURRENT));
|
||||
like.add(
|
||||
new Press(Extreme3DButton.TWELVE),
|
||||
new Task(Action.DISLIKE, Target.CURRENT));
|
||||
add(like);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package mimis.device.javainput.rumblepad;
|
||||
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
import mimis.input.Button;
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
|
||||
public enum RumblepadButton implements Button {
|
||||
ONE ("Button 0"),
|
||||
TWO ("Button 1"),
|
||||
THREE ("Button 2"),
|
||||
FOUR ("Button 3"),
|
||||
FIVE ("Button 4"),
|
||||
SIX ("Button 5"),
|
||||
SEVEN ("Button 6"),
|
||||
EIGHT ("Button 7"),
|
||||
NINE ("Button 8"),
|
||||
TEN ("Button 9");
|
||||
|
||||
protected String code;
|
||||
|
||||
private RumblepadButton(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static RumblepadButton create(String code) throws UnknownButtonException {
|
||||
for (RumblepadButton button : RumblepadButton.values()) {
|
||||
if (button.getCode().equals(code)) {
|
||||
return button;
|
||||
}
|
||||
}
|
||||
throw new UnknownButtonException();
|
||||
}
|
||||
|
||||
public static RumblepadButton create(JXInputButtonEvent event) throws UnknownButtonException {
|
||||
return create(event.getButton().getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package mimis.device.javainput.rumblepad;
|
||||
|
||||
import mimis.device.javainput.DirectionButton;
|
||||
import mimis.device.javainput.JavaInputDevice;
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
import mimis.exception.button.UnknownDirectionException;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.input.Button;
|
||||
import mimis.value.Action;
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
public class RumblepadDevice extends JavaInputDevice {
|
||||
protected static final String TITLE = "RumblePad";
|
||||
protected static final String NAME = "Logitech RumblePad 2 USB";
|
||||
|
||||
protected static RumblepadTaskMapCycle taskMapCycle;
|
||||
|
||||
public RumblepadDevice() {
|
||||
super(TITLE, NAME);
|
||||
taskMapCycle = new RumblepadTaskMapCycle();
|
||||
}
|
||||
|
||||
protected void activate() throws ActivateException {
|
||||
super.activate();
|
||||
parser(Action.ADD, taskMapCycle.mimis);
|
||||
parser(Action.ADD, taskMapCycle.player);
|
||||
parser(Action.ADD, taskMapCycle.like);
|
||||
}
|
||||
|
||||
protected Button getButton(JXInputButtonEvent event) throws UnknownButtonException {
|
||||
return RumblepadButton.create(event);
|
||||
}
|
||||
|
||||
protected Button getButton(JXInputDirectionalEvent event) throws UnknownDirectionException {
|
||||
return DirectionButton.create(event);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package mimis.device.javainput.rumblepad;
|
||||
|
||||
import mimis.device.javainput.DirectionButton;
|
||||
import mimis.input.Task;
|
||||
import mimis.input.state.Press;
|
||||
import mimis.state.TaskMap;
|
||||
import mimis.state.TaskMapCycle;
|
||||
import mimis.value.Action;
|
||||
import mimis.value.Target;
|
||||
|
||||
public class RumblepadTaskMapCycle extends TaskMapCycle {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
public TaskMap mimis, player, like;
|
||||
|
||||
public RumblepadTaskMapCycle() {
|
||||
/* Mimis */
|
||||
mimis = new TaskMap();
|
||||
mimis.add(
|
||||
new Press(RumblepadButton.ONE),
|
||||
new Task(Action.PREVIOUS, Target.MAIN));
|
||||
mimis.add(
|
||||
new Press(RumblepadButton.THREE),
|
||||
new Task(Action.NEXT, Target.MAIN));
|
||||
add(mimis);
|
||||
|
||||
/* Player */
|
||||
player = new TaskMap();
|
||||
player.add(
|
||||
new Press(DirectionButton.WEST),
|
||||
new Task(Action.PLAY, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(DirectionButton.EAST),
|
||||
new Task(Action.MUTE, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(RumblepadButton.NINE),
|
||||
new Task(Action.SHUFFLE, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(RumblepadButton.TEN),
|
||||
new Task(Action.REPEAT, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(RumblepadButton.EIGHT),
|
||||
new Task(Action.NEXT, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(RumblepadButton.SIX),
|
||||
new Task(Action.PREVIOUS, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(RumblepadButton.SEVEN),
|
||||
new Task(Action.FORWARD, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(RumblepadButton.FIVE),
|
||||
new Task(Action.REWIND, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(DirectionButton.SOUTH),
|
||||
new Task(Action.VOLUME_DOWN, Target.CURRENT));
|
||||
player.add(
|
||||
new Press(DirectionButton.NORTH),
|
||||
new Task(Action.VOLUME_UP, Target.CURRENT));
|
||||
add(player);
|
||||
|
||||
like = new TaskMap();
|
||||
like.add(
|
||||
new Press(RumblepadButton.FOUR),
|
||||
new Task(Action.LIKE, Target.CURRENT));
|
||||
like.add(
|
||||
new Press(RumblepadButton.TWO),
|
||||
new Task(Action.DISLIKE, Target.CURRENT));
|
||||
add(like);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package mimis.device.jintellitype;
|
||||
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
import mimis.input.Button;
|
||||
|
||||
import com.melloware.jintellitype.JIntellitype;
|
||||
|
||||
|
||||
public enum CommandButton implements Button {
|
||||
BROWSER_BACKWARD (JIntellitype.APPCOMMAND_BROWSER_BACKWARD),
|
||||
BROWSER_FORWARD (JIntellitype.APPCOMMAND_BROWSER_FORWARD),
|
||||
BROWSER_REFRESH (JIntellitype.APPCOMMAND_BROWSER_REFRESH),
|
||||
BROWSER_STOP (JIntellitype.APPCOMMAND_BROWSER_STOP),
|
||||
BROWSER_SEARCH (JIntellitype.APPCOMMAND_BROWSER_SEARCH),
|
||||
BROWSER_FAVOURITES (JIntellitype.APPCOMMAND_BROWSER_FAVOURITES),
|
||||
BROWSER_HOME (JIntellitype.APPCOMMAND_BROWSER_HOME),
|
||||
VOLUME_MUTE (JIntellitype.APPCOMMAND_VOLUME_MUTE),
|
||||
VOLUME_DOWN (JIntellitype.APPCOMMAND_VOLUME_DOWN),
|
||||
VOLUME_UP (JIntellitype.APPCOMMAND_VOLUME_UP),
|
||||
MEDIA_NEXTTRACK (JIntellitype.APPCOMMAND_MEDIA_NEXTTRACK),
|
||||
MEDIA_PREVIOUSTRACK (JIntellitype.APPCOMMAND_MEDIA_PREVIOUSTRACK),
|
||||
MEDIA_STOP (JIntellitype.APPCOMMAND_MEDIA_STOP),
|
||||
MEDIA_PLAY_PAUSE (JIntellitype.APPCOMMAND_MEDIA_PLAY_PAUSE),
|
||||
LAUNCH_MAIL (JIntellitype.APPCOMMAND_LAUNCH_MAIL),
|
||||
LAUNCH_MEDIA_SELECT (JIntellitype.APPCOMMAND_LAUNCH_MEDIA_SELECT),
|
||||
LAUNCH_APP1 (JIntellitype.APPCOMMAND_LAUNCH_APP1),
|
||||
LAUNCH_APP2 (JIntellitype.APPCOMMAND_LAUNCH_APP2),
|
||||
BASS_DOWN (JIntellitype.APPCOMMAND_BASS_DOWN),
|
||||
BASS_BOOST (JIntellitype.APPCOMMAND_BASS_BOOST),
|
||||
BASS_UP (JIntellitype.APPCOMMAND_BASS_UP),
|
||||
TREBLE_DOWN (JIntellitype.APPCOMMAND_TREBLE_DOWN),
|
||||
TREBLE_UP (JIntellitype.APPCOMMAND_TREBLE_UP),
|
||||
MICROPHONE_VOLUME_MUTE (JIntellitype.APPCOMMAND_MICROPHONE_VOLUME_MUTE),
|
||||
MICROPHONE_VOLUME_DOWN (JIntellitype.APPCOMMAND_MICROPHONE_VOLUME_DOWN),
|
||||
MICROPHONE_VOLUME_UP (JIntellitype.APPCOMMAND_MICROPHONE_VOLUME_UP),
|
||||
HELP (JIntellitype.APPCOMMAND_HELP),
|
||||
FIND (JIntellitype.APPCOMMAND_FIND),
|
||||
NEW (JIntellitype.APPCOMMAND_NEW),
|
||||
OPEN (JIntellitype.APPCOMMAND_OPEN),
|
||||
CLOSE (JIntellitype.APPCOMMAND_CLOSE),
|
||||
SAVE (JIntellitype.APPCOMMAND_SAVE),
|
||||
PRINT (JIntellitype.APPCOMMAND_PRINT),
|
||||
UNDO (JIntellitype.APPCOMMAND_UNDO),
|
||||
REDO (JIntellitype.APPCOMMAND_REDO),
|
||||
COPY (JIntellitype.APPCOMMAND_COPY),
|
||||
CUT (JIntellitype.APPCOMMAND_CUT),
|
||||
PASTE (JIntellitype.APPCOMMAND_PASTE),
|
||||
REPLY_TO_MAIL (JIntellitype.APPCOMMAND_REPLY_TO_MAIL),
|
||||
FORWARD_MAIL (JIntellitype.APPCOMMAND_FORWARD_MAIL),
|
||||
SEND_MAIL (JIntellitype.APPCOMMAND_SEND_MAIL),
|
||||
SPELL_CHECK (JIntellitype.APPCOMMAND_SPELL_CHECK),
|
||||
DICTATE_OR_COMMAND_CONTROL_TOGGLE (JIntellitype.APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE),
|
||||
MIC_ON_OFF_TOGGLE (JIntellitype.APPCOMMAND_MIC_ON_OFF_TOGGLE),
|
||||
CORRECTION_LIST (JIntellitype.APPCOMMAND_CORRECTION_LIST);
|
||||
|
||||
protected int code;
|
||||
|
||||
private CommandButton(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static CommandButton create(int code) throws UnknownButtonException {
|
||||
for (CommandButton button : CommandButton.values()) {
|
||||
if (button.getCode() == code) {
|
||||
return button;
|
||||
}
|
||||
}
|
||||
throw new UnknownButtonException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package mimis.device.jintellitype;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mimis.input.Button;
|
||||
import mimis.value.Key;
|
||||
|
||||
import com.melloware.jintellitype.JIntellitype;
|
||||
|
||||
public class Hotkey implements Button {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
protected static ArrayList<Hotkey> hotkeyList;
|
||||
protected static JIntellitype jit;
|
||||
|
||||
public Hotkey(int modifier, int keycode) {
|
||||
int id = hotkeyList.size();
|
||||
jit.registerHotKey(id, modifier, keycode);
|
||||
hotkeyList.add(this);
|
||||
}
|
||||
|
||||
public Hotkey(int modifier, char character) {
|
||||
this(modifier, (int) Character.toUpperCase(character));
|
||||
}
|
||||
|
||||
public Hotkey(char character) {
|
||||
this(0, (int) Character.toUpperCase(character));
|
||||
}
|
||||
|
||||
public Hotkey(int keycode) {
|
||||
this(0, keycode);
|
||||
}
|
||||
|
||||
public Hotkey(Key key) {
|
||||
this(key.getCode());
|
||||
}
|
||||
|
||||
public Hotkey(int modifier, Key key) {
|
||||
this(modifier, key.getCode());
|
||||
}
|
||||
|
||||
public static void initialise(ArrayList<Hotkey> actionList, JIntellitype jit) {
|
||||
Hotkey.hotkeyList = actionList;
|
||||
Hotkey.jit = jit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package mimis.device.jintellitype;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mimis.device.Device;
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.input.state.Press;
|
||||
import mimis.input.state.Release;
|
||||
import mimis.value.Action;
|
||||
import mimis.worker.Component;
|
||||
|
||||
import com.melloware.jintellitype.HotkeyListener;
|
||||
import com.melloware.jintellitype.IntellitypeListener;
|
||||
import com.melloware.jintellitype.JIntellitype;
|
||||
|
||||
public class JIntellitypeDevice extends Component implements Device, HotkeyListener, IntellitypeListener {
|
||||
protected static final String TITLE = "Keyboard";
|
||||
|
||||
protected JIntellitypeTaskMapCycle taskMapCycle;
|
||||
protected ArrayList<Hotkey> hotkeyList;
|
||||
protected JIntellitype jit;
|
||||
|
||||
public JIntellitypeDevice() {
|
||||
super(TITLE);
|
||||
hotkeyList = new ArrayList<Hotkey>();
|
||||
jit = JIntellitype.getInstance();
|
||||
Hotkey.initialise(hotkeyList, jit);
|
||||
taskMapCycle = new JIntellitypeTaskMapCycle();
|
||||
}
|
||||
|
||||
protected void activate() throws ActivateException {
|
||||
super.activate();
|
||||
jit.addHotKeyListener(this);
|
||||
jit.addIntellitypeListener(this);
|
||||
parser(Action.ADD, taskMapCycle.mimis);
|
||||
parser(Action.ADD, taskMapCycle.player);
|
||||
}
|
||||
|
||||
public void onIntellitype(int command) {
|
||||
if (active) {
|
||||
try {
|
||||
CommandButton commandButton = CommandButton.create(command);
|
||||
route(new Press(commandButton));
|
||||
route(new Release(commandButton));
|
||||
} catch (UnknownButtonException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onHotKey(int id) {
|
||||
if (active) {
|
||||
Hotkey hotkey = hotkeyList.get(id);
|
||||
route(new Press(hotkey));
|
||||
route(new Release(hotkey));
|
||||
}
|
||||
}
|
||||
|
||||
protected void deactivate() throws DeactivateException {
|
||||
super.deactivate();
|
||||
jit.removeHotKeyListener(this);
|
||||
jit.removeIntellitypeListener(this);
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
super.exit();
|
||||
jit.cleanUp();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package mimis.device.jintellitype;
|
||||
|
||||
import mimis.input.Task;
|
||||
import mimis.state.TaskMap;
|
||||
import mimis.state.TaskMapCycle;
|
||||
import mimis.value.Action;
|
||||
import mimis.value.Key;
|
||||
import mimis.value.Target;
|
||||
|
||||
public class JIntellitypeTaskMapCycle extends TaskMapCycle {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
public TaskMap mimis, player;
|
||||
|
||||
public JIntellitypeTaskMapCycle() {
|
||||
/* Mimis */
|
||||
mimis = new TaskMap();
|
||||
mimis.add(
|
||||
new Hotkey(Key.PRIOR),
|
||||
new Task(Action.PREVIOUS, Target.MAIN));
|
||||
mimis.add(
|
||||
new Hotkey(Key.NEXT),
|
||||
new Task(Action.NEXT, Target.MAIN));
|
||||
add(mimis);
|
||||
|
||||
/* Player */
|
||||
player = new TaskMap();
|
||||
player.add(
|
||||
CommandButton.VOLUME_DOWN,
|
||||
new Task(Action.VOLUME_DOWN, Target.APPLICATIONS));
|
||||
player.add(
|
||||
CommandButton.VOLUME_UP,
|
||||
new Task(Action.VOLUME_UP, Target.APPLICATIONS));
|
||||
player.add(
|
||||
new Hotkey(Modifier.CTRL | Modifier.WIN, 'x'),
|
||||
new Task(Action.EXIT, Target.MAIN));
|
||||
player.add(
|
||||
new Hotkey(Modifier.CTRL | Modifier.SHIFT | Modifier.WIN, 'n'),
|
||||
new Task(Action.NEXT, Target.CURRENT));
|
||||
player.add(
|
||||
new Hotkey(Modifier.CTRL | Modifier.SHIFT | Modifier.WIN, 'p'),
|
||||
new Task(Action.PREVIOUS, Target.CURRENT));
|
||||
add(player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package mimis.device.jintellitype;
|
||||
|
||||
import mimis.input.Button;
|
||||
|
||||
import com.melloware.jintellitype.JIntellitype;
|
||||
|
||||
public class Modifier implements Button {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
public static final int
|
||||
ALT = JIntellitype.MOD_ALT,
|
||||
CTRL = JIntellitype.MOD_CONTROL,
|
||||
SHIFT = JIntellitype.MOD_SHIFT,
|
||||
WIN = JIntellitype.MOD_WIN;
|
||||
|
||||
protected int code;
|
||||
|
||||
protected Modifier(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
10
java/mimis/src/main/java/mimis/device/lirc/LircButton.java
Normal file
10
java/mimis/src/main/java/mimis/device/lirc/LircButton.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package mimis.device.lirc;
|
||||
|
||||
import mimis.input.Button;
|
||||
|
||||
public interface LircButton extends Button {
|
||||
public static final String NAME = null;
|
||||
|
||||
public String getCode();
|
||||
public String getName();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package mimis.device.lirc;
|
||||
|
||||
public interface LircButtonListener {
|
||||
public void add(LircButton lircButton);
|
||||
}
|
||||
108
java/mimis/src/main/java/mimis/device/lirc/LircDevice.java
Normal file
108
java/mimis/src/main/java/mimis/device/lirc/LircDevice.java
Normal file
@@ -0,0 +1,108 @@
|
||||
package mimis.device.lirc;
|
||||
|
||||
import mimis.application.cmd.CMDApplication;
|
||||
import mimis.device.Device;
|
||||
import mimis.device.lirc.remote.DenonRC176Button;
|
||||
import mimis.device.lirc.remote.PhiliphsRCLE011Button;
|
||||
import mimis.device.lirc.remote.SamsungBN5901015AButton;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.input.Button;
|
||||
import mimis.input.button.ColorButton;
|
||||
import mimis.input.button.NumberButton;
|
||||
import mimis.input.state.Press;
|
||||
import mimis.input.state.Release;
|
||||
import mimis.util.Multiplexer;
|
||||
import mimis.util.Native;
|
||||
import mimis.util.multiplexer.SignalListener;
|
||||
import mimis.value.Action;
|
||||
import mimis.value.Signal;
|
||||
|
||||
public class LircDevice extends CMDApplication implements Device, LircButtonListener, SignalListener<Button> {
|
||||
protected final static String PROGRAM = "winlirc.exe";
|
||||
protected static final String TITLE = "Lirc";
|
||||
|
||||
protected Multiplexer<Button> multiplexer;
|
||||
protected LircService lircService;
|
||||
protected LircTaskMapCycle taskMapCycle;
|
||||
|
||||
public LircDevice() {
|
||||
super(PROGRAM, TITLE);
|
||||
multiplexer = new Multiplexer<Button>(this);
|
||||
lircService = new LircService();
|
||||
lircService.put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values());
|
||||
lircService.put(DenonRC176Button.NAME, DenonRC176Button.values());
|
||||
lircService.put(SamsungBN5901015AButton.NAME, SamsungBN5901015AButton.values());
|
||||
lircService.add(this);
|
||||
taskMapCycle = new LircTaskMapCycle();
|
||||
}
|
||||
|
||||
protected void activate() throws ActivateException {
|
||||
super.activate();
|
||||
lircService.start();
|
||||
parser(Action.ADD, taskMapCycle.denonRC176);
|
||||
parser(Action.ADD, taskMapCycle.philiphsRCLE011);
|
||||
parser(Action.ADD, taskMapCycle.samsungBN5901015A);
|
||||
}
|
||||
|
||||
public boolean active() {
|
||||
if (detect) {
|
||||
if (active && !lircService.active()) {
|
||||
stop();
|
||||
} else if (!active) {
|
||||
running = Native.isRunning(PROGRAM);
|
||||
if (running) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
return active;
|
||||
}
|
||||
|
||||
protected void deactivate() throws DeactivateException {
|
||||
log.debug("Deactivate LircDevice");
|
||||
super.deactivate();
|
||||
lircService.stop();
|
||||
multiplexer.stop();
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
log.debug("Exit LircDevice");
|
||||
super.exit();
|
||||
lircService.exit();
|
||||
multiplexer.exit();
|
||||
}
|
||||
|
||||
public void add(LircButton lircButton) {
|
||||
multiplexer.add(lircButton);
|
||||
}
|
||||
|
||||
public void add(Signal signal, Button button) {
|
||||
add(signal, button, true);
|
||||
}
|
||||
|
||||
public void add(Signal signal, Button button, boolean general) {
|
||||
switch (signal) {
|
||||
case BEGIN:
|
||||
route(new Press(button));
|
||||
break;
|
||||
case END:
|
||||
route(new Release(button));
|
||||
break;
|
||||
}
|
||||
|
||||
if (general) {
|
||||
String string = button.toString();
|
||||
for (Button colorButton : ColorButton.values()) {
|
||||
if (colorButton.toString().equals(string)) {
|
||||
add(signal, ColorButton.valueOf(string), false);
|
||||
}
|
||||
}
|
||||
for (Button numberButton : NumberButton.values()) {
|
||||
if (numberButton.toString().equals(string)) {
|
||||
add(signal, NumberButton.valueOf(string), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
160
java/mimis/src/main/java/mimis/device/lirc/LircService.java
Normal file
160
java/mimis/src/main/java/mimis/device/lirc/LircService.java
Normal file
@@ -0,0 +1,160 @@
|
||||
package mimis.device.lirc;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.InputMismatchException;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Scanner;
|
||||
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.util.Native;
|
||||
import mimis.value.Registry;
|
||||
import mimis.worker.Worker;
|
||||
|
||||
public class LircService extends Worker {
|
||||
public static final String IP = "localhost";
|
||||
public static final int PORT = 8765;
|
||||
|
||||
protected ArrayList<LircButtonListener> lircButtonListenerList;
|
||||
protected String ip;
|
||||
protected int port;
|
||||
protected Socket socket;
|
||||
protected InputStream inputStream;
|
||||
protected OutputStream outputStream;
|
||||
protected BufferedReader bufferedReader;
|
||||
protected PrintWriter printWriter;
|
||||
protected HashMap<String, LircButton[]> buttonMap;
|
||||
protected String send;
|
||||
|
||||
public LircService() {
|
||||
this(IP, PORT);
|
||||
buttonMap = new HashMap<String, LircButton[]>();
|
||||
send = Native.getValue(Registry.CURRENT_USER, "Software\\LIRC", "password");
|
||||
}
|
||||
|
||||
public LircService(String ip, int port) {
|
||||
this.ip = ip;
|
||||
this.port = port;
|
||||
lircButtonListenerList = new ArrayList<LircButtonListener>();
|
||||
}
|
||||
|
||||
public void put(String name, LircButton[] LircButtonArray) {
|
||||
buttonMap.put(name, LircButtonArray);
|
||||
}
|
||||
|
||||
public void add(LircButtonListener lircButtonListener) {
|
||||
lircButtonListenerList.add(lircButtonListener);
|
||||
}
|
||||
|
||||
public void remove(LircButtonListener lircButtonListener) {
|
||||
lircButtonListenerList.remove(lircButtonListener);
|
||||
}
|
||||
|
||||
public void activate() throws ActivateException {
|
||||
log.trace("Activate LircService");
|
||||
try {
|
||||
socket = new Socket(ip, port);
|
||||
socket.setSoTimeout(SLEEP);
|
||||
|
||||
inputStream = socket.getInputStream();
|
||||
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
|
||||
outputStream = socket.getOutputStream();
|
||||
printWriter = new PrintWriter(outputStream);
|
||||
} catch (UnknownHostException e) {
|
||||
log.error(e);
|
||||
throw new ActivateException();
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
throw new ActivateException();
|
||||
}
|
||||
super.activate();
|
||||
}
|
||||
|
||||
public synchronized boolean active() {
|
||||
if (active && !socket.isConnected()) {
|
||||
active = false;
|
||||
}
|
||||
return active;
|
||||
}
|
||||
|
||||
public void deactivate() throws DeactivateException {
|
||||
log.trace("Deactivate LircService");
|
||||
super.deactivate();
|
||||
try {
|
||||
inputStream.close();
|
||||
outputStream.close();
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void work() {
|
||||
try {
|
||||
String line = bufferedReader.readLine();
|
||||
while (line.equals("BEGIN")) {
|
||||
while (!bufferedReader.readLine().equals("END"));
|
||||
line = bufferedReader.readLine();
|
||||
}
|
||||
try {
|
||||
LircButton lircButton = parseButton(new Scanner(line));
|
||||
for (LircButtonListener lircbuttonListener : lircButtonListenerList) {
|
||||
lircbuttonListener.add(lircButton);
|
||||
}
|
||||
} catch (UnknownButtonException e) {
|
||||
log.error(e);
|
||||
}
|
||||
} catch (SocketTimeoutException e) {
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public LircButton parseButton(Scanner scanner) throws UnknownButtonException {
|
||||
try {
|
||||
scanner.next();
|
||||
scanner.next();
|
||||
String code = scanner.next();
|
||||
String remote = scanner.next();
|
||||
log.trace(String.format("%s: %s", remote, code));
|
||||
LircButton[] buttonArray = buttonMap.get(remote);
|
||||
if (buttonArray != null) {
|
||||
for (LircButton button : buttonArray) {
|
||||
if (button.getCode().equals(code)) {
|
||||
return button;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (InputMismatchException e) {
|
||||
log.error(e);
|
||||
} catch (NoSuchElementException e) {
|
||||
log.error(e);
|
||||
}
|
||||
throw new UnknownButtonException();
|
||||
}
|
||||
|
||||
public void send(LircButton button) {
|
||||
send(button, 0);
|
||||
}
|
||||
|
||||
public void send(LircButton button, int repeat) {
|
||||
if (send == null) {
|
||||
return;
|
||||
}
|
||||
String command = String.format("%s %s %s \n", send, button.getName(), button.getCode());
|
||||
printWriter.append(command);
|
||||
printWriter.flush();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package mimis.device.lirc;
|
||||
|
||||
import mimis.device.lirc.remote.DenonRC176EventMap;
|
||||
import mimis.device.lirc.remote.PhiliphsRCLE011EventMap;
|
||||
import mimis.device.lirc.remote.SamsungBN5901015AEventMap;
|
||||
import mimis.state.TaskMap;
|
||||
import mimis.state.TaskMapCycle;
|
||||
|
||||
public class LircTaskMapCycle extends TaskMapCycle {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
public TaskMap denonRC176, philiphsRCLE011, samsungBN5901015A;
|
||||
|
||||
public LircTaskMapCycle() {
|
||||
add(denonRC176 = new DenonRC176EventMap());
|
||||
add(philiphsRCLE011 = new PhiliphsRCLE011EventMap());
|
||||
add(samsungBN5901015A = new SamsungBN5901015AEventMap());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package mimis.device.lirc.remote;
|
||||
|
||||
import mimis.device.lirc.LircButton;
|
||||
|
||||
public enum DenonRC176Button implements LircButton {
|
||||
TAPE_AB ("TAPE_AB"),
|
||||
TAPE_REC ("TAPE_REC"),
|
||||
TAPE_PAUSE ("TAPE_PAUSE"),
|
||||
TAPE_STOP ("TAPE_STOP"),
|
||||
TAPE_REWIND ("TAPE_REW"),
|
||||
TAPE_FORWARD ("TAPE_FF"),
|
||||
TAPE_PREIVOUS ("TAPE_PLAYREV"),
|
||||
TAPE_NEXT ("TAPE_PLAY"),
|
||||
CD_PREVIOUS ("CD_TRACK_-"),
|
||||
CD_NEXT ("CD_TRACK_+"),
|
||||
CD_SHUFFLE ("CD_RANDOM"),
|
||||
CD_REPEAT ("CD_REPEAT"),
|
||||
CD_SKIP ("CD_SKIP"),
|
||||
CD_PAUSE ("CD_PAUSE"),
|
||||
CD_STOP ("CD_STOP"),
|
||||
CD_PLAY ("CD_PLAY"),
|
||||
AMP_TAPE2 ("AMP_TAPE2"),
|
||||
AMP_TAPE1 ("AMP_TAPE1"),
|
||||
AMP_AUX ("AMP_AUX"),
|
||||
AMP_TUNER ("AMP_TUNER"),
|
||||
AMP_CD ("AMP_CD"),
|
||||
AMP_PHONO ("AMP_PHONO"),
|
||||
AMP_VOLUME_UP ("AMP_VOL_UP"),
|
||||
AMP_VOLUME_DOWN ("AMP_VOL_DOWN"),
|
||||
AMP_POWER ("AMP_POWER"),
|
||||
AMP_MUTE ("AMP_MUTE"),
|
||||
TUNER_UP ("TUN_CH_UP"),
|
||||
TUNER_DOWN ("TUN_CH_DOWN");
|
||||
|
||||
public static final String NAME = "DENON_RC-176";
|
||||
|
||||
protected String code;
|
||||
|
||||
private DenonRC176Button(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package mimis.device.lirc.remote;
|
||||
|
||||
import mimis.input.Task;
|
||||
import mimis.state.TaskMap;
|
||||
import mimis.value.Action;
|
||||
import mimis.value.Target;
|
||||
|
||||
public class DenonRC176EventMap extends TaskMap {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
public DenonRC176EventMap() {
|
||||
/* Mimis */
|
||||
add(DenonRC176Button.TUNER_UP, new Task(Action.NEXT, Target.MAIN));
|
||||
add(DenonRC176Button.TUNER_DOWN, new Task(Action.PREVIOUS, Target.MAIN));
|
||||
|
||||
/* Application */
|
||||
add(DenonRC176Button.AMP_POWER, new Task(Action.START, Target.CURRENT));
|
||||
add(DenonRC176Button.CD_NEXT, new Task(Action.NEXT, Target.CURRENT));
|
||||
add(DenonRC176Button.CD_PREVIOUS, new Task(Action.PREVIOUS, Target.CURRENT));
|
||||
add(DenonRC176Button.TAPE_REWIND, new Task(Action.REWIND, Target.CURRENT));
|
||||
add(DenonRC176Button.CD_PLAY, new Task(Action.PLAY, Target.CURRENT));
|
||||
add(DenonRC176Button.CD_PAUSE, new Task(Action.PLAY, Target.CURRENT));
|
||||
add(DenonRC176Button.TAPE_FORWARD, new Task(Action.FORWARD, Target.CURRENT));
|
||||
add(DenonRC176Button.AMP_MUTE, new Task(Action.MUTE, Target.CURRENT));
|
||||
add(DenonRC176Button.AMP_VOLUME_UP, new Task(Action.VOLUME_UP, Target.CURRENT));
|
||||
add(DenonRC176Button.AMP_VOLUME_DOWN, new Task(Action.VOLUME_DOWN, Target.CURRENT));
|
||||
add(DenonRC176Button.CD_REPEAT, new Task(Action.REPEAT, Target.CURRENT));
|
||||
add(DenonRC176Button.CD_SHUFFLE, new Task(Action.SHUFFLE, Target.CURRENT));
|
||||
add(DenonRC176Button.TAPE_AB, new Task(Action.LIKE, Target.CURRENT));
|
||||
add(DenonRC176Button.TAPE_REC, new Task(Action.DISLIKE, Target.CURRENT));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package mimis.device.lirc.remote;
|
||||
|
||||
import mimis.device.lirc.LircButton;
|
||||
|
||||
public enum PhiliphsRCLE011Button implements LircButton {
|
||||
POWER ("Standby"),
|
||||
RED ("Red"),
|
||||
GREEN ("Green"),
|
||||
YELLOW ("Yellow"),
|
||||
BLUE ("Blue"),
|
||||
TUNE ("Tune"),
|
||||
RADIO ("Radio"),
|
||||
SQUARE ("Square"),
|
||||
MENU ("Menu"),
|
||||
TEXT ("Text"),
|
||||
UP ("Up"),
|
||||
DOWN ("Down"),
|
||||
LEFT ("Left"),
|
||||
RIGHT ("Right"),
|
||||
VOLUME_UP ("Volume+"),
|
||||
VOLUME_DOWN ("Volume-"),
|
||||
MUTE ("Mute"),
|
||||
PROGRAM_UP ("Program+"),
|
||||
PROGRAM_DOWN ("Program-"),
|
||||
ONE ("1"),
|
||||
TWO ("2"),
|
||||
THREE ("3"),
|
||||
FOUR ("4"),
|
||||
FIVE ("5"),
|
||||
SIX ("6"),
|
||||
SEVEN ("7"),
|
||||
EIGHT ("8"),
|
||||
NINE ("9"),
|
||||
ZERO ("0"),
|
||||
CLOCK ("Clock"),
|
||||
OUT ("Out"),
|
||||
INFO ("i+"),
|
||||
SCREEN_UP ("screenup"),
|
||||
SCREEN_DOWN ("screendown"),
|
||||
QUESTION ("question");
|
||||
|
||||
public static final String NAME = "Philips_RCLE011";
|
||||
|
||||
protected String code;
|
||||
|
||||
private PhiliphsRCLE011Button(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package mimis.device.lirc.remote;
|
||||
|
||||
import mimis.input.Task;
|
||||
import mimis.state.TaskMap;
|
||||
import mimis.value.Action;
|
||||
import mimis.value.Target;
|
||||
|
||||
public class PhiliphsRCLE011EventMap extends TaskMap {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
public PhiliphsRCLE011EventMap() {
|
||||
/* Mimis */
|
||||
add(PhiliphsRCLE011Button.UP, new Task(Action.NEXT, Target.MAIN));
|
||||
add(PhiliphsRCLE011Button.DOWN, new Task(Action.PREVIOUS, Target.MAIN));
|
||||
|
||||
/* Application */
|
||||
add(PhiliphsRCLE011Button.POWER, new Task(Action.START, Target.CURRENT));
|
||||
add(PhiliphsRCLE011Button.PROGRAM_UP, new Task(Action.NEXT, Target.CURRENT));
|
||||
add(PhiliphsRCLE011Button.PROGRAM_DOWN, new Task(Action.PREVIOUS, Target.CURRENT));
|
||||
add(PhiliphsRCLE011Button.LEFT, new Task(Action.REWIND, Target.CURRENT));
|
||||
add(PhiliphsRCLE011Button.TUNE, new Task(Action.PLAY, Target.CURRENT));
|
||||
add(PhiliphsRCLE011Button.RIGHT, new Task(Action.FORWARD, Target.CURRENT));
|
||||
add(PhiliphsRCLE011Button.VOLUME_DOWN, new Task(Action.VOLUME_DOWN, Target.CURRENT));
|
||||
add(PhiliphsRCLE011Button.MUTE, new Task(Action.MUTE, Target.CURRENT));
|
||||
add(PhiliphsRCLE011Button.VOLUME_UP, new Task(Action.VOLUME_UP, Target.CURRENT));
|
||||
add(PhiliphsRCLE011Button.CLOCK, new Task(Action.REPEAT, Target.CURRENT));
|
||||
add(PhiliphsRCLE011Button.OUT, new Task(Action.SHUFFLE, Target.CURRENT));
|
||||
add(PhiliphsRCLE011Button.SQUARE, new Task(Action.FULLSCREEN, Target.CURRENT));
|
||||
add(PhiliphsRCLE011Button.RED, new Task(Action.DISLIKE, Target.CURRENT));
|
||||
add(PhiliphsRCLE011Button.GREEN, new Task(Action.LIKE, Target.CURRENT));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package mimis.device.lirc.remote;
|
||||
|
||||
import mimis.device.lirc.LircButton;
|
||||
|
||||
public enum SamsungBN5901015AButton implements LircButton {
|
||||
POWER ("Power"),
|
||||
SOURCE ("Source"),
|
||||
ONE ("1"),
|
||||
TWO ("2"),
|
||||
THREE ("3"),
|
||||
FOUR ("4"),
|
||||
FIVE ("5"),
|
||||
SIX ("6"),
|
||||
SEVEN ("7"),
|
||||
EIGHT ("8"),
|
||||
NINE ("9"),
|
||||
ZERO ("0"),
|
||||
TEXT ("TTX/Mix"),
|
||||
CHANNEL_TOGGLE ("Pre-Ch"),
|
||||
VOLUME_DOWN ("Vol+"),
|
||||
VOLUME_UP ("Vol-"),
|
||||
MUTE ("Mute"),
|
||||
CHANNEL_LIST ("Ch.List"),
|
||||
CHANNEL_NEXT ("Ch+"),
|
||||
CHANNEL_PREVIOUS ("Ch-"),
|
||||
MEDIA ("Media.P"),
|
||||
MENU ("Menu"),
|
||||
GUIDE ("Guide"),
|
||||
TOOLS ("Tools"),
|
||||
UP ("Up"),
|
||||
INFO ("Info"),
|
||||
RETURN ("Return"),
|
||||
EXIT ("Exit"),
|
||||
LEFT ("Left"),
|
||||
ENTER ("Enter"),
|
||||
RIGHT ("Right"),
|
||||
DOWN ("Down"),
|
||||
RED ("Red"),
|
||||
GREEN ("Green"),
|
||||
YELLOW ("Yellow"),
|
||||
BLUE ("Blue"),
|
||||
MODE_P ("P.Mode"),
|
||||
MODE_S ("S.Mode"),
|
||||
SIZE_P ("P.Size"),
|
||||
Dual ("Dual"),
|
||||
AUDIO ("AD"),
|
||||
SUBTITLE ("Subt."),
|
||||
REWIND ("Rewind"),
|
||||
PAUSE ("Pause"),
|
||||
FORWARD ("Forward"),
|
||||
RECORD ("Record"),
|
||||
PLAY ("Play"),
|
||||
STOP ("Stop");
|
||||
|
||||
public static final String NAME = "Samsung_BN59-01015A";
|
||||
|
||||
protected String code;
|
||||
|
||||
private SamsungBN5901015AButton(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package mimis.device.lirc.remote;
|
||||
|
||||
import mimis.input.Task;
|
||||
import mimis.state.TaskMap;
|
||||
import mimis.value.Action;
|
||||
import mimis.value.Target;
|
||||
|
||||
public class SamsungBN5901015AEventMap extends TaskMap {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
public SamsungBN5901015AEventMap() {
|
||||
add(SamsungBN5901015AButton.VOLUME_UP, new Task(Action.VOLUME_UP, Target.CURRENT));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package mimis.device.lirc.remote;
|
||||
|
||||
import mimis.device.lirc.LircButton;
|
||||
|
||||
public enum WC02IPOButton implements LircButton {
|
||||
MINUS ("MINUS"),
|
||||
PLUS ("PLUS"),
|
||||
NEXT ("NEXT"),
|
||||
PREVIOUS ("PREVIOUS"),
|
||||
PLAY ("PLAY"),
|
||||
HOLD ("HOLD");
|
||||
|
||||
public static final String NAME = "WC02-IPO";
|
||||
|
||||
protected String code;
|
||||
|
||||
private WC02IPOButton(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
}
|
||||
189
java/mimis/src/main/java/mimis/device/network/NetworkDevice.java
Normal file
189
java/mimis/src/main/java/mimis/device/network/NetworkDevice.java
Normal file
@@ -0,0 +1,189 @@
|
||||
package mimis.device.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import mimis.device.Device;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.input.Feedback;
|
||||
import mimis.input.Input;
|
||||
import mimis.input.Task;
|
||||
import mimis.value.Action;
|
||||
import mimis.value.Target;
|
||||
import mimis.worker.Component;
|
||||
import mimis.worker.Worker;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class NetworkDevice extends Component implements Device {
|
||||
protected static final String TITLE = "Network";
|
||||
public static final int PORT = 6789;
|
||||
|
||||
protected Log log = LogFactory.getLog(NetworkDevice.class);
|
||||
protected Server server;
|
||||
protected ConcurrentLinkedQueue<Client> clientList;
|
||||
|
||||
public NetworkDevice(int port) {
|
||||
super(TITLE);
|
||||
clientList = new ConcurrentLinkedQueue<Client>();
|
||||
server = new Server(port);
|
||||
}
|
||||
|
||||
public NetworkDevice() {
|
||||
this(PORT);
|
||||
}
|
||||
|
||||
protected void activate() throws ActivateException {
|
||||
server.start();
|
||||
super.activate();
|
||||
}
|
||||
|
||||
public boolean active() {
|
||||
for (Client client : clientList) {
|
||||
if (!client.active()) {
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
return active = server.active();
|
||||
}
|
||||
|
||||
protected void deactivate() throws DeactivateException {
|
||||
super.deactivate();
|
||||
server.stop();
|
||||
}
|
||||
|
||||
public synchronized void exit() {
|
||||
super.exit();
|
||||
server.exit();
|
||||
}
|
||||
|
||||
protected void feedback(Feedback feedback) {
|
||||
for (Client client : clientList) {
|
||||
client.send(feedback);
|
||||
}
|
||||
}
|
||||
|
||||
protected class Server extends Worker {
|
||||
protected ServerSocket serverSocket;
|
||||
protected int port;
|
||||
|
||||
public Server(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
protected void activate() throws ActivateException {
|
||||
try {
|
||||
serverSocket = new ServerSocket(port);
|
||||
} catch (IOException e) {
|
||||
throw new ActivateException();
|
||||
}
|
||||
super.activate();
|
||||
}
|
||||
|
||||
public synchronized boolean active() {
|
||||
return active = serverSocket != null && !serverSocket.isClosed();
|
||||
}
|
||||
|
||||
protected synchronized void deactivate() throws DeactivateException {
|
||||
super.deactivate();
|
||||
try {
|
||||
route(new Feedback("[NetworkDevice] Closing server socket"));
|
||||
serverSocket.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
} finally {
|
||||
for (Client client : clientList) {
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void work() {
|
||||
try {
|
||||
route(new Feedback("[NetworkDevice] Wating for clients"));
|
||||
Socket socket = serverSocket.accept();
|
||||
Client client = new Client(socket);
|
||||
client.start();
|
||||
route(new Feedback("[NetworkDevice] Client connected: " + socket.getInetAddress()));
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void exit() {
|
||||
super.exit();
|
||||
for (Client client : clientList) {
|
||||
client.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class Client extends Worker {
|
||||
protected Socket socket;
|
||||
protected InputStream inputStream;
|
||||
protected OutputStream outputStream;
|
||||
protected ObjectOutputStream objectOutputStream;
|
||||
|
||||
public Client(Socket socket) throws IOException {
|
||||
this.socket = socket;
|
||||
inputStream = socket.getInputStream();
|
||||
outputStream = socket.getOutputStream();
|
||||
objectOutputStream = new ObjectOutputStream(outputStream);
|
||||
clientList.add(this);
|
||||
}
|
||||
|
||||
public boolean active() {
|
||||
return active = socket.isConnected();
|
||||
}
|
||||
|
||||
public void work() {
|
||||
ObjectInputStream objectInputStream;
|
||||
try {
|
||||
objectInputStream = new ObjectInputStream(inputStream);
|
||||
Object object;
|
||||
do {
|
||||
object = objectInputStream.readObject();
|
||||
if (object instanceof Input) {
|
||||
log.trace(object);
|
||||
route((Input) object);
|
||||
}
|
||||
} while (object != null);
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
stop();
|
||||
} catch (ClassNotFoundException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void deactivate() throws DeactivateException {
|
||||
super.deactivate();
|
||||
send(new Task(Action.STOP, Target.SELF));
|
||||
clientList.remove(this);
|
||||
try {
|
||||
inputStream.close();
|
||||
outputStream.close();
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
}
|
||||
route(new Feedback("[NetworkDevice] Client disconnected: " + socket.getInetAddress()));
|
||||
}
|
||||
|
||||
public void send(Object object) {
|
||||
try {
|
||||
objectOutputStream.writeObject(object);
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
180
java/mimis/src/main/java/mimis/device/panel/Panel.java
Normal file
180
java/mimis/src/main/java/mimis/device/panel/Panel.java
Normal file
@@ -0,0 +1,180 @@
|
||||
package mimis.device.panel;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
import mimis.Gui;
|
||||
import mimis.util.Swing;
|
||||
import mimis.util.swing.HoldButton;
|
||||
import mimis.util.swing.HoldButtonListener;
|
||||
import mimis.util.swing.ToggleButton;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class Panel extends JFrame implements HoldButtonListener {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
protected final static String TITLE = "MIMIS Panel Device";
|
||||
|
||||
protected PanelDevice panelDevice;
|
||||
|
||||
protected HoldButton upButton;
|
||||
protected HoldButton previousButton;
|
||||
protected HoldButton rewindButton;
|
||||
protected HoldButton stopButton;
|
||||
protected ToggleButton playPauseToggleButton;
|
||||
protected HoldButton forwardButton;
|
||||
protected HoldButton downButton;
|
||||
protected HoldButton nextButton;
|
||||
protected HoldButton volumeDownButton;
|
||||
protected ToggleButton muteToggleButton;
|
||||
protected HoldButton volumeUpButton;
|
||||
protected HoldButton repeatButton;
|
||||
protected HoldButton shuffleButton;
|
||||
|
||||
Panel(PanelDevice panelDevice) {
|
||||
super(TITLE);
|
||||
this.panelDevice = panelDevice;
|
||||
setIconImage(Swing.getImage(Gui.ICON));
|
||||
createControls();
|
||||
layoutControls();
|
||||
pack();
|
||||
setResizable(false);
|
||||
setVisible(true);
|
||||
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||
}
|
||||
|
||||
protected HoldButton getButton(String name, String text) {
|
||||
HoldButton button = new HoldButton(this);
|
||||
button.setIcon(Swing.getImageIcon(name));
|
||||
button.setToolTipText(text);
|
||||
button.setFocusPainted(false);
|
||||
return button;
|
||||
}
|
||||
|
||||
protected ToggleButton getToggleButton(String firstName, String secondName, String text) {
|
||||
ImageIcon firstImageIcon = Swing.getImageIcon(firstName);
|
||||
ImageIcon secondImageIcon = Swing.getImageIcon(secondName);
|
||||
ToggleButton button = new ToggleButton(this, firstImageIcon, secondImageIcon);
|
||||
button.setToolTipText(text);
|
||||
button.setFocusPainted(false);
|
||||
return button;
|
||||
}
|
||||
|
||||
protected void createControls() {
|
||||
upButton = getButton("icons/up.png", "Go to previous application");
|
||||
nextButton = getButton("icons/next.png", "Go to next track");
|
||||
previousButton = getButton("icons/previous.png", "Go to previous track");
|
||||
rewindButton = getButton("icons/rewind.png", "Skip backward");
|
||||
playPauseToggleButton = getToggleButton("icons/play.png", "icons/pause.png", "Play/pause");
|
||||
forwardButton = getButton("icons/forward.png", "Skip forward");
|
||||
downButton = getButton("icons/down.png", "Go to next application");
|
||||
volumeDownButton = getButton("icons/volumeDown.png", "Decrease volume");
|
||||
muteToggleButton = getToggleButton("icons/mute.png", "icons/unmute.png", "Toggle Mute");
|
||||
volumeUpButton = getButton("icons/volumeUp.png", "Increase volume");
|
||||
repeatButton = getButton("icons/repeat.png", "Repeat");
|
||||
shuffleButton = getButton("icons/shuffle.png", "Shuffle");
|
||||
}
|
||||
|
||||
protected void layoutControls() {
|
||||
setLayout(new BorderLayout());
|
||||
layoutControlPanel();
|
||||
}
|
||||
|
||||
protected void layoutControlPanel() {
|
||||
JPanel controlPanel = new JPanel();
|
||||
controlPanel.setLayout(new BorderLayout());
|
||||
|
||||
JPanel upperControlPanel = new JPanel();
|
||||
controlPanel.add(upperControlPanel, BorderLayout.NORTH);
|
||||
upperControlPanel.add(upButton);
|
||||
upperControlPanel.add(previousButton);
|
||||
upperControlPanel.add(rewindButton);
|
||||
upperControlPanel.add(playPauseToggleButton);
|
||||
upperControlPanel.add(forwardButton);
|
||||
upperControlPanel.add(nextButton);
|
||||
|
||||
JPanel lowerControlPanel = new JPanel();
|
||||
controlPanel.add(lowerControlPanel, BorderLayout.SOUTH);
|
||||
lowerControlPanel.add(downButton);
|
||||
lowerControlPanel.add(repeatButton);
|
||||
lowerControlPanel.add(volumeDownButton);
|
||||
lowerControlPanel.add(muteToggleButton);
|
||||
lowerControlPanel.add(volumeUpButton);
|
||||
lowerControlPanel.add(shuffleButton);
|
||||
|
||||
add(controlPanel, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
/* Listeners */
|
||||
public void buttonPressed(HoldButton button) {
|
||||
if (button.equals(previousButton)) {
|
||||
panelDevice.buttonPressed(PanelButton.PREVIOUS);
|
||||
} else if (button.equals(rewindButton)) {
|
||||
panelDevice.buttonPressed(PanelButton.REWIND);
|
||||
} else if (button.equals(playPauseToggleButton)) {
|
||||
panelDevice.buttonPressed(PanelButton.PLAY);
|
||||
} else if (button.equals(forwardButton)) {
|
||||
panelDevice.buttonPressed(PanelButton.FORWARD);
|
||||
} else if (button.equals(nextButton)) {
|
||||
panelDevice.buttonPressed(PanelButton.NEXT);
|
||||
} else if (button.equals(volumeDownButton)) {
|
||||
panelDevice.buttonPressed(PanelButton.VOLUME_DOWN);
|
||||
} else if (button.equals(muteToggleButton)) {
|
||||
panelDevice.buttonPressed(PanelButton.MUTE);
|
||||
} else if (button.equals(volumeUpButton)) {
|
||||
panelDevice.buttonPressed(PanelButton.VOLUME_UP);
|
||||
} else if (button.equals(repeatButton)) {
|
||||
panelDevice.buttonPressed(PanelButton.REPEAT);
|
||||
} else if (button.equals(shuffleButton)) {
|
||||
panelDevice.buttonPressed(PanelButton.SHUFFLE);
|
||||
} else if (button.equals(upButton)) {
|
||||
panelDevice.buttonPressed(PanelButton.UP);
|
||||
} else if (button.equals(downButton)) {
|
||||
panelDevice.buttonPressed(PanelButton.DOWN);
|
||||
}
|
||||
}
|
||||
|
||||
public void buttonReleased(HoldButton button) {
|
||||
if (button.equals(previousButton)) {
|
||||
panelDevice.buttonReleased(PanelButton.PREVIOUS);
|
||||
} else if (button.equals(rewindButton)) {
|
||||
panelDevice.buttonReleased(PanelButton.REWIND);
|
||||
} else if (button.equals(playPauseToggleButton)) {
|
||||
panelDevice.buttonReleased(PanelButton.PLAY);
|
||||
playPauseToggleButton.toggle();
|
||||
} else if (button.equals(forwardButton)) {
|
||||
panelDevice.buttonReleased(PanelButton.FORWARD);
|
||||
} else if (button.equals(nextButton)) {
|
||||
panelDevice.buttonReleased(PanelButton.NEXT);
|
||||
} else if (button.equals(volumeDownButton)) {
|
||||
panelDevice.buttonReleased(PanelButton.VOLUME_DOWN);
|
||||
} else if (button.equals(muteToggleButton)) {
|
||||
panelDevice.buttonReleased(PanelButton.MUTE);
|
||||
muteToggleButton.toggle();
|
||||
} else if (button.equals(volumeUpButton)) {
|
||||
panelDevice.buttonReleased(PanelButton.VOLUME_UP);
|
||||
} else if (button.equals(repeatButton)) {
|
||||
panelDevice.buttonReleased(PanelButton.REPEAT);
|
||||
} else if (button.equals(shuffleButton)) {
|
||||
panelDevice.buttonReleased(PanelButton.SHUFFLE);
|
||||
} else if (button.equals(upButton)) {
|
||||
panelDevice.buttonReleased(PanelButton.UP);
|
||||
} else if (button.equals(downButton)) {
|
||||
panelDevice.buttonReleased(PanelButton.DOWN);
|
||||
}
|
||||
}
|
||||
|
||||
protected void processWindowEvent(WindowEvent event) {
|
||||
if (event.getID() == WindowEvent.WINDOW_CLOSING) {
|
||||
log.debug("Window closing");
|
||||
panelDevice.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user