<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package net.sf.jaer.util.avioutput;

import com.jogamp.common.nio.Buffers;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import java.awt.Desktop;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Date;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
import net.sf.jaer.Description;
import net.sf.jaer.DevelopmentStatus;
import net.sf.jaer.chip.AEChip;
import net.sf.jaer.event.EventPacket;
import net.sf.jaer.eventio.AEInputStream;
import static net.sf.jaer.eventprocessing.EventFilter.log;
import net.sf.jaer.eventprocessing.EventFilter2D;
import net.sf.jaer.graphics.FrameAnnotater;

/**
 * Base class for EventFilters that write out AVI files from jAER
 *
 * @author Tobi
 */
@Description("Base class for EventFilters that write out AVI files from jAER")
@DevelopmentStatus(DevelopmentStatus.Status.Stable)
public class AbstractAviWriter extends EventFilter2D implements FrameAnnotater, PropertyChangeListener {

    protected AVIOutputStream aviOutputStream = null;
    protected static String DEFAULT_FILENAME = "jAER.avi";
    protected String lastFileName = getString("lastFileName", DEFAULT_FILENAME);
    protected int framesWritten = 0;
    protected final int logEveryThisManyFrames = 30;
    protected boolean writeTimecodeFile = getBoolean("writeTimecodeFile", true);
    protected static final String TIMECODE_SUFFIX = "-timecode.txt";
    protected File timecodeFile = null;
    protected FileWriter timecodeWriter = null;
    protected boolean closeOnRewind = getBoolean("closeOnRewind", true);
    protected boolean propertyChangeListenerAdded = false;
    protected AVIOutputStream.VideoFormat format = AVIOutputStream.VideoFormat.valueOf(getString("format", AVIOutputStream.VideoFormat.RAW.toString()));
    protected int maxFrames = getInt("maxFrames", 0);
    protected float compressionQuality = getFloat("compressionQuality", 0.9f);
    private String[] additionalComments=null;

    public AbstractAviWriter(AEChip chip) {
        super(chip);
        setPropertyTooltip("saveAVIFileAs", "Opens the output file. The AVI file is in RAW format with pixel values 0-255 coming from ApsFrameExtractor displayed frames, which are offset and scaled by it.");
        setPropertyTooltip("closeFile", "Closes the output file if it is open.");
        setPropertyTooltip("writeTimecodeFile", "writes a file alongside AVI file (with suffix " + TIMECODE_SUFFIX + ") that maps from AVI frame to AER timestamp for that frame (the frame end timestamp)");
        setPropertyTooltip("closeOnRewind", "closes recording on rewind event, to allow unattended operation");
        setPropertyTooltip("format", "video file is writtent to this output format (note that RLE will throw exception because OpenGL frames are not 4 or 8 bit images)");
        setPropertyTooltip("maxFrames", "file is automatically closed after this many frames have been written; set to 0 to disable");
        setPropertyTooltip("framesWritten", "READONLY, shows number of frames written");
        setPropertyTooltip("compressionQuality", "In PNG or JPG format, sets compression quality; 0 is lowest quality and 1 is highest, 0.9 is default value");
        setPropertyTooltip("showFolderInDesktop", "Opens the folder containging the last-written AVI file");
        chip.getSupport().addPropertyChangeListener(this);
        
    }

    @Override
    synchronized public EventPacket<?> filterPacket(EventPacket<?> in) {
        if (!propertyChangeListenerAdded) {
            if (chip.getAeViewer() != null) {
                chip.getAeViewer().addPropertyChangeListener(AEInputStream.EVENT_REWIND, this);
                propertyChangeListenerAdded = true;
            }
        }
        return in;
    }

    @Override
    public void resetFilter() {
    }

    @Override
    public void initFilter() {
    }

