#!/usr/bin/env python3
# Copyright 2016 Curtis Sand
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#     Unless required by applicable law or agreed to in writing, software
#     distributed under the License is distributed on an "AS IS" BASIS,
#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#     See the License for the specific language governing permissions and
#     limitations under the License.

"""A test for what happens when two waveforms are averaged together."""

from potty_oh import common
from potty_oh.wav_file import wav_file_context
from potty_oh.waveform import mix_down
from potty_oh.signal_generator import Generator
from potty_oh.music.pitch import Key
from potty_oh.music.interval import Interval


def main():
    parser = common.get_cmd_line_parser(description=__doc__)
    common.ParserArguments.filename(parser)
    common.ParserArguments.length(parser)
    common.ParserArguments.framerate(parser)
    common.ParserArguments.set_defaults(parser, type='constant',
                                        length=2.0)
    args = parser.parse_args()
    common.defaults.framerate = args.framerate

    sg = Generator(length=args.length, verbose=args.debug)

    key = Key()
    unison = sg.sin_constant(key.interval(Interval.unison))
    maj_third = sg.sin_constant(key.interval(Interval.major_third))
    min_third = sg.sin_constant(key.interval(Interval.minor_third))
    fifth = sg.sin_constant(key.interval(Interval.fifth))

    powerchord = unison.mix_down(fifth)

    maj_triad = powerchord.mix_down(maj_third)
    min_triad = mix_down(powerchord, min_third)

    with wav_file_context(args.filename) as fout:
        fout.write_frames(powerchord.frames)
        fout.write_frames(maj_triad.frames)
        fout.write_frames(min_triad.frames)

    return 0


if __name__ == "__main__":
    common.call_main(main)

[((27, 13, 27, 60), 'potty_oh.common.get_cmd_line_parser', 'common.get_cmd_line_parser', (), '', False, 'from potty_oh import common\n'), ((28, 4, 28, 43), 'potty_oh.common.ParserArguments.filename', 'common.ParserArguments.filename', ({(28, 36, 28, 42): 'parser'}, {}), '(parser)', False, 'from potty_oh import common\n'), ((29, 4, 29, 41), 'potty_oh.common.ParserArguments.length', 'common.ParserArguments.length', ({(29, 34, 29, 40): 'parser'}, {}), '(parser)', False, 'from potty_oh import common\n'), ((30, 4, 30, 44), 'potty_oh.common.ParserArguments.framerate', 'common.ParserArguments.framerate', ({(30, 37, 30, 43): 'parser'}, {}), '(parser)', False, 'from potty_oh import common\n'), ((31, 4, 32, 51), 'potty_oh.common.ParserArguments.set_defaults', 'common.ParserArguments.set_defaults', (), '', False, 'from potty_oh import common\n'), ((36, 9, 36, 58), 'potty_oh.signal_generator.Generator', 'Generator', (), '', False, 'from potty_oh.signal_generator import Generator\n'), ((38, 10, 38, 15), 'potty_oh.music.pitch.Key', 'Key', ({}, {}), '()', False, 'from potty_oh.music.pitch import Key\n'), ((47, 16, 47, 47), 'potty_oh.waveform.mix_down', 'mix_down', ({(47, 25, 47, 35): 'powerchord', (47, 37, 47, 46): 'min_third'}, {}), '(powerchord, min_third)', False, 'from potty_oh.waveform import mix_down\n'), ((58, 4, 58, 26), 'potty_oh.common.call_main', 'common.call_main', ({(58, 21, 58, 25): 'main'}, {}), '(main)', False, 'from potty_oh import common\n'), ((49, 9, 49, 40), 'potty_oh.wav_file.wav_file_context', 'wav_file_context', ({(49, 26, 49, 39): 'args.filename'}, {}), '(args.filename)', False, 'from potty_oh.wav_file import wav_file_context\n')]