Package paletai.mapping
Class MediaItem
java.lang.Object
paletai.mapping.MediaItem
- Direct Known Subclasses:
GenerativeMediaItem
A class for managing media items (images/videos) with homography
transformation capabilities. Handles loading, playback, and rendering of
media files with perspective correction.
Key features include:
- Automatic aspect ratio correction
- Video playback control
- Thumbnail generation
- Homography transformation via
VidMap - Media file management
- Generative content support
- UI controls for calibration and playback
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionintAssigned screen index and media identifierbooleanCalibration mode statusBase filename with scene indexContent generator for generative mediaintOriginal media dimensionsintAssigned screen index and media identifierintOriginal media dimensionsprocessing.core.PImageThumbnail representationfloatThumbnail display positionfloatThumbnail display positionHomography transformation handler -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new MediaItem from a file path.MediaItem(processing.core.PApplet p, LunaContentGenerator generator, int screenIndex, int mediaId) Constructs a generative MediaItem from a content generator.MediaItem(processing.core.PApplet p, LunaContentGenerator generator, processing.data.XML mediaXML) Constructs a generative MediaItem from XML configuration.MediaItem(processing.core.PApplet p, processing.data.XML mediaXML) Constructs a MediaItem from XML configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyAspectRatioCorrection(int mediaWidth, int mediaHeight) Adjusts media display to maintain aspect ratio.voidassignToDisplay(int w, int h, int screenIndex) Assigns this media item to a display with specific dimensions.voidcheckHover(float x, float y) Checks hover state for homography points at specified coordinates.voidGenerates a thumbnail image for this media item.Returns the filename of the media.Returns the full file path of the media.processing.opengl.PGraphics2DReturns the transformed media canvas with homography applied.processing.core.PImageReturns the thumbnail image for this media item.voidHides the media item's control group.booleanisLoaded()Checks if media is successfully loaded and ready for display.booleanisVideo()Checks if this media item is a video file.voidStarts media playback in loop mode.voidHandles mouse release events for homography point interaction.voidmoveHoverPoint(float x, float y) Moves the hover point to specified coordinates.voidMutes video audio playback.voidTurns off calibration mode for this media item.voidTurns on calibration mode for this media item.voidStarts media playback.voidrender()Renders the media with homography transformation.voidResets the homography transformation to default state.voidsetPreviewArea(float px, float py, float pw, float ph) Sets the preview area dimensions for homography point display.voidsetThumbnailPosition(int x, int y) Sets the thumbnail position and updates control group placement.voidShows the media item's control group.voidStops media playback and cleans up resources.voidToggles calibration mode for this media item.voidToggles input checking for homography points.voidToggles video loop mode.voidToggles video playback state.voidupdateHomography(processing.core.PVector[] xyNew, processing.core.PVector[] uvNew) Updates the homography transformation with new coordinate points.
-
Field Details
-
fileName
Base filename with scene index -
thumbnail
public processing.core.PImage thumbnailThumbnail representation -
thumbnailX
public float thumbnailXThumbnail display position -
thumbnailY
public float thumbnailYThumbnail display position -
vm
Homography transformation handler -
mediaWidth
public int mediaWidthOriginal media dimensions -
mediaHeight
public int mediaHeightOriginal media dimensions -
assignedScreen
public int assignedScreenAssigned screen index and media identifier -
mediaId
public int mediaIdAssigned screen index and media identifier -
calibrate
public boolean calibrateCalibration mode status -
generator
Content generator for generative media
-
-
Constructor Details
-
MediaItem
Constructs a new MediaItem from a file path.- Parameters:
p- The parent PApplet instancefilePath- Path to media filescreenIndex- The screen index this media is assigned tomediaId- Unique identifier for this media item- Throws:
RuntimeException- If media file cannot be loaded
-
MediaItem
public MediaItem(processing.core.PApplet p, processing.data.XML mediaXML) Constructs a MediaItem from XML configuration. Recreates a media item from saved project data.- Parameters:
p- The parent PApplet instancemediaXML- XML element containing media configuration
-
MediaItem
public MediaItem(processing.core.PApplet p, LunaContentGenerator generator, int screenIndex, int mediaId) Constructs a generative MediaItem from a content generator.- Parameters:
p- The parent PApplet instancegenerator- The content generator to usescreenIndex- The screen index this media is assigned tomediaId- Unique identifier for this media item
-
MediaItem
public MediaItem(processing.core.PApplet p, LunaContentGenerator generator, processing.data.XML mediaXML) Constructs a generative MediaItem from XML configuration. Recreates a generative media item from saved project data.- Parameters:
p- The parent PApplet instancegenerator- The content generator to usemediaXML- XML element containing media configuration
-
-
Method Details
-
showControls
public void showControls()Shows the media item's control group. Makes the calibration and playback controls visible. -
hideControls
public void hideControls()Hides the media item's control group. Removes the calibration and playback controls from display. -
setThumbnailPosition
public void setThumbnailPosition(int x, int y) Sets the thumbnail position and updates control group placement. Positions the thumbnail and aligns the control group above it.- Parameters:
x- The x-coordinate for thumbnail placementy- The y-coordinate for thumbnail placement
-
assignToDisplay
public void assignToDisplay(int w, int h, int screenIndex) Assigns this media item to a display with specific dimensions. Creates the media canvas, sets resolution, and configures the homography transformation for the target display. For generative content, calls the generator's setup method.- Parameters:
w- The width of the target displayh- The height of the target displayscreenIndex- The index of the screen to assign to- See Also:
-
isLoaded
public boolean isLoaded()Checks if media is successfully loaded and ready for display.- Returns:
- true if media is ready for display, false otherwise
-
applyAspectRatioCorrection
public void applyAspectRatioCorrection(int mediaWidth, int mediaHeight) Adjusts media display to maintain aspect ratio. Automatically updates homography points to fit media properly within the display canvas while preserving the original aspect ratio.- Parameters:
mediaWidth- Original media widthmediaHeight- Original media height- See Also:
-
updateHomography
public void updateHomography(processing.core.PVector[] xyNew, processing.core.PVector[] uvNew) Updates the homography transformation with new coordinate points. Wrapper method for VidMap's updateHomography functionality.- Parameters:
xyNew- New destination points for transformationuvNew- New source points for transformation- See Also:
-
toggleCalibration
public void toggleCalibration()Toggles calibration mode for this media item. Wrapper method for VidMap's toggleCalibration functionality.- See Also:
-
offCalibration
public void offCalibration()Turns off calibration mode for this media item. Wrapper method for VidMap's offCalibration functionality.- See Also:
-
onCalibration
public void onCalibration()Turns on calibration mode for this media item. Wrapper method for VidMap's onCalibration functionality.- See Also:
-
toggleInput
public void toggleInput()Toggles input checking for homography points. Enables or disables mouse interaction with transformation points.- See Also:
-
checkHover
public void checkHover(float x, float y) Checks hover state for homography points at specified coordinates. Wrapper method for VidMap's checkHover functionality.- Parameters:
x- The x-coordinate to checky- The y-coordinate to check- See Also:
-
moveHoverPoint
public void moveHoverPoint(float x, float y) Moves the hover point to specified coordinates. Wrapper method for VidMap's moveHoverPoint functionality.- Parameters:
x- The target x-coordinatey- The target y-coordinate- See Also:
-
mouseReleased
public void mouseReleased()Handles mouse release events for homography point interaction. Wrapper method for VidMap's mouseReleased functionality.- See Also:
-
resetHomography
public void resetHomography()Resets the homography transformation to default state. Clears custom transformation points and reapplies aspect ratio correction.- See Also:
-
generateThumbnail
public void generateThumbnail()Generates a thumbnail image for this media item. For generative content: captures the current generator output. For images: creates a resized copy of the original image. For videos: captures the first available frame and resizes it. Sets thumbnailGenerated flag to true when complete.- See Also:
-
setPreviewArea
public void setPreviewArea(float px, float py, float pw, float ph) Sets the preview area dimensions for homography point display. Wrapper method for VidMap's setPreviewArea functionality.- Parameters:
px- Preview area x-coordinatepy- Preview area y-coordinatepw- Preview area widthph- Preview area height- See Also:
-
render
public void render()Renders the media with homography transformation. Handles static images, video playback, and generative content. For videos: reads new frames and manages thumbnail generation. For generative content: updates and draws the generator output. Applies homography transformation to the final output.- See Also:
-
togglePlayback
public void togglePlayback()Toggles video playback state. Plays if paused, pauses if playing. No effect on static images or generative content. -
toggleLoop
public void toggleLoop()Toggles video loop mode. Switches between single playback and continuous looping for video content. -
playMedia
public void playMedia()Starts media playback. For videos: begins playback from the start in single-play mode. Stops any existing playback before starting new playback. No effect on static images or generative content. -
loopMedia
public void loopMedia()Starts media playback in loop mode. For videos: begins continuous looping playback. Stops any existing playback before starting new looped playback. No effect on static images or generative content. -
stopMedia
public void stopMedia()Stops media playback and cleans up resources. For videos: stops playback, disposes native resources, and clears the display. Crucial for GStreamer cleanup to release native pipeline resources. No effect on static images or generative content. -
muteMedia
public void muteMedia()Mutes video audio playback. Sets video volume to zero if the video is not currently playing. No effect on static images or generative content. -
getFilePath
Returns the full file path of the media.- Returns:
- The complete file path, or null for generative content
-
getFileName
Returns the filename of the media.- Returns:
- The filename without path, or generator name for generative content
-
getThumbnail
public processing.core.PImage getThumbnail()Returns the thumbnail image for this media item.- Returns:
- The thumbnail PImage, or null if not generated
- See Also:
-
isVideo
public boolean isVideo()Checks if this media item is a video file.- Returns:
- true if this is a video media item
-
getMediaCanvas
public processing.opengl.PGraphics2D getMediaCanvas()Returns the transformed media canvas with homography applied. Wrapper method for VidMap's getMediaCanvas functionality.- Returns:
- PGraphics2D containing the transformed media output
- See Also:
-