Ignore:
Timestamp:
04/09/03 05:44:11 (21 years ago)
Author:
Nicholas Riley
Message:

VERSION: Updated for 1.1b4.

PSMovieAlertController.[hm]: Set output volume from alert; save and
restore output volume (bug 27).

PSBeepAlert.[hm]: Save and set volume, disabled pending a
synchronous equivalent to NSBeep().

NJRQTMediaPopUpButton.[hm]: Save movieHasAudio (does not include
beeps, pending the above fix, since they don't permit volume
adjustment). savedVolume indicates whether the volume has been saved
but not restored yet; outputVolume stores the set volume (eventually
incorporated into a PSMediaAlert).

PSMediaAlert.[hm]: Stores repetitions and volume information for audio
alerts. New superclass of PSBeepAlert and PSMovieAlert.

PSPreferencesController.m: Fixed bug where hot keys still appeared
even after they couldn't be set - last of bug 29. Add Command-comma
to the list of disallowed equivalents, as it's reserved for
Preferences now (still a bug - it'll show the entire set key
equivalent at the left side of the window when you press
command-comma; ah well.)

Volume [0123].png: Volume-indicating small icons from QuickTime 6.

NJRSoundManager.[hm]: Interface to volume saving, restoring, setting -
necessary because the QuickTime call to SetDefaultOutputVolume sets
the right channel volume only (bug 27).

PSVolumeController.h: Controller for volume popup window (bug 27).
Not your average NSWindowController, but it works. Keyboard control
of volume is still necessary; filed as bug 31.

PSAlarmSetController.[hm]: Added references to sound volume button and
showVolume: action. Added volume setting support (bug 27); mostly
similar interface to calendar, though we need direct calls to
NJRSoundManager to restore sound volume at times. Only enable sound
volume button if selected media file has audio component (and isn't the
system alert sound, which I discussed above). Take advantage of
PSMediaAlert to factor some code in _readAlerts:. Save and restore
volume as part of alerts.

Read Me.rtfd: Updated release notes; fixed some bizarre text
formatting problems; search/replace "* " bullet-space with "*\t"
bullet-tab to improve alignment in release notes.

PSMovieAlert.[hm]: Factored code into PSMediaAlert. Describe output
volume as percentage of maximum.

NJRHotKey.m: Fixed some odd spacing left over from Ecky's code.

PSApplication.m: Restore saved output volume on quit.

English.lproj/MainMenu.nib: Added volume button.

English.lproj/Volume.nib: Volume nib (bug 27).

