Ignore:
Timestamp:
10/02/18 10:18:57 (6 years ago)
Author:
bln4
Message:

org.apollo.ApolloGestureActions ->
org.apollo.widgets.SampledTrack ->

Reimplemented the ability to stamp SampledTracks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/apollo/widgets/SampledTrack.java

    r1156 r1179  
    159159
    160160                // Create the immutable mix subject
    161                 if (mixTemplate == null)
     161                if (mixTemplate == null) {
    162162                        trackMix = SoundDesk.getInstance().getOrCreateMix(SoundDesk.createPureLocalChannelID(this));
    163                
    164                 else trackMix = SoundDesk.getInstance().createMix(
    165                                 SoundDesk.createPureLocalChannelID(this),
    166                                 mixTemplate.getVolume(),
    167                                 mixTemplate.isMuted());
     163                } else {
     164                        trackMix = SoundDesk.getInstance().createMix(
     165                                        SoundDesk.createPureLocalChannelID(this),
     166                                        mixTemplate.getVolume(),
     167                                        mixTemplate.isMuted());
     168                }
    168169                               
    169170                // Keep meta as constant as possible for best results
     
    275276                fulltrackView.addMouseMotionListener(new MouseMotionListener() {
    276277
     278                        @Override
    277279                        public void mouseDragged(MouseEvent e) {
    278280                                if (nameLabel != null) {
     
    283285                        }
    284286
     287                        @Override
    285288                        public void mouseMoved(MouseEvent e) {
    286289
     
    331334                fulltrackView.addMouseListener(new MouseListener() {
    332335
     336                        @Override
    333337                        public void mouseClicked(MouseEvent e) {
    334                                 if (trackModel == null) return;
     338                                if (trackModel == null) {
     339                                        return;
     340                                }
    335341                               
    336342                                if (nameLabel != null) {
     
    349355                        }
    350356
     357                        @Override
    351358                        public void mouseEntered(MouseEvent e) {
    352359                        }
    353360
     361                        @Override
    354362                        public void mouseExited(MouseEvent e) {
    355363                        }
    356364
     365                        @Override
    357366                        public void mousePressed(MouseEvent e) {
    358367                                if (nameLabel != null) {
     
    370379                        }
    371380
     381                        @Override
    372382                        public void mouseReleased(MouseEvent e) {
    373383                                if (nameLabel != null) {
     
    378388                               
    379389                                 if (!e.isConsumed() && e.getButton() == MouseEvent.BUTTON2) {
    380                                                 if (split(true))
     390                                                if (split(true)) {
    381391                                                        e.consume();
     392                                                }
    382393                                        }
    383394                               
     
    393404                fulltrackView.addKeyListener(new KeyListener() {
    394405
     406                        @Override
    395407                        public void keyPressed(KeyEvent e)
    396408                        {
    397409                        }
    398410
     411                        @Override
    399412                        public void keyReleased(KeyEvent e)
    400413                        {
     
    408421                                else if (!e.isControlDown() && e.getKeyCode() == KeyEvent.VK_DELETE) {
    409422                                       
    410                                         if (split(false))  // try Perform delete-split
     423                                        if (split(false)) {
    411424                                                e.consume();
     425                                        }
    412426                                       
    413427                                }
     
    420434                                               
    421435                                                String name =  getName();
    422                                                 if (name == null) name = "Unamed";
     436                                                if (name == null) {
     437                                                        name = "Unamed";
     438                                                }
    423439                                               
    424440                                                Mutable.Long initTime = getInitiationTimeFromMeta();
    425                                                 if (initTime == null) initTime = Mutable.createMutableLong(0);
     441                                                if (initTime == null) {
     442                                                        initTime = Mutable.createMutableLong(0);
     443                                                }
    426444                                               
    427445                                                Text linkSource = new Text(current.getNextItemID());
     
    433451                                                // Save any changes in the audio - or save for the first time
    434452                                                if (trackModel.isAudioModified())
     453                                                 {
    435454                                                        saveWidgetData(); // a little lag is OK .. could make smarter if really need to
     455                                                }
    436456                                               
    437457                                                // Create a new frame to hold the track
     
    477497                        }
    478498
     499                        @Override
    479500                        public void keyTyped(KeyEvent e) {
    480501                        }
     
    486507               
    487508                String metaName = getStrippedDataString(TrackWidgetCommons.META_NAME_TAG);
    488                 if (metaName == null) metaName = "Untitled";
     509                if (metaName == null) {
     510                        metaName = "Untitled";
     511                }
    489512                nameLabel.setText(metaName);
    490513
    491514                nameLabel.addTextChangeListener(new TextChangeListener() { //  a little bit loopy!
    492515
     516                        @Override
    493517                        public void onTextChanged(Object source, String newLabel) {
    494518                                if (trackModel != null && !nameLabel.getText().equals(trackModel.getName())) {
     
    558582                int width = -1;
    559583                if (tl != null) {
    560                         width = (int)((double)runningtime / tl.getTimePerPixel());
     584                        width = (int)(runningtime / tl.getTimePerPixel());
    561585                }       
    562586               
    563587                // Clamp width to something reasonable.
    564                 if (width > 0 && width < FrameLayoutDaemon.MIN_TRACK_WIDGET_WIDTH) width = FrameLayoutDaemon.MIN_TRACK_WIDGET_WIDTH;
     588                if (width > 0 && width < FrameLayoutDaemon.MIN_TRACK_WIDGET_WIDTH) {
     589                        width = FrameLayoutDaemon.MIN_TRACK_WIDGET_WIDTH;
     590                }
    565591
    566592                long initTime = (tl == null) ? 0 : tl.getMSTimeAtX(x);
     
    573599                data.add(TrackWidgetCommons.META_INITIATIONTIME_TAG + initTime);
    574600                data.add(TrackWidgetCommons.META_LAST_WIDTH_TAG + width); // although layout manager will handle, just to quick set
    575                 if (name != null) data.add(TrackWidgetCommons.META_NAME_TAG + name);
     601                if (name != null) {
     602                        data.add(TrackWidgetCommons.META_NAME_TAG + name);
     603                }
    576604               
    577605                source.setData(data);
     
    644672                data.add(META_LOCALNAME_TAG + localFileName);
    645673               
    646                 if (shouldOmitAudioIndexing) data.add(META_DONT_INDEX_AUDIO_TAG);
     674                if (shouldOmitAudioIndexing) {
     675                        data.add(META_DONT_INDEX_AUDIO_TAG);
     676                }
    647677               
    648678                String lastName = getName();
    649679               
    650                 if (lastName != null)
     680                if (lastName != null) {
    651681                        data.add(TrackWidgetCommons.META_NAME_TAG + lastName);
     682                }
    652683               
    653684                data.add(TrackWidgetCommons.META_LAST_WIDTH_TAG + getWidth());
     
    663694                }
    664695               
    665                 if (initTime == null) initTime = getInitiationTimeFromMeta(); // old meta
    666                 if (initTime == null) initTime = Mutable.createMutableLong(0L);
     696                if (initTime == null)
     697                 {
     698                        initTime = getInitiationTimeFromMeta(); // old meta
     699                }
     700                if (initTime == null) {
     701                        initTime = Mutable.createMutableLong(0L);
     702                }
    667703
    668704                data.add(TrackWidgetCommons.META_INITIATIONTIME_TAG + initTime);
     
    677713        public Widget copy()
    678714                throws InteractiveWidgetNotAvailableException, InteractiveWidgetInitialisationFailedException {
    679                
    680715                if (trackModel == null) {
    681716                        return super.copy();
    682717                       
    683718                } else {
    684 
    685719                        return SampledTrack.createFromMemory(
    686720                                        trackModel.getAllAudioBytesCopy(),
     
    711745                        setLoadScreenMessage("Recovering audio file...");
    712746                       
    713                         if (recoveryFile.exists())
     747                        if (recoveryFile.exists()) {
    714748                                f = recoveryFile;
     749                        }
    715750
    716751                }
     
    735770                       
    736771                        // Nullify
    737                         if (!f.exists() || !f.isFile()) f = null;
     772                        if (!f.exists() || !f.isFile()) {
     773                                f = null;
     774                        }
    738775
    739776                }
     
    799836                // Set the name for this track
    800837                String name = getStrippedDataString(TrackWidgetCommons.META_NAME_TAG);
    801                 if (name != null)
     838                if (name != null) {
    802839                        trackModel.setName(name);
     840                }
    803841               
    804842                initObservers(); // sets default name if non set
     
    817855                        SwingUtilities.invokeAndWait(new Runnable() {
    818856                               
     857                                @Override
    819858                                public void run() {
    820859                                       
     
    859898         * Used by save manager
    860899         */
     900        @Override
    861901        public boolean doesNeedSaving() {
    862902                return (trackModel != null && (trackModel.isAudioModified() || trackModel.getFilepath() == null));
     
    866906         * Used by save manager
    867907         */
     908        @Override
    868909        public String getSaveName() {
    869910               
    870                 if (trackModel != null && trackModel.getName() != null)
     911                if (trackModel != null && trackModel.getName() != null) {
    871912                        return "Sampled Track: " + trackModel.getName();
    872                 else return "A Sampled Track";
     913                } else {
     914                        return "A Sampled Track";
     915                }
    873916               
    874917        }
     
    890933        protected void saveWidgetData() {
    891934               
    892                 if (trackModel == null) return; // nothing to save
     935                if (trackModel == null)
     936                 {
     937                        return; // nothing to save
     938                }
    893939               
    894940                // If saving for the file time then get a filename
     
    920966                        try {
    921967                                SwingUtilities.invokeAndWait(new Runnable() {
     968                                        @Override
    922969                                        public void run() {
    923970                                                releaseMemory(true);
     
    947994                // Still needs to save?
    948995                if (doesNeedSaving() || trackModel == null)
     996                 {
    949997                        return; // Release memory later when saved
     998                }
    950999
    9511000                try {
    9521001                        // Release memory - on swing thread to avoid nullified model data wil painting / editing.
    9531002                        SwingUtilities.invokeAndWait(new Runnable() {
     1003                                @Override
    9541004                                public void run() {
    9551005                                        releaseMemory(true);
     
    9691019
    9701020                // Need unloading?
    971                 if (trackModel == null) return;
     1021                if (trackModel == null) {
     1022                        return;
     1023                }
    9721024               
    9731025                // Get rid of old temporary files
     
    10191071                        // Release memory - on swing thread to avoid nullified model data wil painting / editing.
    10201072                        SwingUtilities.invokeAndWait(new Runnable() {
     1073                                @Override
    10211074                                public void run() {
    10221075                                        releaseMemory(false);
     
    10601113         * Global Track model re-use ....
    10611114         */
     1115        @Override
    10621116        public SampledTrackModel getSharedSampledTrackModel(String localfilename) {
    10631117                if (trackModel != null &&
     
    11091163        }
    11101164
     1165        @Override
    11111166        public void onGraphDirty(SampledTrackGraphView graph, Rectangle dirty)
    11121167        {
     
    11161171        }
    11171172
     1173        @Override
    11181174        public Subject getObservedSubject() {
    11191175                return null;
     
    11321188         * Responds to model changed events by updating the GUI ...
    11331189         */
     1190        @Override
    11341191        public void modelChanged(Subject source, SubjectChangedEvent event) {
    11351192               
     
    11641221                                        } else {
    11651222                                                float perc = ((Float)event.getState()).floatValue();
    1166                                                 if (perc > 1.0f) perc = 1.0f;
     1223                                                if (perc > 1.0f) {
     1224                                                        perc = 1.0f;
     1225                                                }
    11671226                                                perc *= FILE_LOADING_PERCENT_RANGE; // Dont stretch load to all of bar - still will have more work to do
    11681227                                                updateLoadPercentage(perc);
     
    12131272                                       
    12141273                                                Mutable.Long inittime = getInitiationTimeFromMeta();
    1215                                                 if (inittime == null) inittime = Mutable.createMutableLong(0);
     1274                                                if (inittime == null) {
     1275                                                        inittime = Mutable.createMutableLong(0);
     1276                                                }
    12161277                                                inittime.value += (oldRunningTime - newRunningTime);
    12171278                                               
     
    12331294        }
    12341295       
     1296        @Override
    12351297        public void setObservedSubject(Subject parent) {
    12361298        }
     
    13181380                        // Draw the name
    13191381                        String name = getName();
    1320                         if (name == null) name = "Unnamed";
     1382                        if (name == null) {
     1383                                name = "Unnamed";
     1384                        }
    13211385
    13221386                        g.setFont(SwingMiscManager.getIfUsingSwingFontManager().getInternalFont(TrackWidgetCommons.FREESPACE_TRACKNAME_FONT));
     
    14191483                                                inferInitTime &= (eventType == ItemParentStateChangedEvent.EVENT_TYPE_ADDED);
    14201484                                               
    1421                                                 if (inferInitTime)
     1485                                                if (inferInitTime) {
    14221486                                                        initTime = Mutable.createMutableLong(FrameLayoutDaemon.getInstance().getMSAtX(getX(), parent));
     1487                                                }
    14231488                                        }
    14241489
     
    15491614                // Cannot inject into EditableSampledTrackGraphView's while playing, although
    15501615                // won't break anything, this would be confusing for the user.
    1551                 if (target.isPlaying()) return;
     1616                if (target.isPlaying()) {
     1617                        return;
     1618                }
    15521619               
    15531620                // Inject the audio at the graph poistion
     
    15631630                // more references to this item therefore the memory will be freed
    15641631                // eventually after this invoke
    1565                 if (destroySelf) removeSelf();
     1632                if (destroySelf) {
     1633                        removeSelf();
     1634                }
    15661635        }
    15671636       
     
    16061675         *              The name given to this widget... can be null.
    16071676         */
     1677        @Override
    16081678        public String getName() {
    1609                 if (this.trackModel != null)
     1679                if (this.trackModel != null) {
    16101680                        return trackModel.getName();
    1611                 else if (this.nameLabel != null) {
     1681                } else if (this.nameLabel != null) {
    16121682                        return nameLabel.getText();
    16131683                }
     
    16241694        public Mutable.Long getInitiationTimeFromMeta() {
    16251695                Long l = getStrippedDataLong(TrackWidgetCommons.META_INITIATIONTIME_TAG, null);
    1626                 if (l != null) return Mutable.createMutableLong(l.longValue());
     1696                if (l != null) {
     1697                        return Mutable.createMutableLong(l.longValue());
     1698                }
    16271699                return null;
    16281700        }
     
    16631735        public void setYPosition(int newY) {
    16641736
    1665                 if (getY() == newY || isFloating()) return;
     1737                if (getY() == newY || isFloating()) {
     1738                        return;
     1739                }
    16661740
    16671741                Frame parent = getParentFrame();
    16681742               
    16691743                Mutable.Long initTime = getInitiationTimeFromMeta();
    1670                 if (initTime == null) return;
     1744                if (initTime == null) {
     1745                        return;
     1746                }
    16711747               
    16721748                setPosition(getX(), newY);
     
    17711847                                // Build the new neighbouring widget
    17721848                                Frame target = getParentFrame();
    1773                                 if (target == null) target = DisplayController.getCurrentFrame();
     1849                                if (target == null) {
     1850                                        target = DisplayController.getCurrentFrame();
     1851                                }
    17741852                               
    17751853                                // Determine init time
    17761854                                Mutable.Long initTime = getInitiationTimeFromMeta();
    17771855                               
    1778                                 if (initTime == null) initTime = Mutable.createMutableLong(0);
     1856                                if (initTime == null) {
     1857                                        initTime = Mutable.createMutableLong(0);
     1858                                }
    17791859                               
    17801860                                initTime.value += AudioMath.framesToMilliseconds(rightSideStartFrame, trackModel.getFormat());
     
    18291909                Frame parent = getParentFrame();
    18301910                String pfname = (parent != null) ?  parent.getName() : null;
    1831                 if (pfname == null) return;
     1911                if (pfname == null) {
     1912                        return;
     1913                }
    18321914
    18331915                if (!ExpandedTrackManager.getInstance().isTrackInExpansionSelection(trackModel)) {
     
    19131995                }
    19141996
     1997                @Override
    19151998                public void actionPerformed(ActionEvent e) {
    1916                         if (trackModel == null) return;
     1999                        if (trackModel == null) {
     2000                                return;
     2001                        }
    19172002                       
    19182003                        if (e.getSource() == playPauseButton) {
     
    20122097                }
    20132098               
     2099                @Override
    20142100                public Subject getObservedSubject()
    20152101                {
     
    20172103                }
    20182104
     2105                @Override
    20192106                public void setObservedSubject(Subject parent)
    20202107                {
     
    20242111                 * Receives events from the track model OR from the observed track sequence.
    20252112                 */
     2113                @Override
    20262114                public void modelChanged(Subject source, SubjectChangedEvent event)
    20272115                {
     
    21092197                protected void volumeChanged()
    21102198                {
    2111                         trackMix.setVolume(((float)volumeSlider.getValue()) / 100.0f);
     2199                        trackMix.setVolume((volumeSlider.getValue()) / 100.0f);
    21122200                }
    21132201
Note: See TracChangeset for help on using the changeset viewer.