예제 #1
0
    def populate_fields(self):
        """
        This method does all of the work for the Learner, analyzing
        the audio and coming out with ngrams for generation.
        """
        for f in self.files:
            audio = putil.load_pickle(f)
            if not audio:
                audio = putil.load_pickle(putil.make_pickle_audio(f))
            self.songs.append({"data": audio, "bpm": audio.analysis.tempo,
                               "time": audio.analysis.time_signature,
                               "file": f})

        self.find_pitch_sequences()
        self.combine_same_pitch_for_length()

        # Populate the bigram structure
        self.ngrams["notes"] = self.count_ngrams(self.get_notes())
        self.ngrams["rhythms"] = self.count_ngrams(self.get_rhythms())
예제 #2
0
def main():
    if "--help" in sys.argv:
        print """
        Usage: ./HearBayes.py [audiofile_out]
        [length of generation in seconds][audiofiles_in or Learner pickle
        file, ..., ]

        #TODO optional: --bpm=[number], --key=[C-B,+ for sharp, - for flat]
                --time_sig=[number 1-4, only common time sigs allowed here]

        In place of [audiofiles_in] as the last argument, you can also
        specify a pickle file with extension ".pickle" to use as the Learner
        if it has already been trained.
        """
        return 0
    arguments = sys.argv

    file_out = arguments[1]
    length = int(arguments[2])
    files_in = arguments[3:]

    if len(files_in) == 1 and "pickle" in files_in[0].split("."):
        print "Loading learner from pickle..."
        learner = putil.load_pickle(files_in[0])
    else:
        learner = l.Learner(list(files_in))
        print "Learning songs..."
        learner.populate_fields()
        learner.save(files_in[0] + ".learner")
        print("%d progressions learned" % len(learner.note_list))

    print "Generating new audio..."
    generator = g.Generator(learner, file_out)

    generator.write_music(length, bpm=120, initial_key="D+")
    print "Finished!"

    # Debugging information about target statistics to more accurately
    # set the ngram length.
    print("hit notes: %d" % generator.FOUND_NOTE)
    print("missed notes: %d" % generator.NOT_FOUND_NOTE)
    print("hit rhythms: %d" % generator.FOUND_RHYTHM)
    print("missed rhythms: %d" % generator.NOT_FOUND_RHYTHM)
    print("not in key: %d" % generator.NOT_IN_KEY)

    return 0
예제 #3
0
            self.vmax = self.grid.max()
        else:
            self.vmax = vmax
        if show:
            self.show_grid(ax=ax)


## Define arguments for plotting P(z) grid
## The panel grid should have this arrangement:
## -------------------
##     1    |    2   |
## -------------------
##     3    |    4   |
## -------------------
dkgrid_dir = '/Users/khuang/Dropbox/Research/bivariate/bivariate_fit/dropsim_kernels'
dkgrid3 = pu.load_pickle(
    os.path.join(dkgrid_dir, 'udrops_gds_deep_kgrid_m2h_140815.p'))
dkgrid4 = pu.load_pickle(
    os.path.join(dkgrid_dir, 'bdrops_goods_kgrid_140317.p'))
dkgrid5 = pu.load_pickle(
    os.path.join(dkgrid_dir, 'vdrops_goods_kgrid_140402.p'))
dkgrid6 = pu.load_pickle(
    os.path.join(dkgrid_dir, 'idrops_gds_deep_kgrid_140228.p'))
dkgrid_list = [dkgrid3, dkgrid4, dkgrid5, dkgrid6]
pms = pmscolors.pmscolors()
colors = map(pms, ['Blue Purples', 'Periwinkle', 'Olive Green', 'Bright Red'])
m1500_lims = np.array([[-23., -21.], [-21., -19.], [-23., -21.], [-21., -19]])
logr_lims = np.array([[-0.5, 0.5], [-0.5, 0.5], [-1.5, 0.5], [-1.5, 0.5]])


def plot_dkgrid_multiple(dkgrids=dkgrid_list,
                         colors=colors,
예제 #4
0
from peer_spider import Spider
from pickle_util import load_pickle

val_perc = load_pickle("data/account_percent.pkl")
s = Spider(['3.14.161.135', '3.12.207.193', '3.142.224.108'], 'casper')
s.get_all_nodes()
perc = s.get_weight_active_percent(val_perc)
print(f"{round(perc, 2)}% weight active.")
from pickle_util import load_pickle, save_bz2_pickle
from pathlib import Path

SCRIPT_DIR = Path(__file__).parent.absolute()
DATA_DIR = SCRIPT_DIR / "data"

for file in DATA_DIR.glob('*.pickle'):
    data = load_pickle(file)
    save_bz2_pickle(data, file.with_suffix(".pbz2"))