PSCalendarController.m: Removed casts from a copy/paste error. Fixed
variable names in some code inherited from my TextExtras incremental
search modifications - it's not always a text field now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/Pester/Source/NJRQTMediaPopUpButton.m

    r103 r133  
    99#import "NJRQTMediaPopUpButton.h"
    1010#import "SoundFileManager.h"
     11#import "NJRSoundManager.h"
    1112#import "NSMovie-NJRExtensions.h"
    1213#import "NSImage-NJRExtensions.h"
     
    2728- (NSMenuItem *)_itemForAlias:(BDAlias *)alias;
    2829- (BOOL)_validateWithPreview:(BOOL)doPreview;
     30- (void)_updateOutputVolume;
     31- (void)_startSoundPreview;
    2932@end
    3033
     
    267270}
    268271
     272- (BOOL)hasAudio;
     273{
     274    return movieHasAudio;
     275}
     276
     277- (float)outputVolume;
     278{
     279    return outputVolume;
     280}
     281
     282- (void)setOutputVolume:(float)volume withPreview:(BOOL)doPreview;
     283{
     284    if (![NJRSoundManager volumeIsNotMutedOrInvalid: volume]) return;
     285    outputVolume = volume;
     286    if (!doPreview) return;
     287    // NSLog(@"setting volume to %f, preview movie %@", volume, [preview movie]);
     288    if ([preview movie] == nil) {
     289        [self _validateWithPreview: YES];
     290    } else { // don't restart preview if already playing
     291        [self _updateOutputVolume];
     292    }
     293}
     294
    269295#pragma mark selected media validation
    270296
     
    276302}
    277303
     304- (void)_updateOutputVolume;
     305{
     306    if ([preview movie] != nil && outputVolume != kNoVolume) {
     307        if (!savedVolume && ![NJRSoundManager saveDefaultOutputVolume])
     308            return;
     309        savedVolume = YES;
     310        [NJRSoundManager setDefaultOutputVolume: outputVolume];
     311        if (![preview isPlaying]) [self _startSoundPreview];
     312    }
     313}
     314
     315- (void)_resetOutputVolume;
     316{
     317    [NJRSoundManager restoreSavedDefaultOutputVolumeIfCurrently: outputVolume];
     318    savedVolume = NO;
     319}
     320
     321- (void)_resetPreview;
     322{
     323    // if we donÕt do this after the runloop has finished, then we crash in MCIdle because itÕs expecting a movie and doesnÕt have one any more
     324    [preview setMovie: nil]; // otherwise we get an extra runloop timer which uses a lot of CPU from +[NSMovieView _idleMovies]
     325    // need to wait for runloop to stop movie, otherwise we're still playing at the time the volume changes
     326    [self performSelector: @selector(_resetOutputVolume) withObject: nil afterDelay: 0];
     327}
     328
    278329void
    279330MovieStoppedCB(QTCallBack cb, long refCon)
    280331{
    281     NSMovieView *preview = (NSMovieView *)refCon;
    282     // if we donÕt do this after the runloop has finished, then we crash in MCIdle because itÕs expecting a movie and doesnÕt have one any more
    283     [preview performSelector: @selector(setMovie:) withObject: nil afterDelay: 0]; // otherwise we get an extra runloop timer which uses a lot of CPU from +[NSMovieView _idleMovies]
     332    NJRQTMediaPopUpButton *self = (NJRQTMediaPopUpButton *)refCon;
     333    // avoid multiple messages from multiple movie playback cycles in the same runloop
     334    [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(_resetPreview) object: nil];
     335    [self performSelector: @selector(_resetPreview) withObject: nil afterDelay: 0];
    284336    DisposeCallBack(cb);
     337}
     338
     339- (void)_startSoundPreview;
     340{
     341    Movie qtMovie = [[preview movie] QTMovie];
     342    QTCallBack cbStop = NewCallBack(GetMovieTimeBase(qtMovie), callBackAtExtremes);
     343    QTCallBackUPP cbStopUPP = NewQTCallBackUPP(MovieStoppedCB);
     344    OSErr err = CallMeWhen(cbStop, cbStopUPP, (long)self, triggerAtStop, 0, 0);
     345    if (err != noErr) {
     346        NSLog(@"Can't register QuickTime stop timebase callback for preview: %ld", err);
     347        DisposeCallBack(cbStop);
     348    }
     349    [preview start: self];
    285350}
    286351
     
    291356        [preview setMovie: nil];
    292357        movieCanRepeat = YES;
    293         if (doPreview) NSBeep();
     358        movieHasAudio = NO; // XXX should be YES - this is broken, NSBeep() is asynchronous
     359        if (doPreview) {
     360            // XXX [self _updateOutputVolume];
     361            NSBeep();
     362            // XXX [self _resetOutputVolume];
     363        }
    294364    } else {
    295365        NSMovie *movie = [[NSMovie alloc] initWithURL: [NSURL fileURLWithPath: [selectedAlias fullPath]] byReference: YES];
    296366        movieCanRepeat = ![movie isStatic];
    297         if ([movie hasAudio]) {
     367        if (movieHasAudio = [movie hasAudio]) {
    298368            [preview setMovie: doPreview ? movie : nil];
     369            [self _updateOutputVolume];
    299370        } else {
    300             [preview setMovie: nil];
     371            [self _resetPreview];
     372            doPreview = NO;
    301373            if (movie == nil) {
    302374                NSBeginAlertSheet(@"Format not recognized", nil, nil, nil, [self window], nil, nil, nil, nil, NSLocalizedString(@"The item you selected isn't a sound or movie recognized by QuickTime.  Please select a different item.", "Message displayed in alert sheet when media document is not recognized by QuickTime"));
     
    312384        }
    313385        if (doPreview) {
    314             Movie qtMovie = [movie QTMovie];
    315             QTCallBack cbStop = NewCallBack(GetMovieTimeBase(qtMovie), callBackAtExtremes);
    316             QTCallBackUPP cbStopUPP = NewQTCallBackUPP(MovieStoppedCB);
    317             OSErr err = CallMeWhen(cbStop, cbStopUPP, (long)preview, triggerAtStop, 0, 0);
    318             if (err != noErr) {
    319                 NSLog(@"Can't register QuickTime stop timebase callback for preview: %ld", err);
    320                 DisposeCallBack(cbStop);
    321             }
    322             [preview start: self];
     386            [self _startSoundPreview];
    323387        }
    324388        [movie release];
     
    333397{
    334398    [preview stop: self];
    335     [preview setMovie: nil]; // otherwise we get an extra runloop timer which uses a lot of CPU from +[NSMovieView _idleMovies]
     399    [self _resetPreview];
    336400}
    337401
Note: See TracChangeset for help on using the changeset viewer.