    public void doShowFolderInDesktop() {<commit_msg>renamed boolean for chip propertychangelistener adding<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package net.sf.jaer.util.avioutput;

import com.jogamp.common.nio.Buffers;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import java.awt.Desktop;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Date;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
import net.sf.jaer.Description;
import net.sf.jaer.DevelopmentStatus;
import net.sf.jaer.chip.AEChip;
import net.sf.jaer.event.EventPacket;
import net.sf.jaer.eventio.AEInputStream;
import static net.sf.jaer.eventprocessing.EventFilter.log;
import net.sf.jaer.eventprocessing.EventFilter2D;
import net.sf.jaer.graphics.FrameAnnotater;

/**
 * Base class for EventFilters that write out AVI files from jAER
 *
 * @author Tobi
 */
@Description("Base class for EventFilters that write out AVI files from jAER")
@DevelopmentStatus(DevelopmentStatus.Status.Stable)
public class AbstractAviWriter extends EventFilter2D implements FrameAnnotater, PropertyChangeListener {

    protected AVIOutputStream aviOutputStream = null;
    protected static String DEFAULT_FILENAME = "jAER.avi";
    protected String lastFileName = getString("lastFileName", DEFAULT_FILENAME);
    protected int framesWritten = 0;
    protected final int logEveryThisManyFrames = 30;
    protected boolean writeTimecodeFile = getBoolean("writeTimecodeFile", true);
    protected static final String TIMECODE_SUFFIX = "-timecode.txt";
    protected File timecodeFile = null;
    protected FileWriter timecodeWriter = null;
    protected boolean closeOnRewind = getBoolean("closeOnRewind", true);
    private boolean chipPropertyChangeListenerAdded = false;
    protected AVIOutputStream.VideoFormat format = AVIOutputStream.VideoFormat.valueOf(getString("format", AVIOutputStream.VideoFormat.RAW.toString()));
    protected int maxFrames = getInt("maxFrames", 0);
    protected float compressionQuality = getFloat("compressionQuality", 0.9f);
    private String[] additionalComments=null;

    public AbstractAviWriter(AEChip chip) {
        super(chip);
        setPropertyTooltip("saveAVIFileAs", "Opens the output file. The AVI file is in RAW format with pixel values 0-255 coming from ApsFrameExtractor displayed frames, which are offset and scaled by it.");
        setPropertyTooltip("closeFile", "Closes the output file if it is open.");
        setPropertyTooltip("writeTimecodeFile", "writes a file alongside AVI file (with suffix " + TIMECODE_SUFFIX + ") that maps from AVI frame to AER timestamp for that frame (the frame end timestamp)");
        setPropertyTooltip("closeOnRewind", "closes recording on rewind event, to allow unattended operation");
        setPropertyTooltip("format", "video file is writtent to this output format (note that RLE will throw exception because OpenGL frames are not 4 or 8 bit images)");
        setPropertyTooltip("maxFrames", "file is automatically closed after this many frames have been written; set to 0 to disable");
        setPropertyTooltip("framesWritten", "READONLY, shows number of frames written");
        setPropertyTooltip("compressionQuality", "In PNG or JPG format, sets compression quality; 0 is lowest quality and 1 is highest, 0.9 is default value");
        setPropertyTooltip("showFolderInDesktop", "Opens the folder containging the last-written AVI file");
        chip.getSupport().addPropertyChangeListener(this);
        
    }

    @Override
    synchronized public EventPacket<?> filterPacket(EventPacket<?> in) {
        if (!chipPropertyChangeListenerAdded) {
            if (chip.getAeViewer() != null) {
                chip.getAeViewer().addPropertyChangeListener(AEInputStream.EVENT_REWIND, this);
                chipPropertyChangeListenerAdded = true;
            }
        }
        return in;
    }

    @Override
    public void resetFilter() {
    }

    @Override
    public void initFilter() {
    }

    public void doShowFolderInDesktop() {
{'fraction_non_alphanumeric': 0.08564631245043616, 'fraction_numerical': 0.004531550923303501, 'mean_word_length': 4.382926829268293, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5931909', 'n_tokens_mistral': 2460, 'n_tokens_neox': 2393, 'n_words': 737}