| 3017 | | // Get first time value: |
| 3018 | | if (beatCount == 1) |
| 3019 | | gettimeofday(¤tTime,NULL); |
| 3020 | | |
| 3021 | | eventCount++; |
| 3022 | | |
| 3023 | | // Set wlastTime to wcurrentTime to remind the time: |
| 3024 | | lastTime = currentTime; |
| 3025 | | |
| 3026 | | // Get new time: |
| 3027 | | gettimeofday(¤tTime,NULL); |
| 3028 | | |
| 3029 | | |
| 3030 | | // Build doubled time difference: |
| 3031 | | lastBeatTime = (double)( |
| 3032 | | lastTime.tv_sec |
| 3033 | | + (double)(lastTime.tv_usec * US_DIVIDER) |
| 3034 | | + (int)m_nCoutOffset * .0001 |
| 3035 | | ); |
| 3036 | | currentBeatTime = (double)( |
| 3037 | | currentTime.tv_sec |
| 3038 | | + (double)(currentTime.tv_usec * US_DIVIDER) |
| 3039 | | ); |
| 3040 | | beatDiff = beatCount == 1 ? 0 : currentBeatTime - lastBeatTime; |
| 3041 | | |
| 3042 | | //if differences are to big reset the beatconter |
| 3043 | | if( beatDiff > 3.001 * 1/m_ntaktoMeterCompute ){ |
| 3044 | | eventCount = 1; |
| 3045 | | beatCount = 1; |
| 3046 | | return; |
| 3047 | | } |
| 3048 | | // Only accept differences big enough |
| 3049 | | if (beatCount == 1 || beatDiff > .001) { |
| 3050 | | if (beatCount > 1) |
| 3051 | | beatDiffs[beatCount - 2] = beatDiff ; |
| 3052 | | // Compute and reset: |
| 3053 | | if (beatCount == m_nbeatsToCount){ |
| 3054 | | // unsigned long currentframe = getRealtimeFrames(); |
| 3055 | | double beatTotalDiffs = 0; |
| 3056 | | for(int i = 0; i < (m_nbeatsToCount - 1); i++) |
| 3057 | | beatTotalDiffs += beatDiffs[i]; |
| 3058 | | double beatDiffAverage = |
| 3059 | | beatTotalDiffs |
| 3060 | | / (beatCount - 1) |
| 3061 | | * m_ntaktoMeterCompute ; |
| 3062 | | beatCountBpm = |
| 3063 | | (float) ((int) (60 / beatDiffAverage * 100)) |
| 3064 | | / 100; |
| 3065 | | AudioEngine::get_instance()->lock( RIGHT_HERE ); |
| 3066 | | if ( beatCountBpm > 500) |
| 3067 | | beatCountBpm = 500; |
| 3068 | | setBPM( beatCountBpm ); |
| 3069 | | AudioEngine::get_instance()->unlock(); |
| 3070 | | if (Preferences::get_instance()->m_mmcsetplay |
| 3071 | | == Preferences::SET_PLAY_OFF) { |
| 3072 | | beatCount = 1; |
| 3073 | | eventCount = 1; |
| 3074 | | }else{ |
| 3075 | | if ( m_audioEngineState != STATE_PLAYING ){ |
| 3076 | | unsigned bcsamplerate = |
| 3077 | | m_pAudioDriver->getSampleRate(); |
| 3078 | | unsigned long rtstartframe = 0; |
| 3079 | | if ( m_ntaktoMeterCompute <= 1){ |
| 3080 | | rtstartframe = |
| 3081 | | bcsamplerate |
| 3082 | | * beatDiffAverage |
| 3083 | | * ( 1/ m_ntaktoMeterCompute ); |
| 3084 | | }else |
| 3085 | | { |
| 3086 | | rtstartframe = |
| 3087 | | bcsamplerate |
| 3088 | | * beatDiffAverage |
| 3089 | | / m_ntaktoMeterCompute ; |
| 3090 | | } |
| 3091 | | |
| 3092 | | int sleeptime = |
| 3093 | | ( (float) rtstartframe |
| 3094 | | / (float) bcsamplerate |
| 3095 | | * (int) 1000 ) |
| 3096 | | + (int)m_nCoutOffset |
| 3097 | | + (int) m_nStartOffset; |
| 3098 | | #ifdef WIN32 |
| 3099 | | Sleep( sleeptime ); |
| 3100 | | #else |
| 3101 | | usleep( 1000 * sleeptime ); |
| 3102 | | #endif |
| 3103 | | |
| 3104 | | sequencer_play(); |
| 3105 | | } |
| 3106 | | |
| 3107 | | beatCount = 1; |
| 3108 | | eventCount = 1; |
| 3109 | | return; |
| 3110 | | } |
| 3111 | | } |
| 3112 | | else { |
| 3113 | | beatCount ++; |
| 3114 | | } |
| 3115 | | } |
| 3116 | | return; |
| | 3017 | // Get first time value: |
| | 3018 | if (beatCount == 1) |
| | 3019 | gettimeofday(¤tTime,NULL); |
| | 3020 | |
| | 3021 | eventCount++; |
| | 3022 | |
| | 3023 | // Set wlastTime to wcurrentTime to remind the time: |
| | 3024 | lastTime = currentTime; |
| | 3025 | |
| | 3026 | // Get new time: |
| | 3027 | gettimeofday(¤tTime,NULL); |
| | 3028 | |
| | 3029 | |
| | 3030 | // Build doubled time difference: |
| | 3031 | lastBeatTime = (double)( |
| | 3032 | lastTime.tv_sec |
| | 3033 | + (double)(lastTime.tv_usec * US_DIVIDER) |
| | 3034 | + (int)m_nCoutOffset * .0001 |
| | 3035 | ); |
| | 3036 | currentBeatTime = (double)( |
| | 3037 | currentTime.tv_sec |
| | 3038 | + (double)(currentTime.tv_usec * US_DIVIDER) |
| | 3039 | ); |
| | 3040 | beatDiff = beatCount == 1 ? 0 : currentBeatTime - lastBeatTime; |
| | 3041 | |
| | 3042 | //if differences are to big reset the beatconter |
| | 3043 | if( beatDiff > 3.001 * 1/m_ntaktoMeterCompute ){ |
| | 3044 | eventCount = 1; |
| | 3045 | beatCount = 1; |
| | 3046 | return; |
| | 3047 | } |
| | 3048 | // Only accept differences big enough |
| | 3049 | if (beatCount == 1 || beatDiff > .001) { |
| | 3050 | if (beatCount > 1) |
| | 3051 | beatDiffs[beatCount - 2] = beatDiff ; |
| | 3052 | // Compute and reset: |
| | 3053 | if (beatCount == m_nbeatsToCount){ |
| | 3054 | // unsigned long currentframe = getRealtimeFrames(); |
| | 3055 | double beatTotalDiffs = 0; |
| | 3056 | for(int i = 0; i < (m_nbeatsToCount - 1); i++) |
| | 3057 | beatTotalDiffs += beatDiffs[i]; |
| | 3058 | double beatDiffAverage = |
| | 3059 | beatTotalDiffs |
| | 3060 | / (beatCount - 1) |
| | 3061 | * m_ntaktoMeterCompute ; |
| | 3062 | beatCountBpm = |
| | 3063 | (float) ((int) (60 / beatDiffAverage * 100)) |
| | 3064 | / 100; |
| | 3065 | AudioEngine::get_instance()->lock( RIGHT_HERE ); |
| | 3066 | if ( beatCountBpm > 500) |
| | 3067 | beatCountBpm = 500; |
| | 3068 | setBPM( beatCountBpm ); |
| | 3069 | AudioEngine::get_instance()->unlock(); |
| | 3070 | if (Preferences::get_instance()->m_mmcsetplay |
| | 3071 | == Preferences::SET_PLAY_OFF) { |
| | 3072 | beatCount = 1; |
| | 3073 | eventCount = 1; |
| | 3074 | }else{ |
| | 3075 | if ( m_audioEngineState != STATE_PLAYING ){ |
| | 3076 | unsigned bcsamplerate = |
| | 3077 | m_pAudioDriver->getSampleRate(); |
| | 3078 | unsigned long rtstartframe = 0; |
| | 3079 | if ( m_ntaktoMeterCompute <= 1){ |
| | 3080 | rtstartframe = |
| | 3081 | bcsamplerate |
| | 3082 | * beatDiffAverage |
| | 3083 | * ( 1/ m_ntaktoMeterCompute ); |
| | 3084 | }else |
| | 3085 | { |
| | 3086 | rtstartframe = |
| | 3087 | bcsamplerate |
| | 3088 | * beatDiffAverage |
| | 3089 | / m_ntaktoMeterCompute ; |
| | 3090 | } |
| | 3091 | |
| | 3092 | int sleeptime = |
| | 3093 | ( (float) rtstartframe |
| | 3094 | / (float) bcsamplerate |
| | 3095 | * (int) 1000 ) |
| | 3096 | + (int)m_nCoutOffset |
| | 3097 | + (int) m_nStartOffset; |
| | 3098 | #ifdef WIN32 |
| | 3099 | Sleep( sleeptime ); |
| | 3100 | #else |
| | 3101 | usleep( 1000 * sleeptime ); |
| | 3102 | #endif |
| | 3103 | |
| | 3104 | sequencer_play(); |
| | 3105 | } |
| | 3106 | |
| | 3107 | beatCount = 1; |
| | 3108 | eventCount = 1; |
| | 3109 | return; |
| | 3110 | } |
| | 3111 | } |
| | 3112 | else { |
| | 3113 | beatCount ++; |
| | 3114 | } |
| | 3115 | } |
| | 3116 | return; |
| 3329 | | //time line test |
| 3330 | | if ( Preferences::get_instance()->__usetimeline ){ |
| 3331 | | float bpm = m_pSong->__bpm; |
| 3332 | | for ( int i = 0; i < static_cast<int>(m_timelinevector.size() ); i++){ |
| 3333 | | if( m_timelinevector[i].m_htimelinebeat > getPatternPos() ){ |
| 3334 | | break; |
| 3335 | | } |
| 3336 | | bpm = m_timelinevector[i].m_htimelinebpm; |
| 3337 | | }//for |
| 3338 | | if(bpm != m_pSong->__bpm){ |
| 3339 | | setBPM( bpm ); |
| 3340 | | } |
| 3341 | | }//if |
| | 3329 | //time line test |
| | 3330 | if ( Preferences::get_instance()->__usetimeline ){ |
| | 3331 | float bpm = m_pSong->__bpm; |
| | 3332 | for ( int i = 0; i < static_cast<int>(m_timelinevector.size() ); i++){ |
| | 3333 | if( m_timelinevector[i].m_htimelinebeat > getPatternPos() ){ |
| | 3334 | break; |
| | 3335 | } |
| | 3336 | bpm = m_timelinevector[i].m_htimelinebpm; |
| | 3337 | }//for |
| | 3338 | if(bpm != m_pSong->__bpm){ |
| | 3339 | setBPM( bpm ); |
| | 3340 | } |
| | 3341 | }//if |