Changeset 342


Ignore:
Timestamp:
10/04/08 16:20:57 (16 years ago)
Author:
bjn8
Message:

Fixed timing accuracy-issues with overdubbing

Location:
trunk/src_apollo/org/apollo
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src_apollo/org/apollo/audio/structure/AudioStructureModel.java

    r318 r342  
    10931093                                if (odframe != null) {
    10941094                                        tinf = odframe.removeTrack(localFilename);
    1095                                         assert(tinf != null);
     1095                                        //assert(tinf != null);
    10961096                                        cancelFetch = doNotify = true;
    10971097                                }
  • trunk/src_apollo/org/apollo/audio/util/FrameLayoutDaemon.java

    r340 r342  
    553553         *
    554554         * @return
     555         *              The best timeline for the given frame - null if could not infer (if had to).
    555556         */
    556557        public Timeline getTimeline(Frame targetFrame) {
  • trunk/src_apollo/org/apollo/gui/EditableSampledTrackGraphView.java

    r338 r342  
    279279                                                0,
    280280                                                0,
    281                                                 -1,
    282281                                                TrackNameCreator.getDefaultName(),
    283282                                                getMix());
  • trunk/src_apollo/org/apollo/util/AudioMath.java

    r315 r342  
    2727         */
    2828        public static int millisecondsToFrames(long ms, AudioFormat format) {
    29                 double portion = ms;
    30                 portion /= 1000.0;
    31                 return (int)(format.getFrameRate() * portion);
     29                double tmp = ms * format.getFrameRate();
     30                tmp /= 1000.0;
     31                return (int)tmp;
    3232        }
    3333       
    3434        public static long framesToMilliseconds(long frames, AudioFormat format) {
    35                 double portion = frames;
    36                 portion /= (double)format.getFrameRate();
    37                 return (long)(portion * 1000.0);
     35                double tmp = frames * 1000.0;
     36                tmp /= (double)format.getFrameRate();
     37                return (long)tmp;
    3838        }
    3939       
  • trunk/src_apollo/org/apollo/widgets/SampleRecorder.java

    r335 r342  
    386386                                                         getX(),
    387387                                                         getY(),
    388                                                          initiationTime,
    389388                                                         TrackNameCreator.getNameCopy(targetFrame.getTitle() + "_"),
    390389                                                         null);
     
    393392                                                 
    394393                                                 targetFrame.addAllItems(trackWidget.getItems());
    395                
     394                                                 
     395                                                 // Must be exact
     396                                                 trackWidget.setInitiationTime(initiationTime);
     397
    396398                                         } else {
    397399                                                 
  • trunk/src_apollo/org/apollo/widgets/SampledTrack.java

    r340 r342  
    405405                                }
    406406                               
    407                                 // Toggle indexing
     407                                // Toggle pitch-track indexing
    408408                                if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_I) {
    409409                                        setShouldOmitIndexAudio(!shouldOmitIndexAudio());
     
    453453                                                        initTime += AudioMath.framesToMilliseconds(rightSideStartFrame, trackModel.getFormat());
    454454                                                       
     455                                                        System.out.println("initTime = " + getInitiationTimeFromMeta() + " + " + AudioMath.framesToMilliseconds(rightSideStartFrame, trackModel.getFormat())
     456                                                                        + " = " + initTime);
     457                                                       
    455458                                                        SampledTrack rightSideTrack = SampledTrack.createFromMemory(
    456459                                                                        rightsideAudio,
     
    459462                                                                        0, // X Coord overridden
    460463                                                                        getY(),
    461                                                                         initTime,
    462464                                                                        getName() + " part",
    463465                                                                        trackMix);
     
    465467                                                        // Anchor it
    466468                                                        target.addAllItems(rightSideTrack.getItems());
     469                                                       
     470                                                        // Adjust initiation time to be exact
     471                                                        rightSideTrack.setInitiationTime(initTime);
     472                                                       
     473                                                        // TODO: FrameLayoutDaemon.getInstance().resumeLayout(this); ?
    467474                                                }
    468475                                               
     
    511518        /**
    512519         * Creates a {@link SampledTrack} instantly from audio bytes in memory and adds it to a given frame.
     520         *
    513521         * @param audioBytes
    514522         *                      The audio samples.
     
    523531         *
    524532         * @param y
    525          *
    526          * @param specificInitTime
    527          *              Negative to determine init time from x position. Positive to override
    528          *              and determine x position from given init time
    529533         *
    530534         * @param name
     
    543547                        Frame targetFrame,
    544548                        int x, int y,
    545                         long specificInitTime,
    546549                        String name,
    547550                        TrackMixSubject mixTemplate) {
     
    554557                source.setParent(targetFrame);
    555558               
    556                
    557                
     559
    558560                long runningtime = AudioMath.framesToMilliseconds(
    559561                                audioBytes.length / format.getFrameSize(), format);
    560                
    561562               
    562563                Timeline tl = FrameLayoutDaemon.getInstance().getTimeline(targetFrame);
     
    570571                if (width > 0 && width < FrameLayoutDaemon.MIN_TRACK_WIDGET_WIDTH) width = FrameLayoutDaemon.MIN_TRACK_WIDGET_WIDTH;
    571572
    572                 if (specificInitTime < 0) {
    573                        
    574                         if (tl == null) specificInitTime = 0;
    575                         else specificInitTime = tl.getMSTimeAtX(x);
    576                        
    577                 } else if (tl != null) { // if defined a specific ms time and a timeline is avialable
    578                        
    579                         x = tl.getXAtMSTime(specificInitTime);
    580                 }
    581                
     573                long initTime = (tl == null) ? 0 : tl.getMSTimeAtX(x);
     574
    582575                source.setPosition(x, y);
    583576                       
     
    585578                LinkedList<String> data = new LinkedList<String>();
    586579
    587                 data.add(TrackWidgetCommons.META_INITIATIONTIME_TAG + specificInitTime);
     580                data.add(TrackWidgetCommons.META_INITIATIONTIME_TAG + initTime);
    588581                data.add(TrackWidgetCommons.META_LAST_WIDTH_TAG + width); // although layout manager will handle, just to quick set
    589582                if (name != null) data.add(TrackWidgetCommons.META_NAME_TAG + name);
     
    703696                                        getX(),
    704697                                        getY(),
    705                                         -1,
    706698                                        TrackNameCreator.getNameCopy(trackModel.getName()),
    707699                                        trackMix);
     
    15711563        public Long getInitiationTimeFromMeta() {
    15721564                return getStrippedDataLong(TrackWidgetCommons.META_INITIATIONTIME_TAG, null);
     1565        }
     1566       
     1567        /**
     1568         * Adjusts the initiation time for this track - to the exact millisecond.
     1569         *
     1570         * The x-position is updated (which will be eventually done with possibly better
     1571         * accuracy if the layout daemon is on)
     1572         *
     1573         * @param specificInitTime
     1574         *              The new initiation time for this track in milliseconds
     1575         */
     1576        public void setInitiationTime(long specificInitTime) {
     1577               
     1578                Frame parent = getParentFrame();
     1579               
     1580                // Update x position if it can
     1581                if (parent != null) {
     1582                        Timeline tl = FrameLayoutDaemon.getInstance().getTimeline(parent);
     1583                        if (tl != null) {
     1584                                this.setPosition(tl.getXAtMSTime(specificInitTime), getY());
     1585                        }
     1586                }
     1587               
     1588                updateData(TrackWidgetCommons.META_INITIATIONTIME_TAG, TrackWidgetCommons.META_INITIATIONTIME_TAG + specificInitTime);
     1589               
     1590                // If this track is in the audio model ...
     1591                if (AudioStructureModel.getInstance().getTrackGraphInfo(localFileName, (parent != null) ? parent.getName() : null) != null)  {
     1592                       
     1593                        // Add and remove it
     1594                        AudioStructureModel.getInstance().onTrackWidgetRemoved(
     1595                                        localFileName, (parent != null) ? parent.getName() : null);
     1596                       
     1597                        AudioStructureModel.getInstance().onTrackWidgetAnchored(
     1598                                        localFileName, (parent != null) ? parent.getName() : null,
     1599                                                        specificInitTime, getRunningMSTimeFromRawAudio(), getName());
     1600                }
    15731601        }
    15741602       
Note: See TracChangeset for help on using the changeset viewer.